1 #include <gtest/gtest.h>
3 #include <boost/process.hpp>
5 #include "config/config.h"
6 #include "logging/logging.h"
7 #include "package_manager/ostreemanager.h"
8 #include "primary/aktualizr.h"
9 #include "storage/sqlstorage.h"
10 #include "test_utils.h"
11 #include "uptane_test_common.h"
13 static std::string server =
"http://127.0.0.1:";
14 static std::string treehub_server =
"http://127.0.0.1:";
15 static boost::filesystem::path sysroot;
22 Config conf = UptaneTestCommon::makeTestConfig(temp_dir, server);
23 conf.pacman.type = PACKAGE_MANAGER_OSTREE;
24 conf.pacman.sysroot = sysroot.string();
25 conf.pacman.ostree_server = treehub_server;
26 conf.pacman.os =
"dummy-os";
27 conf.provision.device_id =
"device_id";
28 conf.provision.ecu_registration_endpoint = server +
"/director/ecus";
29 conf.tls.server = server;
32 std::shared_ptr<INvStorage> storage = INvStorage::newStorage(conf.storage);
33 auto uptane_client = std_::make_unique<SotaUptaneClient>(conf, storage);
34 uptane_client->initialize();
35 EXPECT_FALSE(uptane_client->uptaneIteration(
nullptr,
nullptr));
36 EXPECT_STREQ(uptane_client->getLastException().what(),
37 "The target had a non-OSTree package that can not be installed on an OSTree system.");
42 int main(
int argc,
char **argv) {
43 ::testing::InitGoogleTest(&argc, argv);
48 std::cerr <<
"Error: " << argv[0] <<
" requires the path to the uptane-generator utility "
49 <<
"and an OSTree sysroot\n";
53 boost::filesystem::path uptane_generator_path;
54 uptane_generator_path = argv[1];
58 sysroot = temp_sysroot /
"sysroot";
61 int ret = system((std::string(
"cp -r ") + argv[2] + std::string(
" ") + sysroot.string()).c_str());
68 std::string new_rev = ostree.lastStdOut();
69 boost::trim_if(new_rev, boost::is_any_of(
" \t\r\n"));
71 std::string port = TestUtils::getFreePort();
73 boost::process::child http_server_process(
"tests/fake_http_server/fake_test_server.py", port,
"-m", meta_dir.Path());
74 TestUtils::waitForServer(server +
"/");
75 std::string treehub_port = TestUtils::getFreePort();
76 treehub_server += treehub_port;
78 boost::process::child ostree_server_process(
"tests/sota_tools/treehub_server.py", std::string(
"-p"), treehub_port,
79 std::string(
"-d"), treehub_dir.PathString(), std::string(
"-s0.5"),
80 std::string(
"--create"));
81 TestUtils::waitForServer(treehub_server +
"/");
83 Process uptane_gen(uptane_generator_path.string());
84 uptane_gen.run({
"generate",
"--path", meta_dir.PathString(),
"--correlationid",
"abc123"});
85 uptane_gen.run({
"image",
"--path", meta_dir.PathString(),
"--targetname",
"update_1.0",
"--targetsha256", new_rev,
86 "--targetlength",
"0",
"--targetformat",
"BINARY",
"--hwid",
"primary_hw"});
87 uptane_gen.run({
"addtarget",
"--path", meta_dir.PathString(),
"--targetname",
"update_1.0",
"--hwid",
"primary_hw",
88 "--serial",
"CA:FE:A6:D2:84:9D"});
89 uptane_gen.run({
"signtargets",
"--path", meta_dir.PathString(),
"--correlationid",
"abc123"});
91 return RUN_ALL_TESTS();