Skip to content

Commit

Permalink
[#287] Add tests for WebAuthnVerifier in passkey package
Browse files Browse the repository at this point in the history
  • Loading branch information
akshay-ap committed Mar 13, 2024
1 parent 7b3ea24 commit cc75ffa
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions modules/passkey/test/verifiers/WebAuthnVerifier.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { expect } from 'chai'
import { deployments, ethers } from 'hardhat'

describe.only('WebAuthnVerifier', () => {
const setupTests = deployments.createFixture(async ({ deployments }) => {
const { WebAuthnVerifier } = await deployments.fixture()
const webAuthnVerifier = await ethers.getContractAt('WebAuthnVerifier', WebAuthnVerifier.address)
return { webAuthnVerifier }
})

it('Should return false when invalid signature', async () => {
const webAuthnVerifier = await setupTests()

const authenticatorData = ethers.randomBytes(100)
authenticatorData[32] = 0x01

const challenge = ethers.randomBytes(32)
const clientDataFields = ethers.randomBytes(100)

expect(
await webAuthnVerifier.webAuthnVerifier.verifyWebAuthnSignature(
authenticatorData,
'0x01',
challenge,
clientDataFields,
[0n, 0n],
0n,
0n,
),
).to.be.false

expect(
await webAuthnVerifier.webAuthnVerifier.verifyWebAuthnSignatureAllowMalleability(
authenticatorData,
'0x01',
challenge,
clientDataFields,
[0n, 0n],
0n,
0n,
),
).to.be.false
})

it('Should return false on non-matching authenticator flags', async () => {
const webAuthnVerifier = await setupTests()

const authenticatorData = ethers.randomBytes(100)
authenticatorData[32] = 0x02

const challenge = ethers.randomBytes(32)
const clientDataFields = ethers.randomBytes(100)

expect(
await webAuthnVerifier.webAuthnVerifier.verifyWebAuthnSignature(
authenticatorData,
'0x01',
challenge,
clientDataFields,
[0n, 0n],
0n,
0n,
),
).to.be.false

expect(
await webAuthnVerifier.webAuthnVerifier.verifyWebAuthnSignatureAllowMalleability(
authenticatorData,
'0x01',
challenge,
clientDataFields,
[0n, 0n],
0n,
0n,
),
).to.be.false
})
})

0 comments on commit cc75ffa

Please sign in to comment.