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, DeviceIdFailure) {
23 RecordProperty(
"zephyr_key",
"OTA-1209,TST-185");
26 config.storage.path = temp_dir.Path();
27 EXPECT_EQ(config.provision.mode, ProvisionMode::kDeviceCred);
29 auto storage = INvStorage::newStorage(config.storage);
30 auto http = std::make_shared<HttpFake>(temp_dir.Path());
31 KeyManager keys(storage, config.keymanagerConfig());
34 EXPECT_THROW(
Initializer(config.provision, storage, http, keys, {}), std::exception);
41 TEST(DeviceCredProv, TlsFailure) {
42 RecordProperty(
"zephyr_key",
"OTA-1209,TST-185");
46 config.provision.device_id =
"device_id";
47 config.storage.path = temp_dir.Path();
48 EXPECT_EQ(config.provision.mode, ProvisionMode::kDeviceCred);
50 auto storage = INvStorage::newStorage(config.storage);
51 auto http = std::make_shared<HttpFake>(temp_dir.Path());
52 KeyManager keys(storage, config.keymanagerConfig());
62 TEST(DeviceCredProv, Incomplete) {
63 RecordProperty(
"zephyr_key",
"OTA-1209,TST-187");
67 config.provision.device_id =
"device_id";
68 config.storage.path = temp_dir.Path();
69 config.import.base_path = temp_dir /
"import";
70 EXPECT_EQ(config.provision.mode, ProvisionMode::kDeviceCred);
72 auto http = std::make_shared<HttpFake>(temp_dir.Path());
78 Utils::createDirectories(temp_dir /
"import", S_IRWXU);
79 boost::filesystem::copy_file(
"tests/test_data/device_cred_prov/ca.pem", temp_dir /
"import/ca.pem");
80 auto storage = INvStorage::newStorage(config.storage);
81 storage->importData(config.import);
82 KeyManager keys(storage, config.keymanagerConfig());
91 boost::filesystem::remove_all(temp_dir.Path());
92 Utils::createDirectories(temp_dir /
"import", S_IRWXU);
93 boost::filesystem::copy_file(
"tests/test_data/device_cred_prov/client.pem", temp_dir /
"import/client.pem");
94 auto storage = INvStorage::newStorage(config.storage);
95 storage->importData(config.import);
96 KeyManager keys(storage, config.keymanagerConfig());
105 boost::filesystem::remove_all(temp_dir.Path());
106 Utils::createDirectories(temp_dir /
"import", S_IRWXU);
107 boost::filesystem::copy_file(
"tests/test_data/device_cred_prov/pkey.pem", temp_dir /
"import/pkey.pem");
108 auto storage = INvStorage::newStorage(config.storage);
109 storage->importData(config.import);
110 KeyManager keys(storage, config.keymanagerConfig());
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/client.pem", temp_dir /
"import/client.pem");
123 auto storage = INvStorage::newStorage(config.storage);
124 storage->importData(config.import);
125 KeyManager keys(storage, config.keymanagerConfig());
134 boost::filesystem::remove_all(temp_dir.Path());
135 Utils::createDirectories(temp_dir /
"import", S_IRWXU);
136 boost::filesystem::copy_file(
"tests/test_data/device_cred_prov/ca.pem", temp_dir /
"import/ca.pem");
137 boost::filesystem::copy_file(
"tests/test_data/device_cred_prov/pkey.pem", temp_dir /
"import/pkey.pem");
138 auto storage = INvStorage::newStorage(config.storage);
139 storage->importData(config.import);
140 KeyManager keys(storage, config.keymanagerConfig());
149 boost::filesystem::remove_all(temp_dir.Path());
150 Utils::createDirectories(temp_dir /
"import", S_IRWXU);
151 boost::filesystem::copy_file(
"tests/test_data/device_cred_prov/client.pem", temp_dir /
"import/client.pem");
152 boost::filesystem::copy_file(
"tests/test_data/device_cred_prov/pkey.pem", temp_dir /
"import/pkey.pem");
153 auto storage = INvStorage::newStorage(config.storage);
154 storage->importData(config.import);
155 KeyManager keys(storage, config.keymanagerConfig());
165 boost::filesystem::remove_all(temp_dir.Path());
166 Utils::createDirectories(temp_dir /
"import", S_IRWXU);
167 boost::filesystem::copy_file(
"tests/test_data/device_cred_prov/ca.pem", temp_dir /
"import/ca.pem");
168 boost::filesystem::copy_file(
"tests/test_data/device_cred_prov/client.pem", temp_dir /
"import/client.pem");
169 boost::filesystem::copy_file(
"tests/test_data/device_cred_prov/pkey.pem", temp_dir /
"import/pkey.pem");
170 auto storage = INvStorage::newStorage(config.storage);
171 storage->importData(config.import);
172 KeyManager keys(storage, config.keymanagerConfig());
174 EXPECT_NO_THROW(
Initializer(config.provision, storage, http, keys, {}));
180 TEST(DeviceCredProv, Success) {
181 RecordProperty(
"zephyr_key",
"OTA-996,OTA-1210,TST-186");
184 Utils::createDirectories(temp_dir /
"import", S_IRWXU);
185 boost::filesystem::copy_file(
"tests/test_data/device_cred_prov/ca.pem", temp_dir /
"import/ca.pem");
186 boost::filesystem::copy_file(
"tests/test_data/device_cred_prov/client.pem", temp_dir /
"import/client.pem");
187 boost::filesystem::copy_file(
"tests/test_data/device_cred_prov/pkey.pem", temp_dir /
"import/pkey.pem");
188 config.storage.path = temp_dir.Path();
189 config.import.base_path = temp_dir /
"import";
193 EXPECT_EQ(config.provision.mode, ProvisionMode::kDeviceCred);
195 auto storage = INvStorage::newStorage(config.storage);
196 storage->importData(config.import);
197 auto http = std::make_shared<HttpFake>(temp_dir.Path());
198 KeyManager keys(storage, config.keymanagerConfig());
200 EXPECT_NO_THROW(
Initializer(config.provision, storage, http, keys, {}));
204 int main(
int argc,
char** argv) {
205 ::testing::InitGoogleTest(&argc, argv);
206 logger_set_threshold(boost::log::trivial::trace);
207 return RUN_ALL_TESTS();