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());
42 TEST(DeviceCredProv, Incomplete) {
43 RecordProperty(
"zephyr_key",
"OTA-1209,TST-187");
47 config.provision.device_id =
"device_id";
48 config.storage.path = temp_dir.Path();
49 config.import.base_path = temp_dir /
"import";
50 EXPECT_EQ(config.provision.mode, ProvisionMode::kDeviceCred);
52 auto http = std::make_shared<HttpFake>(temp_dir.Path());
55 config.import.tls_cacert_path =
BasedPath(
"ca.pem");
56 config.import.tls_clientcert_path =
BasedPath(
"");
57 config.import.tls_pkey_path =
BasedPath(
"");
58 Utils::createDirectories(temp_dir /
"import", S_IRWXU);
59 boost::filesystem::copy_file(
"tests/test_data/device_cred_prov/ca.pem", temp_dir /
"import/ca.pem");
60 auto storage = INvStorage::newStorage(config.storage);
61 storage->importData(config.import);
62 KeyManager keys(storage, config.keymanagerConfig());
68 config.import.tls_cacert_path =
BasedPath(
"");
69 config.import.tls_clientcert_path =
BasedPath(
"client.pem");
70 config.import.tls_pkey_path =
BasedPath(
"");
71 boost::filesystem::remove_all(temp_dir.Path());
72 Utils::createDirectories(temp_dir /
"import", S_IRWXU);
73 boost::filesystem::copy_file(
"tests/test_data/device_cred_prov/client.pem", temp_dir /
"import/client.pem");
74 auto storage = INvStorage::newStorage(config.storage);
75 storage->importData(config.import);
76 KeyManager keys(storage, config.keymanagerConfig());
82 config.import.tls_cacert_path =
BasedPath(
"");
83 config.import.tls_clientcert_path =
BasedPath(
"");
84 config.import.tls_pkey_path =
BasedPath(
"pkey.pem");
85 boost::filesystem::remove_all(temp_dir.Path());
86 Utils::createDirectories(temp_dir /
"import", S_IRWXU);
87 boost::filesystem::copy_file(
"tests/test_data/device_cred_prov/pkey.pem", temp_dir /
"import/pkey.pem");
88 auto storage = INvStorage::newStorage(config.storage);
89 storage->importData(config.import);
90 KeyManager keys(storage, config.keymanagerConfig());
96 config.import.tls_cacert_path =
BasedPath(
"ca.pem");
97 config.import.tls_clientcert_path =
BasedPath(
"client.pem");
98 config.import.tls_pkey_path =
BasedPath(
"");
99 boost::filesystem::remove_all(temp_dir.Path());
100 Utils::createDirectories(temp_dir /
"import", S_IRWXU);
101 boost::filesystem::copy_file(
"tests/test_data/device_cred_prov/ca.pem", temp_dir /
"import/ca.pem");
102 boost::filesystem::copy_file(
"tests/test_data/device_cred_prov/client.pem", temp_dir /
"import/client.pem");
103 auto storage = INvStorage::newStorage(config.storage);
104 storage->importData(config.import);
105 KeyManager keys(storage, config.keymanagerConfig());
111 config.import.tls_cacert_path =
BasedPath(
"ca.pem");
112 config.import.tls_clientcert_path =
BasedPath(
"");
113 config.import.tls_pkey_path =
BasedPath(
"pkey.pem");
114 boost::filesystem::remove_all(temp_dir.Path());
115 Utils::createDirectories(temp_dir /
"import", S_IRWXU);
116 boost::filesystem::copy_file(
"tests/test_data/device_cred_prov/ca.pem", temp_dir /
"import/ca.pem");
117 boost::filesystem::copy_file(
"tests/test_data/device_cred_prov/pkey.pem", temp_dir /
"import/pkey.pem");
118 auto storage = INvStorage::newStorage(config.storage);
119 storage->importData(config.import);
120 KeyManager keys(storage, config.keymanagerConfig());
126 config.import.tls_cacert_path =
BasedPath(
"");
127 config.import.tls_clientcert_path =
BasedPath(
"client.pem");
128 config.import.tls_pkey_path =
BasedPath(
"pkey.pem");
129 boost::filesystem::remove_all(temp_dir.Path());
130 Utils::createDirectories(temp_dir /
"import", S_IRWXU);
131 boost::filesystem::copy_file(
"tests/test_data/device_cred_prov/client.pem", temp_dir /
"import/client.pem");
132 boost::filesystem::copy_file(
"tests/test_data/device_cred_prov/pkey.pem", temp_dir /
"import/pkey.pem");
133 auto storage = INvStorage::newStorage(config.storage);
134 storage->importData(config.import);
135 KeyManager keys(storage, config.keymanagerConfig());
142 config.import.tls_cacert_path =
BasedPath(
"ca.pem");
143 config.import.tls_clientcert_path =
BasedPath(
"client.pem");
144 config.import.tls_pkey_path =
BasedPath(
"pkey.pem");
145 boost::filesystem::remove_all(temp_dir.Path());
146 Utils::createDirectories(temp_dir /
"import", S_IRWXU);
147 boost::filesystem::copy_file(
"tests/test_data/device_cred_prov/ca.pem", temp_dir /
"import/ca.pem");
148 boost::filesystem::copy_file(
"tests/test_data/device_cred_prov/client.pem", temp_dir /
"import/client.pem");
149 boost::filesystem::copy_file(
"tests/test_data/device_cred_prov/pkey.pem", temp_dir /
"import/pkey.pem");
150 auto storage = INvStorage::newStorage(config.storage);
151 storage->importData(config.import);
152 KeyManager keys(storage, config.keymanagerConfig());
154 EXPECT_NO_THROW(
Initializer(config.provision, storage, http, keys, {}));
160 TEST(DeviceCredProv, Success) {
161 RecordProperty(
"zephyr_key",
"OTA-996,OTA-1210,TST-186");
164 Utils::createDirectories(temp_dir /
"import", S_IRWXU);
165 boost::filesystem::copy_file(
"tests/test_data/device_cred_prov/ca.pem", temp_dir /
"import/ca.pem");
166 boost::filesystem::copy_file(
"tests/test_data/device_cred_prov/client.pem", temp_dir /
"import/client.pem");
167 boost::filesystem::copy_file(
"tests/test_data/device_cred_prov/pkey.pem", temp_dir /
"import/pkey.pem");
168 config.storage.path = temp_dir.Path();
169 config.import.base_path = temp_dir /
"import";
170 config.import.tls_cacert_path =
BasedPath(
"ca.pem");
171 config.import.tls_clientcert_path =
BasedPath(
"client.pem");
172 config.import.tls_pkey_path =
BasedPath(
"pkey.pem");
173 EXPECT_EQ(config.provision.mode, ProvisionMode::kDeviceCred);
175 auto storage = INvStorage::newStorage(config.storage);
176 storage->importData(config.import);
177 auto http = std::make_shared<HttpFake>(temp_dir.Path());
178 KeyManager keys(storage, config.keymanagerConfig());
180 EXPECT_NO_THROW(
Initializer(config.provision, storage, http, keys, {}));
184 int main(
int argc,
char** argv) {
185 ::testing::InitGoogleTest(&argc, argv);
186 logger_set_threshold(boost::log::trivial::trace);
187 return RUN_ALL_TESTS();