9
9
10
10
#include " httpfake.h"
11
11
#include " logging/logging.h"
12
- #include " primary/initializer.h"
12
+ #include " primary/provisioner.h"
13
+ #include " primary/provisioner_test_utils.h"
13
14
#include " primary/sotauptaneclient.h"
14
15
#include " storage/invstorage.h"
15
16
#include " uptane/uptanerepository.h"
@@ -28,10 +29,10 @@ TEST(DeviceCredProv, DeviceIdFailure) {
28
29
29
30
auto storage = INvStorage::newStorage (config.storage );
30
31
auto http = std::make_shared<HttpFake>(temp_dir.Path ());
31
- KeyManager keys (storage, config.keymanagerConfig ());
32
+ auto keys = std::make_shared<KeyManager> (storage, config.keymanagerConfig ());
32
33
33
34
// Expect failure when trying to read the certificate to get the device ID.
34
- EXPECT_THROW ( Initializer (config.provision , storage, http, keys, {}), std:: exception );
35
+ ExpectProvisionError ( Provisioner (config.provision , storage, http, keys, {}));
35
36
}
36
37
37
38
/* *
@@ -49,10 +50,10 @@ TEST(DeviceCredProv, TlsFailure) {
49
50
50
51
auto storage = INvStorage::newStorage (config.storage );
51
52
auto http = std::make_shared<HttpFake>(temp_dir.Path ());
52
- KeyManager keys (storage, config.keymanagerConfig ());
53
+ auto keys = std::make_shared<KeyManager> (storage, config.keymanagerConfig ());
53
54
54
55
// Expect failure when trying to read the TLS credentials.
55
- EXPECT_THROW ( Initializer (config.provision , storage, http, keys, {}), Initializer::Error );
56
+ ExpectProvisionError ( Provisioner (config.provision , storage, http, keys, {}));
56
57
}
57
58
58
59
/* *
@@ -79,9 +80,9 @@ TEST(DeviceCredProv, Incomplete) {
79
80
boost::filesystem::copy_file (" tests/test_data/device_cred_prov/ca.pem" , temp_dir / " import/ca.pem" );
80
81
auto storage = INvStorage::newStorage (config.storage );
81
82
storage->importData (config.import );
82
- KeyManager keys (storage, config.keymanagerConfig ());
83
+ auto keys = std::make_shared<KeyManager> (storage, config.keymanagerConfig ());
83
84
84
- EXPECT_THROW ( Initializer (config.provision , storage, http, keys, {}), Initializer::Error );
85
+ ExpectProvisionError ( Provisioner (config.provision , storage, http, keys, {}));
85
86
}
86
87
87
88
{
@@ -93,9 +94,9 @@ TEST(DeviceCredProv, Incomplete) {
93
94
boost::filesystem::copy_file (" tests/test_data/device_cred_prov/client.pem" , temp_dir / " import/client.pem" );
94
95
auto storage = INvStorage::newStorage (config.storage );
95
96
storage->importData (config.import );
96
- KeyManager keys (storage, config.keymanagerConfig ());
97
+ auto keys = std::make_shared<KeyManager> (storage, config.keymanagerConfig ());
97
98
98
- EXPECT_THROW ( Initializer (config.provision , storage, http, keys, {}), Initializer::Error );
99
+ ExpectProvisionError ( Provisioner (config.provision , storage, http, keys, {}));
99
100
}
100
101
101
102
{
@@ -107,9 +108,9 @@ TEST(DeviceCredProv, Incomplete) {
107
108
boost::filesystem::copy_file (" tests/test_data/device_cred_prov/pkey.pem" , temp_dir / " import/pkey.pem" );
108
109
auto storage = INvStorage::newStorage (config.storage );
109
110
storage->importData (config.import );
110
- KeyManager keys (storage, config.keymanagerConfig ());
111
+ auto keys = std::make_shared<KeyManager> (storage, config.keymanagerConfig ());
111
112
112
- EXPECT_THROW ( Initializer (config.provision , storage, http, keys, {}), Initializer::Error );
113
+ ExpectProvisionError ( Provisioner (config.provision , storage, http, keys, {}));
113
114
}
114
115
115
116
{
@@ -122,9 +123,9 @@ TEST(DeviceCredProv, Incomplete) {
122
123
boost::filesystem::copy_file (" tests/test_data/device_cred_prov/client.pem" , temp_dir / " import/client.pem" );
123
124
auto storage = INvStorage::newStorage (config.storage );
124
125
storage->importData (config.import );
125
- KeyManager keys (storage, config.keymanagerConfig ());
126
+ auto keys = std::make_shared<KeyManager> (storage, config.keymanagerConfig ());
126
127
127
- EXPECT_THROW ( Initializer (config.provision , storage, http, keys, {}), Initializer::Error );
128
+ ExpectProvisionError ( Provisioner (config.provision , storage, http, keys, {}));
128
129
}
129
130
130
131
{
@@ -137,9 +138,9 @@ TEST(DeviceCredProv, Incomplete) {
137
138
boost::filesystem::copy_file (" tests/test_data/device_cred_prov/pkey.pem" , temp_dir / " import/pkey.pem" );
138
139
auto storage = INvStorage::newStorage (config.storage );
139
140
storage->importData (config.import );
140
- KeyManager keys (storage, config.keymanagerConfig ());
141
+ auto keys = std::make_shared<KeyManager> (storage, config.keymanagerConfig ());
141
142
142
- EXPECT_THROW ( Initializer (config.provision , storage, http, keys, {}), Initializer::Error );
143
+ ExpectProvisionError ( Provisioner (config.provision , storage, http, keys, {}));
143
144
}
144
145
145
146
{
@@ -152,9 +153,9 @@ TEST(DeviceCredProv, Incomplete) {
152
153
boost::filesystem::copy_file (" tests/test_data/device_cred_prov/pkey.pem" , temp_dir / " import/pkey.pem" );
153
154
auto storage = INvStorage::newStorage (config.storage );
154
155
storage->importData (config.import );
155
- KeyManager keys (storage, config.keymanagerConfig ());
156
+ auto keys = std::make_shared<KeyManager> (storage, config.keymanagerConfig ());
156
157
157
- EXPECT_THROW ( Initializer (config.provision , storage, http, keys, {}), Initializer::Error );
158
+ ExpectProvisionError ( Provisioner (config.provision , storage, http, keys, {}));
158
159
}
159
160
160
161
// Do one last round with all three files to make sure it actually works as
@@ -169,9 +170,9 @@ TEST(DeviceCredProv, Incomplete) {
169
170
boost::filesystem::copy_file (" tests/test_data/device_cred_prov/pkey.pem" , temp_dir / " import/pkey.pem" );
170
171
auto storage = INvStorage::newStorage (config.storage );
171
172
storage->importData (config.import );
172
- KeyManager keys (storage, config.keymanagerConfig ());
173
+ auto keys = std::make_shared<KeyManager> (storage, config.keymanagerConfig ());
173
174
174
- EXPECT_NO_THROW ( Initializer (config.provision , storage, http, keys, {}));
175
+ ExpectProvisionOK ( Provisioner (config.provision , storage, http, keys, {}));
175
176
}
176
177
177
178
/* *
@@ -195,9 +196,9 @@ TEST(DeviceCredProv, Success) {
195
196
auto storage = INvStorage::newStorage (config.storage );
196
197
storage->importData (config.import );
197
198
auto http = std::make_shared<HttpFake>(temp_dir.Path ());
198
- KeyManager keys (storage, config.keymanagerConfig ());
199
+ auto keys = std::make_shared<KeyManager> (storage, config.keymanagerConfig ());
199
200
200
- EXPECT_NO_THROW ( Initializer (config.provision , storage, http, keys, {}));
201
+ ExpectProvisionOK ( Provisioner (config.provision , storage, http, keys, {}));
201
202
}
202
203
203
204
/* *
@@ -226,8 +227,8 @@ TEST(DeviceCredProv, ReImportCert) {
226
227
/* prepare storage initialized with device_id from config where cert CN and device id are differen*/
227
228
auto storage = INvStorage::newStorage (config.storage );
228
229
storage->importData (config.import );
229
- KeyManager keys (storage, config.keymanagerConfig ());
230
- EXPECT_NO_THROW ( Initializer (config.provision , storage, http, keys, {}));
230
+ auto keys = std::make_shared<KeyManager> (storage, config.keymanagerConfig ());
231
+ ExpectProvisionOK ( Provisioner (config.provision , storage, http, keys, {}));
231
232
std::string device_id;
232
233
EXPECT_TRUE (storage->loadDeviceId (&device_id));
233
234
EXPECT_EQ (device_id, " AnYsTrInG" );
@@ -237,8 +238,8 @@ TEST(DeviceCredProv, ReImportCert) {
237
238
config.import .tls_clientcert_path = utils::BasedPath (" newcert.pem" );
238
239
auto storage = INvStorage::newStorage (config.storage );
239
240
EXPECT_NO_THROW (storage->importData (config.import ));
240
- KeyManager keys (storage, config.keymanagerConfig ());
241
- EXPECT_NO_THROW ( Initializer (config.provision , storage, http, keys, {}));
241
+ auto keys = std::make_shared<KeyManager> (storage, config.keymanagerConfig ());
242
+ ExpectProvisionOK ( Provisioner (config.provision , storage, http, keys, {}));
242
243
std::string device_id;
243
244
EXPECT_TRUE (storage->loadDeviceId (&device_id));
244
245
EXPECT_EQ (device_id, " AnYsTrInG" );
0 commit comments