1 #include <gtest/gtest.h> 3 #include <boost/format.hpp> 5 #include "cert_provider_test.h" 6 #include "libaktualizr/config.h" 7 #include "utilities/utils.h" 9 static boost::filesystem::path CERT_PROVIDER_PATH;
10 static boost::filesystem::path CREDENTIALS_PATH;
16 : test_dir{tmp_dir.PathString()}, credentials_path(tmp_dir.Path() /
"credentials.zip") {
17 boost::filesystem::copy_file(cred_path_in, credentials_path);
20 const std::string test_dir;
21 const std::string fleet_ca_cert =
"tests/test_data/CAcert.pem";
22 const std::string fleet_ca_private_key =
"tests/test_data/CApkey.pem";
23 const boost::filesystem::path credentials_path;
27 TestArgs test_args_{tmp_dir_, CREDENTIALS_PATH.string()};
44 args.credentialFile = test_args_.credentials_path.string();
45 args.localDir = test_args_.test_dir;
46 args.provideRootCA.set();
47 args.provideServerURL.set();
49 device_cred_gen_.run(args);
50 ASSERT_EQ(device_cred_gen_.lastExitCode(), 0) << device_cred_gen_.lastStdErr();
54 ASSERT_TRUE(boost::filesystem::exists(device_cred_path.privateKeyFileFullPath))
55 << device_cred_path.privateKeyFileFullPath;
56 ASSERT_TRUE(boost::filesystem::exists(device_cred_path.certFileFullPath)) << device_cred_path.certFileFullPath;
58 ASSERT_TRUE(boost::filesystem::exists(device_cred_path.serverRootCAFullPath))
59 << device_cred_path.serverRootCAFullPath;
60 ASSERT_TRUE(boost::filesystem::exists(device_cred_path.gtwURLFileFullPath)) << device_cred_path.gtwURLFileFullPath;
62 Process openssl(
"/usr/bin/openssl");
64 openssl.run({
"verify",
"-verbose",
"-CAfile", device_cred_path.serverRootCAFullPath.string(),
65 device_cred_path.certFileFullPath.string()});
66 ASSERT_EQ(openssl.lastExitCode(), 0) << openssl.lastStdErr();
67 ASSERT_EQ(openssl.lastStdOut(), str(boost::format(
"%1%: OK\n") % device_cred_path.certFileFullPath.string()));
71 int main(
int argc,
char** argv) {
72 ::testing::InitGoogleTest(&argc, argv);
75 std::cerr <<
"Two arguments are required: <path-to-cert-provider> <path-to-credentials>" << std::endl;
79 CERT_PROVIDER_PATH = argv[1];
80 std::cout <<
"Path to the cert-provider executable: " << CERT_PROVIDER_PATH << std::endl;
82 CREDENTIALS_PATH = argv[2];
83 std::cout <<
"Path to the shared provisioning credentials: " << CREDENTIALS_PATH << std::endl;
85 int test_run_res = RUN_ALL_TESTS();