1 #include <gtest/gtest.h> 5 #include <boost/filesystem.hpp> 9 #include "libaktualizr/config.h" 11 #include "primary/aktualizr.h" 12 #include "uptane_test_common.h" 14 boost::filesystem::path uptane_generator_path;
16 void delegation_basic(
const boost::filesystem::path& delegation_path,
bool revoke) {
18 std::string cmd =
"tests/uptane_repo_generation/delegation_basic.sh " + uptane_generator_path.string() +
" " +
19 delegation_path.string();
23 int retval = Utils::shell(cmd, &output,
true);
24 EXPECT_EQ(retval, EXIT_SUCCESS) << output;
27 void delegation_nested(
const boost::filesystem::path& delegation_path,
bool revoke) {
29 std::string cmd =
"tests/uptane_repo_generation/delegation_nested.sh " + uptane_generator_path.string() +
" " +
30 delegation_path.string();
34 int retval = Utils::shell(cmd, &output,
true);
35 EXPECT_EQ(retval, EXIT_SUCCESS) << output;
41 :
HttpFake(test_dir_in,
"", test_dir_in /
"delegation_test/repo") {}
43 HttpResponse handle_event(
const std::string& url,
const Json::Value&
data)
override {
45 for (
const Json::Value&
event : data) {
47 EXPECT_EQ(
event[
"event"][
"correlationId"].asString(),
"");
52 unsigned int events_seen{0};
59 for (
auto generate_fun : {delegation_basic, delegation_nested}) {
61 auto delegation_path = temp_dir.Path() /
"delegation_test";
62 generate_fun(delegation_path,
false);
63 auto http = std::make_shared<HttpFakeDelegation>(temp_dir.Path());
68 Config conf = UptaneTestCommon::makeTestConfig(temp_dir, http->tls_server);
70 auto storage = INvStorage::newStorage(conf.storage);
75 EXPECT_EQ(update_result.status, result::UpdateStatus::kUpdatesAvailable);
78 EXPECT_EQ(download_result.status, result::DownloadStatus::kSuccess);
81 for (
const auto& r : install_result.ecu_reports) {
82 EXPECT_EQ(r.install_res.result_code.num_code, data::ResultCode::Numeric::kOk);
86 EXPECT_EQ(http->events_seen, 8);
91 for (
auto generate_fun : {delegation_basic, delegation_nested}) {
93 auto http = std::make_shared<HttpFakeDelegation>(temp_dir.Path());
94 Config conf = UptaneTestCommon::makeTestConfig(temp_dir, http->tls_server);
95 auto storage = INvStorage::newStorage(conf.storage);
97 auto delegation_path = temp_dir.Path() /
"delegation_test";
99 generate_fun(delegation_path,
false);
104 EXPECT_EQ(update_result.status, result::UpdateStatus::kUpdatesAvailable);
105 EXPECT_EQ(update_result.updates.size(), 2);
109 generate_fun(delegation_path,
true);
114 EXPECT_EQ(update_result.status, result::UpdateStatus::kUpdatesAvailable);
115 EXPECT_EQ(update_result.updates.size(), 1);
118 EXPECT_EQ(download_result.status, result::DownloadStatus::kSuccess);
121 for (
const auto& r : install_result.ecu_reports) {
122 EXPECT_EQ(r.install_res.result_code.num_code, data::ResultCode::Numeric::kOk);
129 for (
auto generate_fun : {delegation_basic, delegation_nested}) {
131 auto http = std::make_shared<HttpFakeDelegation>(temp_dir.Path());
132 Config conf = UptaneTestCommon::makeTestConfig(temp_dir, http->tls_server);
133 auto storage = INvStorage::newStorage(conf.storage);
135 auto delegation_path = temp_dir.Path() /
"delegation_test";
137 generate_fun(delegation_path,
false);
142 EXPECT_EQ(update_result.status, result::UpdateStatus::kUpdatesAvailable);
145 EXPECT_EQ(download_result.status, result::DownloadStatus::kSuccess);
149 generate_fun(delegation_path,
true);
154 EXPECT_EQ(update_result.status, result::UpdateStatus::kUpdatesAvailable);
155 EXPECT_EQ(update_result.updates.size(), 1);
158 EXPECT_EQ(download_result.status, result::DownloadStatus::kSuccess);
161 for (
const auto& r : install_result.ecu_reports) {
162 EXPECT_EQ(r.install_res.result_code.num_code, data::ResultCode::Numeric::kOk);
169 for (
auto generate_fun : {delegation_basic, delegation_nested}) {
171 auto http = std::make_shared<HttpFakeDelegation>(temp_dir.Path());
172 Config conf = UptaneTestCommon::makeTestConfig(temp_dir, http->tls_server);
173 auto storage = INvStorage::newStorage(conf.storage);
175 auto delegation_path = temp_dir.Path() /
"delegation_test";
177 generate_fun(delegation_path,
false);
182 EXPECT_EQ(update_result.status, result::UpdateStatus::kUpdatesAvailable);
185 EXPECT_EQ(download_result.status, result::DownloadStatus::kSuccess);
188 for (
const auto& r : install_result.ecu_reports) {
189 EXPECT_EQ(r.install_res.result_code.num_code, data::ResultCode::Numeric::kOk);
194 generate_fun(delegation_path,
true);
199 EXPECT_EQ(update_result.status, result::UpdateStatus::kNoUpdatesAvailable);
207 auto delegation_path = temp_dir.Path() /
"delegation_test";
208 delegation_nested(delegation_path,
false);
209 auto http = std::make_shared<HttpFakeDelegation>(temp_dir.Path());
211 Config conf = UptaneTestCommon::makeTestConfig(temp_dir, http->tls_server);
213 auto storage = INvStorage::newStorage(conf.storage);
218 EXPECT_EQ(update_result.status, result::UpdateStatus::kUpdatesAvailable);
220 std::vector<std::string> expected_target_names = {
"primary.txt",
"abracadabra",
"abc/secondary.txt",
"abc/target0",
221 "abc/target1",
"abc/target2",
"bcd/target0",
"cde/target0",
222 "cde/target1",
"def/target0"};
223 for (
auto& target : aktualizr.uptane_client()->allTargets()) {
224 EXPECT_EQ(target.filename(), expected_target_names[0]);
225 expected_target_names.erase(expected_target_names.begin());
228 EXPECT_TRUE(expected_target_names.empty());
232 int main(
int argc,
char** argv) {
233 ::testing::InitGoogleTest(&argc, argv);
235 std::cerr <<
"Error: " << argv[0] <<
" requires the path to the uptane-generator utility\n";
238 uptane_generator_path = argv[1];
241 logger_set_threshold(boost::log::trivial::trace);
243 return RUN_ALL_TESTS();
Container for information about downloading an update.
Configuration object for an aktualizr instance running on a Primary ECU.
std::future< result::Download > Download(const std::vector< Uptane::Target > &updates)
Download targets.
std::future< result::UpdateCheck > CheckUpdates()
Fetch Uptane metadata and check for updates.
std::future< result::Install > Install(const std::vector< Uptane::Target > &updates)
Install targets.
Container for information about installing an update.
Container for information about available updates.
void Initialize()
Initialize aktualizr.