@@ -17,6 +17,7 @@ const customsServer = nock(CUSTOMS_URL_REAL).defaultReplyHeaders({
1717 'Content-Type' : 'application/json' ,
1818} ) ;
1919const Customs = require ( `../../lib/customs.js` ) ;
20+ const configModule = require ( '../../config' ) ;
2021
2122describe ( 'Customs' , ( ) => {
2223 let customsNoUrl ;
@@ -724,6 +725,18 @@ describe('Customs', () => {
724725 mockRateLimit . check = sinon . spy ( ) ;
725726 mockRateLimit . skip = sinon . spy ( ( ) => false ) ;
726727 mockRateLimit . supportsAction = sinon . spy ( ( ) => true ) ;
728+ // Stub config.get to return email alias domain configurations for tests
729+ const configGetStub = sandbox . stub ( configModule . config , 'get' ) ;
730+ configGetStub
731+ . withArgs ( 'rateLimit.emailAliasNormalization' )
732+ . returns (
733+ JSON . stringify ( [
734+ { domain : 'mozilla.com' , regex : '\\+[^@]+' , replace : '' } ,
735+ ] )
736+ ) ;
737+ configGetStub . callThrough ( ) ;
738+ // Reload the config map with the stubbed config
739+ Customs . _reloadAliasConfigsMap ( ) ;
727740 } ) ;
728741
729742 it ( 'can allow checkAccountStatus with rate-limit lib' , async ( ) => {
@@ -821,6 +834,94 @@ describe('Customs', () => {
821834 } ) ;
822835 assert . callCount ( mockRateLimit . check , 0 ) ;
823836 } ) ;
837+
838+ it ( 'normalizes emails with plus aliases for configured domains' , async ( ) => {
839+ mockRateLimit . check = sandbox . spy ( async ( ) => {
840+ return await Promise . resolve ( null ) ;
841+ } ) ;
842+
843+ const emailWithAlias = '[email protected] ' ; 844+ const normalizedEmail = '[email protected] ' ; 845+ const normalizedIpEmail = `${ ip } _${ normalizedEmail } ` ;
846+
847+ await customs . check ( request , emailWithAlias , 'accountStatusCheck' ) ;
848+
849+ assert . calledWith (
850+ mockRateLimit . check ,
851+ 'accountStatusCheck' ,
852+ sinon . match ( {
853+ ip,
854+ email : normalizedEmail ,
855+ ip_email : normalizedIpEmail ,
856+ } )
857+ ) ;
858+ } ) ;
859+
860+ it ( 'normalizes emails with different cases' , async ( ) => {
861+ mockRateLimit . check = sandbox . spy ( async ( ) => {
862+ return await Promise . resolve ( null ) ;
863+ } ) ;
864+
865+ const mixedCaseEmail = '[email protected] ' ; 866+ const normalizedEmail = '[email protected] ' ; 867+ const normalizedIpEmail = `${ ip } _${ normalizedEmail } ` ;
868+
869+ await customs . check ( request , mixedCaseEmail , 'accountStatusCheck' ) ;
870+
871+ assert . calledWith (
872+ mockRateLimit . check ,
873+ 'accountStatusCheck' ,
874+ sinon . match ( {
875+ ip,
876+ email : normalizedEmail ,
877+ ip_email : normalizedIpEmail ,
878+ } )
879+ ) ;
880+ } ) ;
881+
882+ it ( 'does not remove aliases for non-configured domains' , async ( ) => {
883+ mockRateLimit . check = sandbox . spy ( async ( ) => {
884+ return await Promise . resolve ( null ) ;
885+ } ) ;
886+
887+ const emailWithAlias = '[email protected] ' ; 888+ const normalizedEmail = '[email protected] ' ; // Alias should remain 889+ const normalizedIpEmail = `${ ip } _${ normalizedEmail } ` ;
890+
891+ await customs . check ( request , emailWithAlias , 'accountStatusCheck' ) ;
892+
893+ assert . calledWith (
894+ mockRateLimit . check ,
895+ 'accountStatusCheck' ,
896+ sinon . match ( {
897+ ip,
898+ email : normalizedEmail ,
899+ ip_email : normalizedIpEmail ,
900+ } )
901+ ) ;
902+ } ) ;
903+
904+ it ( 'lowercases emails for all domains' , async ( ) => {
905+ mockRateLimit . check = sandbox . spy ( async ( ) => {
906+ return await Promise . resolve ( null ) ;
907+ } ) ;
908+
909+ const mixedCaseEmail = '[email protected] ' ; 910+ const normalizedEmail = '[email protected] ' ; 911+ const normalizedIpEmail = `${ ip } _${ normalizedEmail } ` ;
912+
913+ await customs . check ( request , mixedCaseEmail , 'accountStatusCheck' ) ;
914+
915+ assert . calledWith (
916+ mockRateLimit . check ,
917+ 'accountStatusCheck' ,
918+ sinon . match ( {
919+ ip,
920+ email : normalizedEmail ,
921+ ip_email : normalizedIpEmail ,
922+ } )
923+ ) ;
924+ } ) ;
824925 } ) ;
825926
826927 describe ( 'statsd metrics' , ( ) => {
0 commit comments