1 #include <gtest/gtest.h>
3 #include <boost/format.hpp>
5 #include "cert_provider_test.h"
6 #include "config/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(cred_path) {}
18 const std::string test_dir;
19 const std::string fleet_ca_cert =
"tests/test_data/CAcert.pem";
20 const std::string fleet_ca_private_key =
"tests/test_data/CApkey.pem";
21 const std::string credentials_path;
26 TestArgs test_args_{tmp_dir_, CREDENTIALS_PATH.string()};
41 if (test_args_.credentials_path.empty()) {
43 SUCCEED() <<
"A path to the credentials file hasn't been proided, so skip the test";
49 args.credentialFile = test_args_.credentials_path;
50 args.localDir = test_args_.test_dir;
51 args.provideRootCA.set();
52 args.provideServerURL.set();
54 device_cred_gen_.run(args);
55 ASSERT_EQ(device_cred_gen_.lastExitCode(), 0) << device_cred_gen_.lastStdErr();
59 ASSERT_TRUE(boost::filesystem::exists(device_cred_path.privateKeyFileFullPath))
60 << device_cred_path.privateKeyFileFullPath;
61 ASSERT_TRUE(boost::filesystem::exists(device_cred_path.certFileFullPath)) << device_cred_path.certFileFullPath;
63 ASSERT_TRUE(boost::filesystem::exists(device_cred_path.serverRootCAFullPath))
64 << device_cred_path.serverRootCAFullPath;
65 ASSERT_TRUE(boost::filesystem::exists(device_cred_path.gtwURLFileFullPath)) << device_cred_path.gtwURLFileFullPath;
67 Process openssl(
"/usr/bin/openssl");
69 openssl.run({
"verify",
"-verbose",
"-CAfile", device_cred_path.serverRootCAFullPath.string(),
70 device_cred_path.certFileFullPath.string()});
71 ASSERT_EQ(openssl.lastExitCode(), 0) << openssl.lastStdErr();
72 ASSERT_EQ(openssl.lastStdOut(), str(boost::format(
"%1%: OK\n") % device_cred_path.certFileFullPath.string()));
76 int main(
int argc,
char** argv) {
77 ::testing::InitGoogleTest(&argc, argv);
80 std::cerr <<
"Two arguments are required: <path-to-cert-provider> <path-to-credentials>" << std::endl;
84 CERT_PROVIDER_PATH = argv[1];
85 std::cout <<
"Path to the cert-provider executable: " << CERT_PROVIDER_PATH << std::endl;
87 CREDENTIALS_PATH = argv[2];
88 std::cout <<
"Path to the shared provisioning credentials: " << CREDENTIALS_PATH << std::endl;
90 int test_run_res = RUN_ALL_TESTS();