File tree Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -26,6 +26,14 @@ export default function(couchOpts={}, opts={}) {
26
26
27
27
api . authenticate = async function authenticate ( username , password ) {
28
28
try {
29
+ if ( typeof username !== "string" || ! username ) {
30
+ throw new HTTPError ( 400 , "Missing username." , "EBADINPUT" ) ;
31
+ }
32
+
33
+ if ( typeof password !== "string" || ! password ) {
34
+ throw new HTTPError ( 400 , "Missing password." , "EBADINPUT" ) ;
35
+ }
36
+
29
37
let { body} = await superagent . get ( `${ baseUrl } /_session` )
30
38
. accept ( "application/json" )
31
39
. auth ( username , password ) ;
Original file line number Diff line number Diff line change @@ -80,6 +80,17 @@ test("fails to sign in with incorrect credentials", async (t) => {
80
80
t . equals ( body . code , "EBADAUTH" , "error has EBADAUTH code" ) ;
81
81
} ) ;
82
82
83
+ test ( "fails to sign in with missing username and password" , async ( t ) => {
84
+ t . plan ( 3 ) ;
85
+ const request = supertest ( createApp ( ) ) ;
86
+
87
+ let { body} = await request . post ( "/" ) . expect ( 400 ) ;
88
+
89
+ t . ok ( body . error , "responds with error" ) ;
90
+ t . equals ( body . status , 400 , "is bad request error" ) ;
91
+ t . equals ( body . code , "EBADINPUT" , "error has bad input code" ) ;
92
+ } ) ;
93
+
83
94
test ( "renews token, responding with new token" , async ( t ) => {
84
95
t . plan ( 8 ) ;
85
96
const request = supertest ( createApp ( ) ) ;
You can’t perform that action at this time.
0 commit comments