@@ -339,6 +339,54 @@ describeAuthEmulator("createSessionCookie", ({ authApi }) => {
339339} ) ;
340340
341341describeAuthEmulator ( "accounts:lookup" , ( { authApi } ) => {
342+ it ( "should return user by email when privileged" , async ( ) => {
343+ const { email } = await registerUser ( authApi ( ) , {
344+ email : "bob@example.com" ,
345+ password : "password" ,
346+ } ) ;
347+
348+ await authApi ( )
349+ . post ( `/identitytoolkit.googleapis.com/v1/projects/${ PROJECT_ID } /accounts:lookup` )
350+ . set ( "Authorization" , "Bearer owner" )
351+ . send ( { email : [ email ] } )
352+ . then ( ( res ) => {
353+ expectStatusCode ( 200 , res ) ;
354+ expect ( res . body . users ) . to . have . length ( 1 ) ;
355+ expect ( res . body . users [ 0 ] . email ) . to . equal ( email ) ;
356+ } ) ;
357+ } ) ;
358+
359+ it ( "should return user by email even when uppercased" , async ( ) => {
360+ const { email } = await registerUser ( authApi ( ) , {
361+ email : "foo@example.com" ,
362+ password : "password" ,
363+ } ) ;
364+ const caplitalizedEmail = email . toUpperCase ( ) ;
365+
366+ await authApi ( )
367+ . post ( `/identitytoolkit.googleapis.com/v1/projects/${ PROJECT_ID } /accounts:lookup` )
368+ . set ( "Authorization" , "Bearer owner" )
369+ . send ( { email : [ caplitalizedEmail ] } )
370+ . then ( ( res ) => {
371+ console . log ( res . body . users ) ;
372+ expectStatusCode ( 200 , res ) ;
373+ expect ( res . body . users ) . to . have . length ( 1 ) ;
374+ expect ( res . body . users [ 0 ] . email ) . to . equal ( email ) ;
375+ } ) ;
376+ } ) ;
377+
378+ it ( "should return empty result when email is not found" , async ( ) => {
379+ await authApi ( )
380+ . post ( `/identitytoolkit.googleapis.com/v1/projects/${ PROJECT_ID } /accounts:lookup` )
381+ . set ( "Authorization" , "Bearer owner" )
382+ . send ( { email : [ "non-existent-email@example.com" ] } )
383+ . then ( ( res ) => {
384+ console . log ( res . body . users ) ;
385+ expectStatusCode ( 200 , res ) ;
386+ expect ( res . body ) . not . to . have . property ( "users" ) ;
387+ } ) ;
388+ } ) ;
389+
342390 it ( "should return user by localId when privileged" , async ( ) => {
343391 const { localId } = await registerAnonUser ( authApi ( ) ) ;
344392
0 commit comments