-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#287] Add tests for WebAuthnVerifier in passkey package
- Loading branch information
Showing
1 changed file
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}) | ||
}) |