Aktualizr
C++ SOTA Client
uptane_implicit_test.cc
Go to the documentation of this file.
1 /**
2  * \file
3  */
4 
5 #include <gtest/gtest.h>
6 
7 #include <boost/filesystem.hpp>
8 #include <boost/smart_ptr/make_shared.hpp>
9 
10 #include "httpfake.h"
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"
17 
18 /**
19  * \verify{\tst{185}} Verify that when using implicit provisioning, aktualizr
20  * halts if credentials are not available.
21  */
22 TEST(UptaneImplicit, ImplicitFailure) {
23  Config config;
24  config.provision.device_id = "device_id";
25 
26  TemporaryDirectory temp_dir;
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();
33 
34  auto storage = INvStorage::newStorage(config.storage);
35  auto http = std::make_shared<HttpFake>(temp_dir.Path());
36  KeyManager keys(storage, config.keymanagerConfig());
37 
38  Initializer initializer(config.provision, storage, http, keys, {});
39  EXPECT_FALSE(initializer.isSuccessful());
40 }
41 
42 /**
43  * \verify{\tst{187}} Verfiy that aktualizr halts when provided incomplete
44  * implicit provisioning credentials.
45  */
46 TEST(UptaneImplicit, ImplicitIncomplete) {
47  TemporaryDirectory temp_dir;
48  Config config;
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();
55 
56  auto http = std::make_shared<HttpFake>(temp_dir.Path());
57 
58  {
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());
63 
64  Initializer initializer(config.provision, storage, http, keys, {});
65  EXPECT_FALSE(initializer.isSuccessful());
66  }
67 
68  {
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());
74 
75  Initializer initializer(config.provision, storage, http, keys, {});
76  EXPECT_FALSE(initializer.isSuccessful());
77  }
78 
79  {
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());
85 
86  Initializer initializer(config.provision, storage, http, keys, {});
87  EXPECT_FALSE(initializer.isSuccessful());
88  }
89 
90  {
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());
97 
98  Initializer initializer(config.provision, storage, http, keys, {});
99  EXPECT_FALSE(initializer.isSuccessful());
100  }
101 
102  {
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());
109 
110  Initializer initializer(config.provision, storage, http, keys, {});
111  EXPECT_FALSE(initializer.isSuccessful());
112  }
113 
114  {
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());
121 
122  Initializer initializer(config.provision, storage, http, keys, {});
123  EXPECT_FALSE(initializer.isSuccessful());
124  }
125 }
126 
127 /**
128  * \verify{\tst{186}} Verify that aktualizr can implicitly provision with
129  * provided credentials.
130  */
131 TEST(UptaneImplicit, ImplicitProvision) {
132  Config config;
133  TemporaryDirectory temp_dir;
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");
141 
142  auto storage = INvStorage::newStorage(config.storage);
143  auto http = std::make_shared<HttpFake>(temp_dir.Path());
144  KeyManager keys(storage, config.keymanagerConfig());
145 
146  Initializer initializer(config.provision, storage, http, keys, {});
147  EXPECT_TRUE(initializer.isSuccessful());
148 }
149 
150 #ifndef __NO_MAIN__
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();
155 }
156 #endif
Configuration object for an aktualizr instance running on a primary ECU.
Definition: config.h:100
TEST(UptaneImplicit, ImplicitFailure)