File tree Expand file tree Collapse file tree
freebuff/web/src/app/onboard Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -23,6 +23,16 @@ describe('freebuff onboard/_helpers', () => {
2323 expect ( result . receivedHash ) . toBe ( 'hashvalue' )
2424 } )
2525
26+ test ( 'parses legacy hyphen-delimited auth code' , ( ) => {
27+ const receivedHash = 'a' . repeat ( 64 )
28+ const authCode = `1234567890abcdef1234567890abcdef-1704067200000-${ receivedHash } `
29+ const result = parseAuthCode ( authCode )
30+
31+ expect ( result . fingerprintId ) . toBe ( '1234567890abcdef1234567890abcdef' )
32+ expect ( result . expiresAt ) . toBe ( '1704067200000' )
33+ expect ( result . receivedHash ) . toBe ( receivedHash )
34+ } )
35+
2636 test ( 'handles auth code missing separator before expiresAt' , ( ) => {
2737 const authCode =
2838 'fingerprint-1231704067200000.abc123hashabc123hashabc123hash'
Original file line number Diff line number Diff line change @@ -13,6 +13,17 @@ export function parseAuthCode(authCode: string): {
1313 )
1414
1515 if ( hashSeparatorIndex === - 1 || expiresSeparatorIndex === - 1 ) {
16+ const legacyMatch = normalizedAuthCode . match (
17+ / ^ (?< fingerprintId > .+ ) - (?< expiresAt > \d + ) - (?< receivedHash > [ a - f 0 - 9 ] { 64 } ) $ / i,
18+ )
19+ if ( legacyMatch ?. groups ) {
20+ return {
21+ fingerprintId : legacyMatch . groups . fingerprintId ,
22+ expiresAt : legacyMatch . groups . expiresAt ,
23+ receivedHash : legacyMatch . groups . receivedHash ,
24+ }
25+ }
26+
1627 return { fingerprintId : '' , expiresAt : '' , receivedHash : '' }
1728 }
1829
Original file line number Diff line number Diff line change @@ -103,6 +103,8 @@ const Onboard = async ({ searchParams }: PageProps) => {
103103 logger . warn (
104104 {
105105 authCodeLength : authCode . length ,
106+ dotCount : authCode . match ( / \. / g) ?. length ?? 0 ,
107+ hyphenCount : authCode . match ( / - / g) ?. length ?? 0 ,
106108 fingerprintIdPrefix : fingerprintId . slice ( 0 , 24 ) ,
107109 fingerprintIdLength : fingerprintId . length ,
108110 expiresAt,
Original file line number Diff line number Diff line change @@ -32,6 +32,16 @@ describe('onboard/_helpers', () => {
3232 expect ( result . receivedHash ) . toBe ( 'abc123hash' )
3333 } )
3434
35+ test ( 'parses legacy hyphen-delimited auth code' , ( ) => {
36+ const receivedHash = 'a' . repeat ( 64 )
37+ const authCode = `1234567890abcdef1234567890abcdef-1704067200000-${ receivedHash } `
38+ const result = parseAuthCode ( authCode )
39+
40+ expect ( result . fingerprintId ) . toBe ( '1234567890abcdef1234567890abcdef' )
41+ expect ( result . expiresAt ) . toBe ( '1704067200000' )
42+ expect ( result . receivedHash ) . toBe ( receivedHash )
43+ } )
44+
3545 test ( 'handles auth code missing separator before expiresAt' , ( ) => {
3646 const authCode =
3747 'fingerprint-1231704067200000.abc123hashabc123hashabc123hash'
Original file line number Diff line number Diff line change @@ -13,6 +13,17 @@ export function parseAuthCode(authCode: string): {
1313 )
1414
1515 if ( hashSeparatorIndex === - 1 || expiresSeparatorIndex === - 1 ) {
16+ const legacyMatch = normalizedAuthCode . match (
17+ / ^ (?< fingerprintId > .+ ) - (?< expiresAt > \d + ) - (?< receivedHash > [ a - f 0 - 9 ] { 64 } ) $ / i,
18+ )
19+ if ( legacyMatch ?. groups ) {
20+ return {
21+ fingerprintId : legacyMatch . groups . fingerprintId ,
22+ expiresAt : legacyMatch . groups . expiresAt ,
23+ receivedHash : legacyMatch . groups . receivedHash ,
24+ }
25+ }
26+
1627 return { fingerprintId : '' , expiresAt : '' , receivedHash : '' }
1728 }
1829
You can’t perform that action at this time.
0 commit comments