@@ -12,8 +12,14 @@ describe('auth.utils', () => {
1212 const codeChallenge1 = 'codeChallenge-1'
1313 const codeChallenge2 = 'codeChallenge-2'
1414
15- const identifier1 = createVfnIdentifier ( { email, codeChallenge : codeChallenge1 } )
16- const identifier2 = createVfnIdentifier ( { email, codeChallenge : codeChallenge2 } )
15+ const identifier1 = createVfnIdentifier ( {
16+ email,
17+ codeChallenge : codeChallenge1 ,
18+ } )
19+ const identifier2 = createVfnIdentifier ( {
20+ email,
21+ codeChallenge : codeChallenge2 ,
22+ } )
1723
1824 expect ( identifier1 ) . not . toBe ( identifier2 )
1925 } )
@@ -22,18 +28,25 @@ describe('auth.utils', () => {
22282329 const codeChallenge = 'test-codeChallenge'
2430
25- const identifier1 = createVfnIdentifier ( { email, codeChallenge : codeChallenge } )
26- const identifier2 = createVfnIdentifier ( { email, codeChallenge : codeChallenge } )
27- const identifier3 = createVfnIdentifier ( { email, codeChallenge : codeChallenge } )
31+ const identifier1 = createVfnIdentifier ( {
32+ email,
33+ codeChallenge : codeChallenge ,
34+ } )
35+ const identifier2 = createVfnIdentifier ( {
36+ email,
37+ codeChallenge : codeChallenge ,
38+ } )
39+ const identifier3 = createVfnIdentifier ( {
40+ email,
41+ codeChallenge : codeChallenge ,
42+ } )
2843
2944 expect ( identifier1 ) . toBe ( identifier2 )
3045 expect ( identifier2 ) . toBe ( identifier3 )
3146 } )
3247 } )
3348
3449 describe ( 'createVfnPrefix' , ( ) => {
35-
36-
3750 it ( 'should only contain uppercase letters from the allowed alphabet' , ( ) => {
3851 const prefix = createVfnPrefix ( )
3952 const allowedChars = / ^ [ A B C D E F G H J K L M N P Q R S T U V W X Y Z ] + $ /
@@ -70,18 +83,30 @@ describe('auth.utils', () => {
7083
7184 it ( 'should generate tokens of sufficient entropy' , ( ) => {
7285 const N = 10000
73- const tokens = Array . from ( { length : N } ) . map ( ( ) => createAuthToken ( {
74- email : testEmail ,
75- codeChallenge : testCodeChallenge ,
76- } ) . token )
86+ const tokens = Array . from ( { length : N } ) . map (
87+ ( ) =>
88+ createAuthToken ( {
89+ email : testEmail ,
90+ codeChallenge : testCodeChallenge ,
91+ } ) . token ,
92+ )
7793
7894 expect ( new Set ( tokens ) . size ) . toBe ( N )
7995 } )
8096
8197 it ( 'should generate different tokens for the same email and codeChallenge on multiple calls' , ( ) => {
82- const result1 = createAuthToken ( { email : testEmail , codeChallenge : testCodeChallenge } )
83- const result2 = createAuthToken ( { email : testEmail , codeChallenge : testCodeChallenge } )
84- const result3 = createAuthToken ( { email : testEmail , codeChallenge : testCodeChallenge } )
98+ const result1 = createAuthToken ( {
99+ email : testEmail ,
100+ codeChallenge : testCodeChallenge ,
101+ } )
102+ const result2 = createAuthToken ( {
103+ email : testEmail ,
104+ codeChallenge : testCodeChallenge ,
105+ } )
106+ const result3 = createAuthToken ( {
107+ email : testEmail ,
108+ codeChallenge : testCodeChallenge ,
109+ } )
85110
86111 expect ( result1 . token ) . not . toBe ( result2 . token )
87112 expect ( result2 . token ) . not . toBe ( result3 . token )
@@ -92,8 +117,14 @@ describe('auth.utils', () => {
92117 const email1 = '[email protected] ' 93118 const email2 = '[email protected] ' 94119
95- const result1 = createAuthToken ( { email : email1 , codeChallenge : testCodeChallenge } )
96- const result2 = createAuthToken ( { email : email2 , codeChallenge : testCodeChallenge } )
120+ const result1 = createAuthToken ( {
121+ email : email1 ,
122+ codeChallenge : testCodeChallenge ,
123+ } )
124+ const result2 = createAuthToken ( {
125+ email : email2 ,
126+ codeChallenge : testCodeChallenge ,
127+ } )
97128
98129 // Hashes should be different due to email being used as salt
99130 expect ( result1 . hashedToken ) . not . toBe ( result2 . hashedToken )
@@ -103,8 +134,14 @@ describe('auth.utils', () => {
103134 const codeChallenge1 = 'codeChallenge-1'
104135 const codeChallenge2 = 'codeChallenge-2'
105136
106- const result1 = createAuthToken ( { email : testEmail , codeChallenge : codeChallenge1 } )
107- const result2 = createAuthToken ( { email : testEmail , codeChallenge : codeChallenge2 } )
137+ const result1 = createAuthToken ( {
138+ email : testEmail ,
139+ codeChallenge : codeChallenge1 ,
140+ } )
141+ const result2 = createAuthToken ( {
142+ email : testEmail ,
143+ codeChallenge : codeChallenge2 ,
144+ } )
108145
109146 // Hashes should be different due to codeChallenge being part of the hash input
110147 expect ( result1 . hashedToken ) . not . toBe ( result2 . hashedToken )
@@ -114,7 +151,11 @@ describe('auth.utils', () => {
114151 // Generate multiple tokens to ensure consistency
115152 const tokens = Array . from (
116153 { length : 50 } ,
117- ( ) => createAuthToken ( { email : testEmail , codeChallenge : testCodeChallenge } ) . token ,
154+ ( ) =>
155+ createAuthToken ( {
156+ email : testEmail ,
157+ codeChallenge : testCodeChallenge ,
158+ } ) . token ,
118159 )
119160 const combinedString = tokens . join ( '' )
120161
@@ -150,7 +191,10 @@ describe('auth.utils', () => {
150191 email : testEmail ,
151192 codeChallenge : testCodeChallenge ,
152193 } )
153- const { token : invalidToken } = createAuthToken ( { email : testEmail , codeChallenge : testCodeChallenge } )
194+ const { token : invalidToken } = createAuthToken ( {
195+ email : testEmail ,
196+ codeChallenge : testCodeChallenge ,
197+ } )
154198
155199 const isValid = isValidToken ( {
156200 token : invalidToken ,
@@ -291,13 +335,21 @@ describe('auth.utils', () => {
291335 ]
292336
293337 const tokens = users . map ( ( { email, codeChallenge } ) => {
294- const { token, hashedToken } = createAuthToken ( { email, codeChallenge : codeChallenge } )
338+ const { token, hashedToken } = createAuthToken ( {
339+ email,
340+ codeChallenge : codeChallenge ,
341+ } )
295342 return { email, codeChallenge, token, hashedToken }
296343 } )
297344
298345 // Verify each token is valid for its own email and codeChallenge
299346 tokens . forEach ( ( { email, codeChallenge, token, hashedToken } ) => {
300- const isValid = isValidToken ( { token, email, codeChallenge : codeChallenge , hash : hashedToken } )
347+ const isValid = isValidToken ( {
348+ token,
349+ email,
350+ codeChallenge : codeChallenge ,
351+ hash : hashedToken ,
352+ } )
301353 expect ( isValid ) . toBe ( true )
302354 } )
303355
@@ -344,10 +396,20 @@ describe('auth.utils', () => {
344396
345397 // But each token should still work with its own codeChallenge
346398 expect (
347- isValidToken ( { token : token1 , email, codeChallenge : codeChallenge1 , hash : hash1 } ) ,
399+ isValidToken ( {
400+ token : token1 ,
401+ email,
402+ codeChallenge : codeChallenge1 ,
403+ hash : hash1 ,
404+ } ) ,
348405 ) . toBe ( true )
349406 expect (
350- isValidToken ( { token : token2 , email, codeChallenge : codeChallenge2 , hash : hash2 } ) ,
407+ isValidToken ( {
408+ token : token2 ,
409+ email,
410+ codeChallenge : codeChallenge2 ,
411+ hash : hash2 ,
412+ } ) ,
351413 ) . toBe ( true )
352414 } )
353415 } )
0 commit comments