-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
156 additions
and
10 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
54 changes: 54 additions & 0 deletions
54
packages/contracts/test/utils/JwtRegistry/JwtRegistry_isDKIMPublicKeyHashValid.t.sol
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,54 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.12; | ||
|
||
import "forge-std/Test.sol"; | ||
import "forge-std/console.sol"; | ||
import {EmailAuth, EmailAuthMsg} from "../../../src/EmailAuth.sol"; | ||
import {RecoveryController} from "../../helpers/RecoveryController.sol"; | ||
import {StructHelper} from "../../helpers/StructHelper.sol"; | ||
import {SimpleWallet} from "../../helpers/SimpleWallet.sol"; | ||
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; | ||
|
||
contract JwtRegistryTest_isDKIMPublicKeyHashValid is StructHelper { | ||
constructor() {} | ||
|
||
function setUp() public override { | ||
super.setUp(); | ||
} | ||
|
||
function testFail_isDKIMPublicKeyHashValid_invalidKid() public { | ||
string memory domainName = "54321|https://example.com|client-id-12345"; | ||
bool res = jwtRegistry.isDKIMPublicKeyHashValid( | ||
domainName, | ||
publicKeyHash | ||
); | ||
assertEq(res, true); | ||
} | ||
|
||
function testFail_isDKIMPublicKeyHashValid_invalidIss() public { | ||
string memory domainName = "12345|https://example.xyz|client-id-12345"; | ||
bool res = jwtRegistry.isDKIMPublicKeyHashValid( | ||
domainName, | ||
publicKeyHash | ||
); | ||
assertEq(res, true); | ||
} | ||
|
||
function testFail_isDKIMPublicKeyHashValid_invalidAzp() public { | ||
string memory domainName = "12345|https://example.com|client-id-54321"; | ||
bool res = jwtRegistry.isDKIMPublicKeyHashValid( | ||
domainName, | ||
publicKeyHash | ||
); | ||
assertEq(res, true); | ||
} | ||
|
||
function test_isDKIMPublicKeyHashValid() public { | ||
string memory domainName = "12345|https://example.com|client-id-12345"; | ||
bool res = jwtRegistry.isDKIMPublicKeyHashValid( | ||
domainName, | ||
publicKeyHash | ||
); | ||
assertEq(res, true); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
packages/contracts/test/utils/JwtRegistry/JwtRegistry_revokeDKIMPublicKeyHash.t.sol
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,43 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.12; | ||
|
||
import "forge-std/Test.sol"; | ||
import "forge-std/console.sol"; | ||
import {EmailAuth, EmailAuthMsg} from "../../../src/EmailAuth.sol"; | ||
import {RecoveryController} from "../../helpers/RecoveryController.sol"; | ||
import {StructHelper} from "../../helpers/StructHelper.sol"; | ||
import {SimpleWallet} from "../../helpers/SimpleWallet.sol"; | ||
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; | ||
import "@zk-email/contracts/DKIMRegistry.sol"; | ||
|
||
contract JwtRegistryTest_revokeDKIMPublicKeyHash is StructHelper { | ||
constructor() {} | ||
|
||
function setUp() public override { | ||
super.setUp(); | ||
} | ||
|
||
function testRevert_revokeDKIMPublicKeyHash_invalidDomainName() public { | ||
string memory domainName = ""; | ||
vm.expectRevert(bytes("Invalid domain name")); | ||
jwtRegistry.revokeDKIMPublicKeyHash(domainName, publicKeyHash); | ||
} | ||
|
||
function testRevert_revokeDKIMPublicKeyHash_invalidPublicKeyHash() public { | ||
string memory domainName = "12345|https://example.com|client-id-12345"; | ||
vm.expectRevert(bytes("Invalid public key hash")); | ||
jwtRegistry.revokeDKIMPublicKeyHash(domainName, bytes32(0)); | ||
} | ||
|
||
function testRevert_revokeDKIMPublicKeyHash_publicKeyHashIsNotSet() public { | ||
string memory domainName = "54321|https://example.com|client-id-12345"; | ||
vm.expectRevert(bytes("publicKeyHash is not set")); | ||
jwtRegistry.revokeDKIMPublicKeyHash(domainName, publicKeyHash); | ||
} | ||
|
||
function test_revokeDKIMPublicKeyHash() public { | ||
string memory domainName = "12345|https://example.com|client-id-12345"; | ||
jwtRegistry.revokeDKIMPublicKeyHash(domainName, publicKeyHash); | ||
assertEq(jwtRegistry.whitelistedClients("client-id-12345"), false); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
packages/contracts/test/utils/JwtRegistry/JwtRegistry_setDKIMPublicKeyHash.t.sol
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,40 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.12; | ||
|
||
import "forge-std/Test.sol"; | ||
import "forge-std/console.sol"; | ||
import {EmailAuth, EmailAuthMsg} from "../../../src/EmailAuth.sol"; | ||
import {RecoveryController} from "../../helpers/RecoveryController.sol"; | ||
import {StructHelper} from "../../helpers/StructHelper.sol"; | ||
import {SimpleWallet} from "../../helpers/SimpleWallet.sol"; | ||
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; | ||
import "@zk-email/contracts/DKIMRegistry.sol"; | ||
|
||
contract JwtRegistryTest_setDKIMPublicKeyHash is StructHelper { | ||
constructor() {} | ||
|
||
function setUp() public override { | ||
super.setUp(); | ||
} | ||
|
||
function testRevert_setDKIMPublicKeyHash_publicKeyHashIsAlreadySet() | ||
public | ||
{ | ||
string memory domainName = "12345|https://example.com|client-id-12345"; | ||
vm.expectRevert(bytes("publicKeyHash is already set")); | ||
jwtRegistry.setDKIMPublicKeyHash(domainName, publicKeyHash); | ||
} | ||
|
||
function testRevert_setDKIMPublicKeyHash_publicKeyHashIsRevoked() public { | ||
string memory domainName = "12345|https://example.com|client-id-12345"; | ||
jwtRegistry.revokeDKIMPublicKeyHash(domainName, publicKeyHash); | ||
vm.expectRevert(bytes("publicKeyHash is revoked")); | ||
jwtRegistry.setDKIMPublicKeyHash(domainName, publicKeyHash); | ||
} | ||
|
||
function test_setDKIMPublicKeyHash() public { | ||
string memory domainName = "12345|https://example.xyz|client-id-12345"; | ||
jwtRegistry.setDKIMPublicKeyHash(domainName, publicKeyHash); | ||
assertEq(jwtRegistry.whitelistedClients("client-id-12345"), true); | ||
} | ||
} |