Skip to content

Commit 52dabf0

Browse files
committed
chore: add critical test for base 2fa functionality
1 parent dc62fc1 commit 52dabf0

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

index.test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,23 @@ test('OTP with digits > 6 should not pad with first character of charSet', async
145145
)
146146
}
147147
})
148+
149+
test('generating a auth uri can be used to generate a otp that can be verified', async () => {
150+
const { otp: _otp, ...totpConfig } = await generateTOTP()
151+
const otpUriString = getTOTPAuthUri({
152+
issuer: 'test',
153+
accountName: 'test',
154+
...totpConfig,
155+
})
156+
157+
const otpUri = new URL(otpUriString)
158+
const options = Object.fromEntries(otpUri.searchParams)
159+
160+
const { otp } = await generateTOTP({
161+
...options,
162+
// the algorithm will be "SHA1" but we need to generate the OTP with "SHA-1"
163+
algorithm: 'SHA-1',
164+
})
165+
const result = await verifyTOTP({ otp, ...totpConfig })
166+
assert.deepStrictEqual(result, { delta: 0 })
167+
})

0 commit comments

Comments
 (0)