5 #include <gtest/gtest.h> 7 #include <boost/filesystem.hpp> 8 #include <boost/smart_ptr/make_shared.hpp> 11 #include "logging/logging.h" 12 #include "primary/initializer.h" 13 #include "primary/sotauptaneclient.h" 14 #include "storage/invstorage.h" 15 #include "uptane/uptanerepository.h" 16 #include "utilities/utils.h" 22 TEST(UptaneImplicit, ImplicitFailure) {
24 config.provision.device_id =
"device_id";
27 config.storage.path = temp_dir.Path();
28 config.storage.uptane_metadata_path =
BasedPath(
"metadata");
29 config.storage.tls_cacert_path =
BasedPath(
"ca.pem");
30 config.storage.tls_clientcert_path =
BasedPath(
"client.pem");
31 config.storage.tls_pkey_path =
BasedPath(
"pkey.pem");
32 config.postUpdateValues();
34 auto storage = INvStorage::newStorage(config.storage);
35 auto http = std::make_shared<HttpFake>(temp_dir.Path());
36 KeyManager keys(storage, config.keymanagerConfig());
38 Initializer initializer(config.provision, storage, http, keys, {});
39 EXPECT_FALSE(initializer.isSuccessful());
46 TEST(UptaneImplicit, ImplicitIncomplete) {
49 config.storage.path = temp_dir.Path();
50 config.storage.tls_cacert_path =
BasedPath(
"ca.pem");
51 config.storage.tls_clientcert_path =
BasedPath(
"client.pem");
52 config.storage.tls_pkey_path =
BasedPath(
"pkey.pem");
53 config.provision.device_id =
"device_id";
54 config.postUpdateValues();
56 auto http = std::make_shared<HttpFake>(temp_dir.Path());
59 boost::filesystem::create_directory(temp_dir.Path());
60 boost::filesystem::copy_file(
"tests/test_data/implicit/ca.pem", temp_dir.Path() /
"ca.pem");
61 auto storage = INvStorage::newStorage(config.storage);
62 KeyManager keys(storage, config.keymanagerConfig());
64 Initializer initializer(config.provision, storage, http, keys, {});
65 EXPECT_FALSE(initializer.isSuccessful());
69 boost::filesystem::remove_all(temp_dir.Path());
70 boost::filesystem::create_directory(temp_dir.Path());
71 boost::filesystem::copy_file(
"tests/test_data/implicit/client.pem", temp_dir.Path() /
"client.pem");
72 auto storage = INvStorage::newStorage(config.storage);
73 KeyManager keys(storage, config.keymanagerConfig());
75 Initializer initializer(config.provision, storage, http, keys, {});
76 EXPECT_FALSE(initializer.isSuccessful());
80 boost::filesystem::remove_all(temp_dir.Path());
81 boost::filesystem::create_directory(temp_dir.Path());
82 boost::filesystem::copy_file(
"tests/test_data/implicit/pkey.pem", temp_dir.Path() /
"pkey.pem");
83 auto storage = INvStorage::newStorage(config.storage);
84 KeyManager keys(storage, config.keymanagerConfig());
86 Initializer initializer(config.provision, storage, http, keys, {});
87 EXPECT_FALSE(initializer.isSuccessful());
91 boost::filesystem::remove_all(temp_dir.Path());
92 boost::filesystem::create_directory(temp_dir.Path());
93 boost::filesystem::copy_file(
"tests/test_data/implicit/ca.pem", temp_dir.Path() /
"ca.pem");
94 boost::filesystem::copy_file(
"tests/test_data/implicit/client.pem", temp_dir.Path() /
"client.pem");
95 auto storage = INvStorage::newStorage(config.storage);
96 KeyManager keys(storage, config.keymanagerConfig());
98 Initializer initializer(config.provision, storage, http, keys, {});
99 EXPECT_FALSE(initializer.isSuccessful());
103 boost::filesystem::remove_all(temp_dir.Path());
104 boost::filesystem::create_directory(temp_dir.Path());
105 boost::filesystem::copy_file(
"tests/test_data/implicit/ca.pem", temp_dir.Path() /
"ca.pem");
106 boost::filesystem::copy_file(
"tests/test_data/implicit/pkey.pem", temp_dir.Path() /
"pkey.pem");
107 auto storage = INvStorage::newStorage(config.storage);
108 KeyManager keys(storage, config.keymanagerConfig());
110 Initializer initializer(config.provision, storage, http, keys, {});
111 EXPECT_FALSE(initializer.isSuccessful());
115 boost::filesystem::remove_all(temp_dir.Path());
116 boost::filesystem::create_directory(temp_dir.Path());
117 boost::filesystem::copy_file(
"tests/test_data/implicit/client.pem", temp_dir.Path() /
"client.pem");
118 boost::filesystem::copy_file(
"tests/test_data/implicit/pkey.pem", temp_dir.Path() /
"pkey.pem");
119 auto storage = INvStorage::newStorage(config.storage);
120 KeyManager keys(storage, config.keymanagerConfig());
122 Initializer initializer(config.provision, storage, http, keys, {});
123 EXPECT_FALSE(initializer.isSuccessful());
131 TEST(UptaneImplicit, ImplicitProvision) {
134 boost::filesystem::copy_file(
"tests/test_data/implicit/ca.pem", temp_dir /
"ca.pem");
135 boost::filesystem::copy_file(
"tests/test_data/implicit/client.pem", temp_dir /
"client.pem");
136 boost::filesystem::copy_file(
"tests/test_data/implicit/pkey.pem", temp_dir /
"pkey.pem");
137 config.storage.path = temp_dir.Path();
138 config.storage.tls_cacert_path =
BasedPath(
"ca.pem");
139 config.storage.tls_clientcert_path =
BasedPath(
"client.pem");
140 config.storage.tls_pkey_path =
BasedPath(
"pkey.pem");
142 auto storage = INvStorage::newStorage(config.storage);
143 auto http = std::make_shared<HttpFake>(temp_dir.Path());
144 KeyManager keys(storage, config.keymanagerConfig());
146 Initializer initializer(config.provision, storage, http, keys, {});
147 EXPECT_TRUE(initializer.isSuccessful());
151 int main(
int argc,
char** argv) {
152 ::testing::InitGoogleTest(&argc, argv);
153 logger_set_threshold(boost::log::trivial::trace);
154 return RUN_ALL_TESTS();
Configuration object for an aktualizr instance running on a primary ECU.
TEST(UptaneImplicit, ImplicitFailure)