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(DeviceCredProv, Failure) {
23 RecordProperty(
"zephyr_key",
"OTA-1209,TST-185");
27 config.provision.device_id =
"device_id";
28 config.storage.path = temp_dir.Path();
29 EXPECT_EQ(config.provision.mode, ProvisionMode::kDeviceCred);
31 auto storage = INvStorage::newStorage(config.storage);
32 auto http = std::make_shared<HttpFake>(temp_dir.Path());
33 KeyManager keys(storage, config.keymanagerConfig());
35 Initializer initializer(config.provision, storage, http, keys, {});
36 EXPECT_FALSE(initializer.isSuccessful());
43 TEST(DeviceCredProv, Incomplete) {
44 RecordProperty(
"zephyr_key",
"OTA-1209,TST-187");
48 config.provision.device_id =
"device_id";
49 config.storage.path = temp_dir.Path();
50 config.import.base_path = temp_dir /
"import";
51 EXPECT_EQ(config.provision.mode, ProvisionMode::kDeviceCred);
53 auto http = std::make_shared<HttpFake>(temp_dir.Path());
56 config.import.tls_cacert_path =
BasedPath(
"ca.pem");
57 config.import.tls_clientcert_path =
BasedPath(
"");
58 config.import.tls_pkey_path =
BasedPath(
"");
59 Utils::createDirectories(temp_dir /
"import", S_IRWXU);
60 boost::filesystem::copy_file(
"tests/test_data/device_cred_prov/ca.pem", temp_dir /
"import/ca.pem");
61 auto storage = INvStorage::newStorage(config.storage);
62 storage->importData(config.import);
63 KeyManager keys(storage, config.keymanagerConfig());
65 Initializer initializer(config.provision, storage, http, keys, {});
66 EXPECT_FALSE(initializer.isSuccessful());
70 config.import.tls_cacert_path =
BasedPath(
"");
71 config.import.tls_clientcert_path =
BasedPath(
"client.pem");
72 config.import.tls_pkey_path =
BasedPath(
"");
73 boost::filesystem::remove_all(temp_dir.Path());
74 Utils::createDirectories(temp_dir /
"import", S_IRWXU);
75 boost::filesystem::copy_file(
"tests/test_data/device_cred_prov/client.pem", temp_dir /
"import/client.pem");
76 auto storage = INvStorage::newStorage(config.storage);
77 storage->importData(config.import);
78 KeyManager keys(storage, config.keymanagerConfig());
80 Initializer initializer(config.provision, storage, http, keys, {});
81 EXPECT_FALSE(initializer.isSuccessful());
85 config.import.tls_cacert_path =
BasedPath(
"");
86 config.import.tls_clientcert_path =
BasedPath(
"");
87 config.import.tls_pkey_path =
BasedPath(
"pkey.pem");
88 boost::filesystem::remove_all(temp_dir.Path());
89 Utils::createDirectories(temp_dir /
"import", S_IRWXU);
90 boost::filesystem::copy_file(
"tests/test_data/device_cred_prov/pkey.pem", temp_dir /
"import/pkey.pem");
91 auto storage = INvStorage::newStorage(config.storage);
92 storage->importData(config.import);
93 KeyManager keys(storage, config.keymanagerConfig());
95 Initializer initializer(config.provision, storage, http, keys, {});
96 EXPECT_FALSE(initializer.isSuccessful());
100 config.import.tls_cacert_path =
BasedPath(
"ca.pem");
101 config.import.tls_clientcert_path =
BasedPath(
"client.pem");
102 config.import.tls_pkey_path =
BasedPath(
"");
103 boost::filesystem::remove_all(temp_dir.Path());
104 Utils::createDirectories(temp_dir /
"import", S_IRWXU);
105 boost::filesystem::copy_file(
"tests/test_data/device_cred_prov/ca.pem", temp_dir /
"import/ca.pem");
106 boost::filesystem::copy_file(
"tests/test_data/device_cred_prov/client.pem", temp_dir /
"import/client.pem");
107 auto storage = INvStorage::newStorage(config.storage);
108 storage->importData(config.import);
109 KeyManager keys(storage, config.keymanagerConfig());
111 Initializer initializer(config.provision, storage, http, keys, {});
112 EXPECT_FALSE(initializer.isSuccessful());
116 config.import.tls_cacert_path =
BasedPath(
"ca.pem");
117 config.import.tls_clientcert_path =
BasedPath(
"");
118 config.import.tls_pkey_path =
BasedPath(
"pkey.pem");
119 boost::filesystem::remove_all(temp_dir.Path());
120 Utils::createDirectories(temp_dir /
"import", S_IRWXU);
121 boost::filesystem::copy_file(
"tests/test_data/device_cred_prov/ca.pem", temp_dir /
"import/ca.pem");
122 boost::filesystem::copy_file(
"tests/test_data/device_cred_prov/pkey.pem", temp_dir /
"import/pkey.pem");
123 auto storage = INvStorage::newStorage(config.storage);
124 storage->importData(config.import);
125 KeyManager keys(storage, config.keymanagerConfig());
127 Initializer initializer(config.provision, storage, http, keys, {});
128 EXPECT_FALSE(initializer.isSuccessful());
132 config.import.tls_cacert_path =
BasedPath(
"");
133 config.import.tls_clientcert_path =
BasedPath(
"client.pem");
134 config.import.tls_pkey_path =
BasedPath(
"pkey.pem");
135 boost::filesystem::remove_all(temp_dir.Path());
136 Utils::createDirectories(temp_dir /
"import", S_IRWXU);
137 boost::filesystem::copy_file(
"tests/test_data/device_cred_prov/client.pem", temp_dir /
"import/client.pem");
138 boost::filesystem::copy_file(
"tests/test_data/device_cred_prov/pkey.pem", temp_dir /
"import/pkey.pem");
139 auto storage = INvStorage::newStorage(config.storage);
140 storage->importData(config.import);
141 KeyManager keys(storage, config.keymanagerConfig());
143 Initializer initializer(config.provision, storage, http, keys, {});
144 EXPECT_FALSE(initializer.isSuccessful());
149 config.import.tls_cacert_path =
BasedPath(
"ca.pem");
150 config.import.tls_clientcert_path =
BasedPath(
"client.pem");
151 config.import.tls_pkey_path =
BasedPath(
"pkey.pem");
152 boost::filesystem::remove_all(temp_dir.Path());
153 Utils::createDirectories(temp_dir /
"import", S_IRWXU);
154 boost::filesystem::copy_file(
"tests/test_data/device_cred_prov/ca.pem", temp_dir /
"import/ca.pem");
155 boost::filesystem::copy_file(
"tests/test_data/device_cred_prov/client.pem", temp_dir /
"import/client.pem");
156 boost::filesystem::copy_file(
"tests/test_data/device_cred_prov/pkey.pem", temp_dir /
"import/pkey.pem");
157 auto storage = INvStorage::newStorage(config.storage);
158 storage->importData(config.import);
159 KeyManager keys(storage, config.keymanagerConfig());
161 Initializer initializer(config.provision, storage, http, keys, {});
162 EXPECT_TRUE(initializer.isSuccessful());
168 TEST(DeviceCredProv, Success) {
169 RecordProperty(
"zephyr_key",
"OTA-996,OTA-1210,TST-186");
172 Utils::createDirectories(temp_dir /
"import", S_IRWXU);
173 boost::filesystem::copy_file(
"tests/test_data/device_cred_prov/ca.pem", temp_dir /
"import/ca.pem");
174 boost::filesystem::copy_file(
"tests/test_data/device_cred_prov/client.pem", temp_dir /
"import/client.pem");
175 boost::filesystem::copy_file(
"tests/test_data/device_cred_prov/pkey.pem", temp_dir /
"import/pkey.pem");
176 config.storage.path = temp_dir.Path();
177 config.import.base_path = temp_dir /
"import";
178 config.import.tls_cacert_path =
BasedPath(
"ca.pem");
179 config.import.tls_clientcert_path =
BasedPath(
"client.pem");
180 config.import.tls_pkey_path =
BasedPath(
"pkey.pem");
181 EXPECT_EQ(config.provision.mode, ProvisionMode::kDeviceCred);
183 auto storage = INvStorage::newStorage(config.storage);
184 storage->importData(config.import);
185 auto http = std::make_shared<HttpFake>(temp_dir.Path());
186 KeyManager keys(storage, config.keymanagerConfig());
188 Initializer initializer(config.provision, storage, http, keys, {});
189 EXPECT_TRUE(initializer.isSuccessful());
193 int main(
int argc,
char** argv) {
194 ::testing::InitGoogleTest(&argc, argv);
195 logger_set_threshold(boost::log::trivial::trace);
196 return RUN_ALL_TESTS();