@@ -675,6 +675,7 @@ describe('deleteAccountIfUnverified', () => {
675675 mockConfig . oauth = { } ;
676676 mockConfig . signinConfirmation = { } ;
677677 mockConfig . signinConfirmation . skipForEmailAddresses = [ ] ;
678+ mockConfig . signinConfirmation . skipForEmailRegex = / ^ $ / ;
678679 const emailRecord : any = {
679680 isPrimary : true ,
680681 isVerified : false ,
@@ -3171,6 +3172,80 @@ describe('/account/login', () => {
31713172 ) ;
31723173 } ) ;
31733174
3175+ describe ( 'skip for email regex' , ( ) => {
3176+ function setupSkipForEmailRegex ( email : string , regex : RegExp ) {
3177+ config . securityHistory . ipProfiling . allowedRecency = 0 ;
3178+ config . signinConfirmation . skipForNewAccounts = { enabled : false } ;
3179+ config . signinConfirmation . skipForEmailAddresses = [ ] ;
3180+ config . signinConfirmation . skipForEmailRegex = regex ;
3181+
3182+ mockDB . verifiedLoginSecurityEvents = sinon . spy ( ( ) =>
3183+ Promise . resolve ( [ ] )
3184+ ) ;
3185+
3186+ mockRequest . payload . email = email ;
3187+
3188+ mockDB . accountRecord = ( ) => {
3189+ return Promise . resolve ( {
3190+ authSalt : hexString ( 32 ) ,
3191+ data : hexString ( 32 ) ,
3192+ email,
3193+ emailVerified : true ,
3194+ primaryEmail : {
3195+ normalizedEmail : normalizeEmail ( email ) ,
3196+ email,
3197+ isVerified : true ,
3198+ isPrimary : true ,
3199+ } ,
3200+ kA : hexString ( 32 ) ,
3201+ lastAuthAt : ( ) => Date . now ( ) ,
3202+ uid,
3203+ wrapWrapKb : hexString ( 32 ) ,
3204+ } ) ;
3205+ } ;
3206+
3207+ const innerAccountRoutes = makeRoutes ( {
3208+ checkPassword : ( ) => Promise . resolve ( true ) ,
3209+ config,
3210+ customs : mockCustoms ,
3211+ db : mockDB ,
3212+ log : mockLog ,
3213+ mailer : mockMailer ,
3214+ push : mockPush ,
3215+ } ) ;
3216+
3217+ route = getRoute ( innerAccountRoutes , '/account/login' ) ;
3218+ }
3219+
3220+ afterEach ( ( ) => {
3221+ config . securityHistory . ipProfiling . allowedRecency =
3222+ defaultConfig . securityHistory . ipProfiling . allowedRecency ;
3223+ config . signinConfirmation . skipForEmailRegex = / ^ $ / ;
3224+ } ) ;
3225+
3226+ it ( 'should skip sign-in confirmation for email matching regex' , ( ) => {
3227+ setupSkipForEmailRegex ( '[email protected] ' , / .+ @ e x a m p l e \. c o m $ / ) ; 3228+
3229+ return runTest ( route , mockRequest , ( response : any ) => {
3230+ expect ( mockDB . createSessionToken . callCount ) . toBe ( 1 ) ;
3231+ const tokenData = mockDB . createSessionToken . getCall ( 0 ) . args [ 0 ] ;
3232+ expect ( tokenData . tokenVerificationId ) . toBeFalsy ( ) ;
3233+ expect ( response . emailVerified ) . toBeTruthy ( ) ;
3234+ } ) ;
3235+ } ) ;
3236+
3237+ it ( 'should not skip sign-in confirmation for email not matching regex' , ( ) => {
3238+ setupSkipForEmailRegex ( '[email protected] ' , / .+ @ e x a m p l e \. c o m $ / ) ; 3239+
3240+ return runTest ( route , mockRequest , ( response : any ) => {
3241+ expect ( mockDB . createSessionToken . callCount ) . toBe ( 1 ) ;
3242+ const tokenData = mockDB . createSessionToken . getCall ( 0 ) . args [ 0 ] ;
3243+ expect ( tokenData . tokenVerificationId ) . toBeTruthy ( ) ;
3244+ expect ( response . verified ) . toBeFalsy ( ) ;
3245+ } ) ;
3246+ } ) ;
3247+ } ) ;
3248+
31743249 describe ( 'skip for known device' , ( ) => {
31753250 let mockAccountEventsManager : any ;
31763251 let savedIpProfiling : any ;
0 commit comments