MCPcopy Create free account
hub / github.com/Icinga/icinga2 / AddCaFixture

Method AddCaFixture

test/remote-certificate-fixture.cpp:43–96  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

41}
42
43void RequiresCertificate::AddCaFixture(const String& caFixtureName)
44{
45 boost::unit_test::decorator::base_ptr certLabel{new boost::unit_test::label{"cert"}};
46 auto& mts = boost::unit_test::framework::master_test_suite();
47
48 auto* setup = boost::unit_test::make_test_case(
49 []() {
50 CertificateFixture certFixture;
51 PkiUtility::NewCa();
52 auto persistentCaPath = CertificateFixture::m_PersistentCertsDir / "ca";
53 auto persistentCertsPath = CertificateFixture::m_PersistentCertsDir / "certs";
54 Utility::CopyFile((certFixture.m_CaDir / "ca.crt").string(), (persistentCaPath / "ca.crt").string());
55 Utility::CopyFile((certFixture.m_CaDir / "ca.crt").string(), (persistentCertsPath / "ca.crt").string());
56 Utility::CopyFile((certFixture.m_CaDir / "ca.key").string(), (persistentCaPath / "ca.key").string());
57
58 BOOST_REQUIRE(Utility::PathExists((persistentCaPath / "ca.crt").string()));
59 BOOST_REQUIRE(Utility::PathExists((persistentCertsPath / "ca.crt").string()));
60 BOOST_REQUIRE(Utility::PathExists((persistentCaPath / "ca.key").string()));
61 },
62 caFixtureName.GetData() + "_setup",
63 __FILE__,
64 __LINE__
65 );
66
67 setup->p_decorators.value.emplace_back(new CTestProperties{"FIXTURES_SETUP " + caFixtureName});
68 setup->p_decorators.value.emplace_back(certLabel);
69 mts.add(setup);
70
71 /* This ensures that tests operating under a different prefix will wait for the
72 * cleanup of another prefix to complete. For example if a group of tests operate
73 * destructively on certs or the CA, they would request their own prefix and
74 * this would ensure that the tests using that prefix run either before or after
75 * other tests.
76 */
77 if (!m_CaFixtures.empty()) {
78 setup->p_decorators.value.emplace_back(new CTestProperties{"DEPENDS " + m_CaFixtures.back() + "_cleanup"});
79 }
80
81 auto* cleanup = boost::unit_test::make_test_case(
82 []() {
83 BOOST_REQUIRE(Utility::PathExists(CertificateFixture::m_PersistentCertsDir.string()));
84 Utility::RemoveDirRecursive(CertificateFixture::m_PersistentCertsDir.string());
85 },
86 caFixtureName.GetData() + "_cleanup",
87 __FILE__,
88 __LINE__
89 );
90
91 cleanup->p_decorators.value.emplace_back(new CTestProperties{"FIXTURES_CLEANUP " + caFixtureName});
92 cleanup->p_decorators.value.emplace_back(certLabel);
93 mts.add(cleanup);
94
95 m_CaFixtures.emplace_back(caFixtureName);
96}
97
98void RequiresCertificate::AddCertFixture(const String& cn, const String& caFixture, const String& certFixture)
99{

Callers

nothing calls this directly

Calls 3

PathExistsFunction · 0.85
stringMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected