This repository has been archived by the owner on May 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Zee314159 <252806294@qq.com>
- Loading branch information
Showing
5 changed files
with
142 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
#include <gtest/gtest.h> | ||
|
||
#include <boost/process.hpp> | ||
|
||
#include "uptane_test_common.h" | ||
|
||
#include "config/config.h" | ||
#include "logging/logging.h" | ||
#include "package_manager/ostreemanager.h" | ||
#include "primary/aktualizr.h" | ||
#include "storage/sqlstorage.h" | ||
#include "test_utils.h" | ||
|
||
static std::string server = "http://127.0.0.1:"; | ||
static std::string treehub_server = "http://127.0.0.1:"; | ||
static boost::filesystem::path sysroot; | ||
|
||
static std::string new_rev; | ||
|
||
/* | ||
* Reject non-OSTree binaries. | ||
*/ | ||
TEST(Aktualizr, DownloadNonOstreeBin) { | ||
TemporaryDirectory temp_dir; | ||
Config conf = UptaneTestCommon::makeTestConfig(temp_dir, server); | ||
conf.pacman.type = PackageManager::kOstree; | ||
conf.pacman.sysroot = sysroot.string(); | ||
conf.pacman.ostree_server = treehub_server; | ||
conf.pacman.os = "dummy-os"; | ||
conf.provision.device_id = "device_id"; | ||
conf.provision.ecu_registration_endpoint = server + "/director/ecus"; | ||
conf.tls.server = server; | ||
|
||
{ | ||
std::shared_ptr<INvStorage> storage = INvStorage::newStorage(conf.storage); | ||
OstreeManager ostree(conf.pacman, storage, nullptr, nullptr); | ||
|
||
Aktualizr aktualizr(conf); | ||
|
||
aktualizr.Initialize(); | ||
|
||
result::UpdateCheck update_result = aktualizr.CheckUpdates().get(); | ||
ASSERT_EQ(update_result.status, result::UpdateStatus::kError); | ||
} | ||
} | ||
|
||
#ifndef __NO_MAIN__ | ||
int main(int argc, char **argv) { | ||
::testing::InitGoogleTest(&argc, argv); | ||
|
||
logger_init(); | ||
|
||
if (argc != 3) { | ||
std::cerr << "Error: " << argv[0] << " requires the path to the uptane-generator utility " | ||
<< "and an OStree sysroot\n"; | ||
return EXIT_FAILURE; | ||
} | ||
|
||
boost::filesystem::path uptane_generator_path; | ||
uptane_generator_path = argv[1]; | ||
|
||
Process ostree("ostree"); | ||
|
||
TemporaryDirectory meta_dir; | ||
TemporaryDirectory temp_sysroot; | ||
sysroot = temp_sysroot / "sysroot"; | ||
// uses cp, as boost doesn't like to copy bad symlinks | ||
int ret = system((std::string("cp -r ") + argv[2] + std::string(" ") + sysroot.string()).c_str()); | ||
if (ret != 0) { | ||
return -1; | ||
} | ||
auto r = ostree.run( | ||
{"rev-parse", std::string("--repo"), (sysroot / "/ostree/repo").string(), "generate-remote/generated"}); | ||
if (std::get<0>(r) != 0) { | ||
return -1; | ||
} | ||
|
||
std::string port = TestUtils::getFreePort(); | ||
server += port; | ||
boost::process::child http_server_process("tests/fake_http_server/fake_test_server.py", port, "-m", meta_dir.Path()); | ||
TestUtils::waitForServer(server + "/"); | ||
|
||
std::string treehub_port = TestUtils::getFreePort(); | ||
treehub_server += treehub_port; | ||
TemporaryDirectory treehub_dir; | ||
boost::process::child ostree_server_process("tests/sota_tools/treehub_server.py", std::string("-p"), treehub_port, | ||
std::string("-d"), treehub_dir.PathString(), std::string("-s0.5"), | ||
std::string("--create")); | ||
TestUtils::waitForServer(treehub_server + "/"); | ||
r = ostree.run({"rev-parse", std::string("--repo"), treehub_dir.PathString(), "master"}); | ||
if (std::get<0>(r) != 0) { | ||
return -1; | ||
} | ||
new_rev = ostree.lastStdOut(); | ||
boost::trim_if(new_rev, boost::is_any_of(" \t\r\n")); | ||
LOG_INFO << "DEST: " << new_rev; | ||
|
||
Process uptane_gen(uptane_generator_path.string()); | ||
uptane_gen.run({"generate", "--path", meta_dir.PathString(), "--correlationid", "abc123"}); | ||
uptane_gen.run({"image", "--path", meta_dir.PathString(), "--targetname", "update_1.0", "--targetsha256", new_rev, | ||
"--targetlength", "0", "--targetformat", "BINARY", "--hwid", "primary_hw"}); | ||
uptane_gen.run({"addtarget", "--path", meta_dir.PathString(), "--targetname", "update_1.0", "--hwid", "primary_hw", | ||
"--serial", "CA:FE:A6:D2:84:9D"}); | ||
uptane_gen.run({"signtargets", "--path", meta_dir.PathString(), "--correlationid", "abc123"}); | ||
LOG_INFO << uptane_gen.lastStdOut(); | ||
// Work around inconsistent directory naming. | ||
Utils::copyDir(meta_dir.Path() / "repo/image", meta_dir.Path() / "repo/repo"); | ||
|
||
return RUN_ALL_TESTS(); | ||
} | ||
#endif // __NO_MAIN__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters