Skip to content

Commit 51e5592

Browse files
authored
Fix legacy CLI auth code parsing (#626)
1 parent 6f27176 commit 51e5592

6 files changed

Lines changed: 270 additions & 199 deletions

File tree

freebuff/web/src/app/onboard/__tests__/helpers.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff 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'

freebuff/web/src/app/onboard/_helpers.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff 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-f0-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

freebuff/web/src/app/onboard/page.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff 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,

0 commit comments

Comments
 (0)