Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated test cases
Browse files Browse the repository at this point in the history
Signed-off-by: AssemblyJohn <ioan.bogdann@gmail.com>
AssemblyJohn committed May 8, 2024
1 parent f71b51b commit 6e702ef
Showing 2 changed files with 24 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lib/evse_security/evse_security.cpp
Original file line number Diff line number Diff line change
@@ -1353,18 +1353,20 @@ GetCertificateInfoResult EvseSecurity::get_ca_certificate_info_internal(CaCertif
for (auto& root : hierarchy.get_hierarchy()) {
if (root.certificate.is_selfsigned() && root.certificate.is_valid()) {
CertificateInfo info;
result.info = info;
info.certificate = root.certificate.get_file().value();
info.certificate_single = root.certificate.get_file().value();

result.info.value().certificate = root.certificate.get_file().value();
result.info = info;
result.status = GetCertificateInfoStatus::Accepted;
return result;
}
}
} else {
CertificateInfo info;
result.info = info;
info.certificate = verify_file.get_path();
info.certificate_single = verify_file.get_path();

result.info.value().certificate = verify_file.get_path();
result.info = info;
result.status = GetCertificateInfoStatus::Accepted;
return result;
}
@@ -1393,7 +1395,7 @@ std::string EvseSecurity::get_verify_file(CaCertificateType certificate_type) {

if (result.status == GetCertificateInfoStatus::Accepted && result.info.has_value()) {
if (result.info.value().certificate.has_value()) {
result.info.value().certificate.value().string();
return result.info.value().certificate.value().string();
}
}

17 changes: 17 additions & 0 deletions tests/tests.cpp
Original file line number Diff line number Diff line change
@@ -463,10 +463,27 @@ TEST_F(EvseSecurityTests, verify_v2g_cert_02) {
ASSERT_TRUE(result != InstallCertificateResult::Accepted);
}

TEST_F(EvseSecurityTests, retrieve_root_ca) {
std::string path = "certs/ca/v2g/V2G_CA_BUNDLE.pem";
std::string retrieved_path = this->evse_security->get_verify_file(CaCertificateType::V2G);

ASSERT_EQ(path, retrieved_path);
}

TEST_F(EvseSecurityTests, install_root_ca_01) {
const auto v2g_root_ca = read_file_to_string(fs::path("certs/ca/v2g/V2G_ROOT_CA_NEW.pem"));
const auto result = this->evse_security->install_ca_certificate(v2g_root_ca, CaCertificateType::V2G);
ASSERT_TRUE(result == InstallCertificateResult::Accepted);

std::string path = "certs/ca/v2g/V2G_CA_BUNDLE.pem";
ASSERT_EQ(this->evse_security->get_verify_file(CaCertificateType::V2G), path);

const auto read_v2g_root_ca = read_file_to_string(path);
X509CertificateBundle root_bundle(read_v2g_root_ca, EncodingFormat::PEM);
X509Wrapper new_root(v2g_root_ca, EncodingFormat::PEM);

// Assert it was really installed
ASSERT_TRUE(root_bundle.contains_certificate(new_root));
}

TEST_F(EvseSecurityTests, install_root_ca_02) {

0 comments on commit 6e702ef

Please sign in to comment.