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();
40 int main(
int argc,
char **argv) {
41 ::testing::InitGoogleTest(&argc, argv);
46 std::cerr <<
"Error: " << argv[0] <<
" requires the path to the uptane-generator utility "
47 <<
"and an OSTree sysroot\n";
51 boost::filesystem::path uptane_generator_path;
52 uptane_generator_path = argv[1];
56 sysroot = temp_sysroot /
"sysroot";
59 int ret = system((std::string(
"cp -r ") + argv[2] + std::string(
" ") + sysroot.string()).c_str());
66 std::string new_rev = ostree.lastStdOut();
67 boost::trim_if(new_rev, boost::is_any_of(
" \t\r\n"));
69 std::string port = TestUtils::getFreePort();
71 boost::process::child http_server_process(
"tests/fake_http_server/fake_test_server.py", port,
"-m", meta_dir.Path());
72 TestUtils::waitForServer(server +
"/");
73 std::string treehub_port = TestUtils::getFreePort();
74 treehub_server += treehub_port;
76 boost::process::child ostree_server_process(
"tests/sota_tools/treehub_server.py", std::string(
"-p"), treehub_port,
77 std::string(
"-d"), treehub_dir.PathString(), std::string(
"-s0.5"),
78 std::string(
"--create"));
79 TestUtils::waitForServer(treehub_server +
"/");
81 Process uptane_gen(uptane_generator_path.string());
82 uptane_gen.run({
"generate",
"--path", meta_dir.PathString(),
"--correlationid",
"abc123"});
83 uptane_gen.run({
"image",
"--path", meta_dir.PathString(),
"--targetname",
"update_1.0",
"--targetsha256", new_rev,
84 "--targetlength",
"0",
"--targetformat",
"BINARY",
"--hwid",
"primary_hw"});
85 uptane_gen.run({
"addtarget",
"--path", meta_dir.PathString(),
"--targetname",
"update_1.0",
"--hwid",
"primary_hw",
86 "--serial",
"CA:FE:A6:D2:84:9D"});
87 uptane_gen.run({
"signtargets",
"--path", meta_dir.PathString(),
"--correlationid",
"abc123"});
89 return RUN_ALL_TESTS();