Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parallel test execution #27

Merged
merged 1 commit into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions scripts/gencert.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/bin/env bash
set -eu

out_certs_dir=./test/.tmp/testcerts
signing_rsa_bits=2048
signing_exponent=65537

Expand Down Expand Up @@ -41,23 +40,24 @@ function gen_ecdsa_signing_cert() {
}

function usage() {
echo "Usage: $0 {gen_rsa_root_cert|gen_rsa_signing_cert|gen_ecdsa_root_cert|gen_ecdsa_signing_cert}"
echo "Usage: $0 <out_certs_dir> {gen_rsa_root_cert|gen_rsa_signing_cert|gen_ecdsa_root_cert|gen_ecdsa_signing_cert}"
exit 1
}

if [ $# -eq 0 ]; then
if [ $# -lt 2 ]; then
usage
fi

out_certs_dir=$1
mkdir -p ${out_certs_dir}

case "$1" in
case "$2" in
"gen_rsa_root_cert")
gen_rsa_root_cert
;;
"gen_rsa_signing_cert")
signing_rsa_bits=$2
signing_exponent=$3
signing_rsa_bits=$3
signing_exponent=$4
gen_rsa_signing_cert
;;
"gen_ecdsa_root_cert")
Expand Down
55 changes: 31 additions & 24 deletions test/CertificateTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ contract CertificateTest is BasicTest {
);
}

string internal constant testCertsDir = "./test/.tmp/testcerts";
string internal constant testCertsBaseDir = "./test/.tmp/testcerts";
string internal constant genCertCmd = "./scripts/gencert.sh";

struct RSAParamsCase {
Expand All @@ -80,17 +80,18 @@ contract CertificateTest is BasicTest {
}

function testValidSigningCerts() public {
string memory testCertsDir = string(abi.encodePacked(testCertsBaseDir, "/", "valid_signing_certs"));
RSAParamsCase[4] memory cases = [
RSAParamsCase("2048", "65537"),
RSAParamsCase("2048", "3"),
RSAParamsCase("4096", "65537"),
RSAParamsCase("4096", "3")
];
vm.warp(1795167418);
cleanupTestCerts();
genRsaRootCert();
cleanupTestCerts(testCertsDir);
genRsaRootCert(testCertsDir);
for (uint256 i = 0; i < cases.length; i++) {
genRsaSigningCert(cases[i].bits, cases[i].exponent);
genRsaSigningCert(testCertsDir, cases[i].bits, cases[i].exponent);
AVRValidator.RSAParams memory rootParams = AVRValidator.verifyRootCACert(
vm.readFileBinary(string(abi.encodePacked(testCertsDir, "/root.crt.der")))
);
Expand All @@ -103,19 +104,21 @@ contract CertificateTest is BasicTest {
}

function testInvalidRootCerts() public {
string memory testCertsDir = string(abi.encodePacked(testCertsBaseDir, "/", "invalid_root_certs"));
vm.warp(1795167418);
cleanupTestCerts();
genEcdsaRootCert();
cleanupTestCerts(testCertsDir);
genEcdsaRootCert(testCertsDir);

vm.expectRevert();
AVRValidator.verifyRootCACert(vm.readFileBinary(string(abi.encodePacked(testCertsDir, "/root.crt.der"))));
}

function testInvalidSigningCerts() public {
string memory testCertsDir = string(abi.encodePacked(testCertsBaseDir, "/", "invalid_signing_certs"));
vm.warp(1795167418);
cleanupTestCerts();
genRsaRootCert();
genEcdsaSigningCert();
cleanupTestCerts(testCertsDir);
genRsaRootCert(testCertsDir);
genEcdsaSigningCert(testCertsDir);

AVRValidator.RSAParams memory rootParams =
AVRValidator.verifyRootCACert(vm.readFileBinary(string(abi.encodePacked(testCertsDir, "/root.crt.der"))));
Expand All @@ -127,41 +130,45 @@ contract CertificateTest is BasicTest {
);
}

function cleanupTestCerts() internal {
function cleanupTestCerts(string memory testCertsDir) internal {
string[] memory cmd = new string[](3);
cmd[0] = "rm";
cmd[1] = "-rf";
cmd[2] = testCertsDir;
runCmd(cmd);
}

function genRsaRootCert() internal {
string[] memory cmd = new string[](2);
function genRsaRootCert(string memory testCertsDir) internal {
string[] memory cmd = new string[](3);
cmd[0] = genCertCmd;
cmd[1] = "gen_rsa_root_cert";
cmd[1] = testCertsDir;
cmd[2] = "gen_rsa_root_cert";
runCmd(cmd);
}

function genRsaSigningCert(string memory bits, string memory exponent) internal {
string[] memory cmd = new string[](4);
function genRsaSigningCert(string memory testCertsDir, string memory bits, string memory exponent) internal {
string[] memory cmd = new string[](5);
cmd[0] = genCertCmd;
cmd[1] = "gen_rsa_signing_cert";
cmd[2] = bits;
cmd[3] = exponent;
cmd[1] = testCertsDir;
cmd[2] = "gen_rsa_signing_cert";
cmd[3] = bits;
cmd[4] = exponent;
runCmd(cmd);
}

function genEcdsaRootCert() internal {
string[] memory cmd = new string[](2);
function genEcdsaRootCert(string memory testCertsDir) internal {
string[] memory cmd = new string[](3);
cmd[0] = genCertCmd;
cmd[1] = "gen_ecdsa_root_cert";
cmd[1] = testCertsDir;
cmd[2] = "gen_ecdsa_root_cert";
runCmd(cmd);
}

function genEcdsaSigningCert() internal {
string[] memory cmd = new string[](2);
function genEcdsaSigningCert(string memory testCertsDir) internal {
string[] memory cmd = new string[](3);
cmd[0] = genCertCmd;
cmd[1] = "gen_ecdsa_signing_cert";
cmd[1] = testCertsDir;
cmd[2] = "gen_ecdsa_signing_cert";
runCmd(cmd);
}

Expand Down