@@ -3080,86 +3080,14 @@ describe('/account/login', () => {
30803080 ) ;
30813081 } ) ;
30823082 } ) ;
3083- } ) ;
3084-
3085- describe ( 'skip for emails' , ( ) => {
3086- function setupSkipForEmails ( email : string ) {
3087- config . securityHistory . ipProfiling . allowedRecency = 0 ;
3088- config . signinConfirmation . skipForNewAccounts = { enabled : false } ;
3089- config . signinConfirmation . skipForEmailAddresses = [
3090- 3091- 3092- ] ;
3093-
3094- // Reset the spy to avoid leaking state between tests
3095- mockDB . verifiedLoginSecurityEvents = sinon . spy ( ( ) =>
3096- Promise . resolve ( [ ] )
3097- ) ;
3098-
3099- mockRequest . payload . email = email ;
3100-
3101- mockDB . accountRecord = ( ) => {
3102- return Promise . resolve ( {
3103- authSalt : hexString ( 32 ) ,
3104- data : hexString ( 32 ) ,
3105- email,
3106- emailVerified : true ,
3107- primaryEmail : {
3108- normalizedEmail : normalizeEmail ( email ) ,
3109- email,
3110- isVerified : true ,
3111- isPrimary : true ,
3112- } ,
3113- kA : hexString ( 32 ) ,
3114- lastAuthAt : ( ) => Date . now ( ) ,
3115- uid,
3116- wrapWrapKb : hexString ( 32 ) ,
3117- } ) ;
3118- } ;
3119-
3120- const innerAccountRoutes = makeRoutes ( {
3121- checkPassword : ( ) => Promise . resolve ( true ) ,
3122- config,
3123- customs : mockCustoms ,
3124- db : mockDB ,
3125- log : mockLog ,
3126- mailer : mockMailer ,
3127- push : mockPush ,
3128- } ) ;
3129-
3130- route = getRoute ( innerAccountRoutes , '/account/login' ) ;
3131- }
31323083
31333084 afterEach ( ( ) => {
3134- // Restore config to default to avoid leaking into subsequent tests
3085+ config . signinConfirmation . skipForNewAccounts = undefined ;
31353086 config . securityHistory . ipProfiling . allowedRecency =
31363087 defaultConfig . securityHistory . ipProfiling . allowedRecency ;
3137- } ) ;
3138-
3139- it ( 'should not skip sign-in confirmation for specified email' , ( ) => {
3140- setupSkipForEmails ( '[email protected] ' ) ; 3141-
3142- return runTest ( route , mockRequest , ( response : any ) => {
3143- expect ( mockDB . createSessionToken . callCount ) . toBe ( 1 ) ;
3144- const tokenData = mockDB . createSessionToken . getCall ( 0 ) . args [ 0 ] ;
3145- expect ( tokenData . tokenVerificationId ) . toBeTruthy ( ) ;
3146- expect ( mockFxaMailer . sendVerifyLoginEmail . callCount ) . toBe ( 1 ) ;
3147- expect ( mockFxaMailer . sendNewDeviceLoginEmail . callCount ) . toBe ( 0 ) ;
3148- expect ( response . verified ) . toBeFalsy ( ) ;
3149- } ) ;
3150- } ) ;
3151-
3152- it ( 'should skip sign-in confirmation for specified email' , ( ) => {
3153- setupSkipForEmails ( '[email protected] ' ) ; 3154-
3155- return runTest ( route , mockRequest , ( response : any ) => {
3156- expect ( mockDB . createSessionToken . callCount ) . toBe ( 1 ) ;
3157- const tokenData = mockDB . createSessionToken . getCall ( 0 ) . args [ 0 ] ;
3158- expect ( tokenData . tokenVerificationId ) . toBeFalsy ( ) ;
3159- expect ( mockMailer . sendVerifyLoginEmail . callCount ) . toBe ( 0 ) ;
3160- expect ( mockFxaMailer . sendNewDeviceLoginEmail . callCount ) . toBe ( 1 ) ;
3161- expect ( response . emailVerified ) . toBeTruthy ( ) ;
3162- } ) ;
3088+ mockDB . verifiedLoginSecurityEvents = sinon . spy ( ( ) =>
3089+ Promise . resolve ( [ ] )
3090+ ) ;
31633091 } ) ;
31643092 } ) ;
31653093
@@ -3184,7 +3112,6 @@ describe('/account/login', () => {
31843112 function setupSkipForEmailRegex ( email : string , regex : RegExp ) {
31853113 config . securityHistory . ipProfiling . allowedRecency = 0 ;
31863114 config . signinConfirmation . skipForNewAccounts = { enabled : false } ;
3187- config . signinConfirmation . skipForEmailAddresses = [ ] ;
31883115 config . signinConfirmation . skipForEmailRegex = regex ;
31893116
31903117 mockDB . verifiedLoginSecurityEvents = sinon . spy ( ( ) =>
@@ -3224,11 +3151,18 @@ describe('/account/login', () => {
32243151
32253152 route = getRoute ( innerAccountRoutes , '/account/login' ) ;
32263153 }
3227-
3154+ beforeEach ( ( ) => {
3155+ // one test is checking the statsd, and this is included in it.
3156+ // We set it here, and reset in the afterEach to avoid having the
3157+ // config state leak to other tests if these fail
3158+ mockRequest . app . clientIdTag = 'test-client-id' ;
3159+ statsd . increment . resetHistory ( ) ;
3160+ } ) ;
32283161 afterEach ( ( ) => {
32293162 config . securityHistory . ipProfiling . allowedRecency =
32303163 defaultConfig . securityHistory . ipProfiling . allowedRecency ;
32313164 config . signinConfirmation . skipForEmailRegex = / ^ $ / ;
3165+ mockRequest . app . clientIdTag = undefined ;
32323166 } ) ;
32333167
32343168 it ( 'should skip sign-in confirmation for email matching regex' , ( ) => {
@@ -3252,6 +3186,19 @@ describe('/account/login', () => {
32523186 expect ( response . verified ) . toBeFalsy ( ) ;
32533187 } ) ;
32543188 } ) ;
3189+
3190+ it ( 'should increment statsd metric for emailAlways' , ( ) => {
3191+ setupSkipForEmailRegex ( '[email protected] ' , / .+ @ e x a m p l e \. c o m $ / ) ; 3192+
3193+ return runTest ( route , mockRequest , ( ) => {
3194+ sinon . assert . calledWith (
3195+ statsd . increment ,
3196+ 'account.signin.confirm.bypass.emailAlways' ,
3197+ { clientId : 'test-client-id' }
3198+ ) ;
3199+ mockRequest . app . clientIdTag = undefined ;
3200+ } ) ;
3201+ } ) ;
32553202 } ) ;
32563203
32573204 describe ( 'skip for known device' , ( ) => {
0 commit comments