-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✅ improve
create
tests using fixtures
Instead of using constant defined in the code of the test, we now use fixtures generated using our homemade tool that mock a webauthn authenticator. Here's the link of the tool: [webauthn-mock](https://github.com/0x90d2b2b7fb7599eebb6e7a32980857d8/webauthn-mock)
- Loading branch information
Showing
8 changed files
with
196 additions
and
64 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
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,95 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity >=0.8.19 <0.9.0; | ||
|
||
import { Test, stdJson } from "../lib/forge-std/src/Test.sol"; | ||
import { WebAuthnWrapper } from "./WebAuthnWrapper.sol"; | ||
|
||
contract WebAuthn256r1Test__Create is Test { | ||
Check warning on line 7 in test/WebAuthn256r1.create.t.sol GitHub Actions / lint
Check warning on line 7 in test/WebAuthn256r1.create.t.sol GitHub Actions / lint
|
||
using stdJson for string; | ||
|
||
WebAuthnWrapper internal implem; | ||
uint256 internal fixturesNb; | ||
|
||
function setUp() external { | ||
// deploy a wrapper contract for the library | ||
implem = new WebAuthnWrapper(); | ||
|
||
// load the fixtures from the fixtures.create.json file | ||
string memory root = vm.projectRoot(); | ||
string memory path = string.concat(root, "/test/fixtures/fixtures.create.json"); | ||
string memory json = vm.readFile(path); | ||
|
||
// store the number of fixtures | ||
bytes memory fixturesNbEncoded = json.parseRaw(".length"); | ||
fixturesNb = abi.decode(fixturesNbEncoded, (uint256)); | ||
} | ||
|
||
/// forge-config: default.fuzz.runs = 50 | ||
/// forge-config: ci.fuzz.runs = 100 | ||
function test_VerifyAValidCreateCorrectly(uint256 identifier) external { | ||
// it verify a valid create correctly | ||
|
||
identifier = bound(identifier, 0, fixturesNb - 1); | ||
|
||
// load the fixtures from the credentials.json file | ||
string memory root = vm.projectRoot(); | ||
string memory path = string.concat(root, "/test/fixtures/fixtures.create.json"); | ||
string memory json = vm.readFile(path); | ||
|
||
bytes memory clientDataJSON; | ||
bytes memory challenge; | ||
bytes memory authData; | ||
uint256 qx; | ||
uint256 qy; | ||
uint256 r; | ||
uint256 s; | ||
|
||
// load a random credential from the JSON file | ||
string memory fixturesId = string.concat(".data[", vm.toString(identifier), "]"); | ||
emit log_named_string("fixturesId", fixturesId); | ||
|
||
{ | ||
// load the clientDataJSON | ||
bytes memory credentialsResponseEncoded = | ||
json.parseRaw(string.concat(fixturesId, ".response.clientDataJSON")); | ||
clientDataJSON = abi.decode(credentialsResponseEncoded, (bytes)); | ||
} | ||
|
||
{ | ||
// load the client challenge from the client data JSON | ||
bytes memory challengeEncoded = | ||
json.parseRaw(string.concat(fixturesId, ".responseDecoded.ClientDataJSON.challenge")); | ||
challenge = abi.decode(challengeEncoded, (bytes)); | ||
} | ||
|
||
{ | ||
// load the auth data from the client data JSON | ||
bytes memory authDataEncoded = json.parseRaw(string.concat(fixturesId, ".response.authData")); | ||
authData = abi.decode(authDataEncoded, (bytes)); | ||
} | ||
|
||
{ | ||
// load qx | ||
qx = json.readUint(string.concat(fixturesId, ".responseDecoded.AttestationObject.authData.pubKeyX")); | ||
} | ||
|
||
{ | ||
// load qy | ||
qy = json.readUint(string.concat(fixturesId, ".responseDecoded.AttestationObject.authData.pubKeyY")); | ||
} | ||
|
||
{ | ||
// load R | ||
string memory key = ".responseDecoded.AttestationObject.attStmt.r"; | ||
r = json.readUint(string.concat(fixturesId, key)); | ||
} | ||
|
||
{ | ||
// load S | ||
string memory key = ".responseDecoded.AttestationObject.attStmt.s"; | ||
s = json.readUint(string.concat(fixturesId, key)); | ||
} | ||
|
||
assertTrue(implem.verify(authData, clientDataJSON, challenge, r, s, qx, qy)); | ||
} | ||
} |
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,2 @@ | ||
WebAuthn256r1Test__Create | ||
└── it verify a valid create correctly |
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,42 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity >=0.8.19 <0.9.0; | ||
|
||
import { Test } from "../lib/forge-std/src/Test.sol"; | ||
import { WebAuthnWrapper } from "./WebAuthnWrapper.sol"; | ||
|
||
// TODO: generate get flow's fixtures | ||
contract WebAuthn256r1Test__Get is Test { | ||
Check warning on line 8 in test/WebAuthn256r1.get.t.sol GitHub Actions / lint
Check warning on line 8 in test/WebAuthn256r1.get.t.sol GitHub Actions / lint
|
||
WebAuthnWrapper internal implem; | ||
uint256 internal fixturesNb; | ||
|
||
function setUp() external { | ||
// deploy a wrapper contract for the library | ||
implem = new WebAuthnWrapper(); | ||
} | ||
|
||
function test_VerifyAValidCreateCorrectly() external { | ||
// it verify a valid get correctly | ||
|
||
assertTrue( | ||
implem.verify( | ||
// authenticatorData | ||
hex"49960de5880e8c687434170f6476605b8fe4aeb9a28632c7995cf3ba831d97631d00000000", | ||
// clientData | ||
hex"7b2274797065223a22776562617574686e2e676574222c226368616c6c656e6765223a226e" | ||
hex"73726d616845506775365541356c367570796f644a747a55554e356c59546c656444706e70" | ||
hex"3658634955222c226f726967696e223a22687474703a2f2f6c6f63616c686f73743a333030" | ||
hex"30222c2263726f73734f726967696e223a66616c73657d", | ||
// clientChallenge | ||
hex"9ecae66a110f82ee9403997aba9ca8749b735143799584e579d0e99e9e977085", | ||
// r | ||
0x637f5e51e5e288310958cca253c12ef632869af03b2d398afb00c7a2ddcfcdd7, | ||
// s | ||
0x0b29ee7b84c8faf6b452e4700d6bd55f93525f1e0be0800e0c1b37986d23717f, | ||
// qx | ||
0xa33941ccf9b4eac590cda2457256babd0dca8379389b7e6612ab8fba34372a5b, | ||
// qy | ||
0xabe3b0cc14188c0ea28775b79120495f504df1e0f937bcbe88b2ee00f0d22c75 | ||
) | ||
); | ||
} | ||
} |
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,2 @@ | ||
WebAuthn256r1Test__Get | ||
└── it verify a valid get correctly |
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
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
Large diffs are not rendered by default.
Oops, something went wrong.