1 #include <gtest/gtest.h> 7 #include "libaktualizr/config.h" 8 #include "primary/aktualizr.h" 9 #include "uptane_test_common.h" 10 #include "virtualsecondary.h" 12 boost::filesystem::path fake_meta_dir;
16 HttpFakeRegistration(
const boost::filesystem::path& test_dir_in,
const boost::filesystem::path& meta_dir_in)
17 :
HttpFake(test_dir_in,
"noupdates", meta_dir_in) {}
19 HttpResponse post(
const std::string& url,
const Json::Value&
data)
override {
20 if (url.find(
"/director/ecus") != std::string::npos) {
21 registration_count += 1;
22 EXPECT_EQ(data[
"primary_ecu_serial"].asString(),
"CA:FE:A6:D2:84:9D");
23 EXPECT_EQ(data[
"ecus"][0][
"ecu_serial"].asString(),
"CA:FE:A6:D2:84:9D");
24 EXPECT_EQ(data[
"ecus"][0][
"hardware_identifier"].asString(),
"primary_hw");
26 return HttpFake::post(url, data);
29 unsigned int registration_count{0};
37 auto http = std::make_shared<HttpFakeRegistration>(temp_dir.Path(), fake_meta_dir);
38 Config conf = UptaneTestCommon::makeTestConfig(temp_dir, http->tls_server);
39 auto storage = INvStorage::newStorage(conf.storage);
43 aktualizr.
AddSecondary(std::make_shared<Primary::VirtualSecondary>(ecu_config));
46 std::vector<std::string> expected_ecus = {
"CA:FE:A6:D2:84:9D",
"ecuserial3",
"secondary_ecu_serial"};
47 UptaneTestCommon::verifyEcus(temp_dir, expected_ecus);
48 EXPECT_EQ(http->registration_count, 1);
50 ecu_config.ecu_serial =
"ecuserial4";
51 aktualizr.
AddSecondary(std::make_shared<Primary::VirtualSecondary>(ecu_config));
53 expected_ecus.push_back(ecu_config.ecu_serial);
54 UptaneTestCommon::verifyEcus(temp_dir, expected_ecus);
55 EXPECT_EQ(http->registration_count, 2);
63 auto http = std::make_shared<HttpFakeRegistration>(temp_dir.Path(), fake_meta_dir);
64 Config conf = UptaneTestCommon::makeTestConfig(temp_dir, http->tls_server);
65 auto storage = INvStorage::newStorage(conf.storage);
70 aktualizr.
AddSecondary(std::make_shared<Primary::VirtualSecondary>(ecu_config));
73 std::vector<std::string> expected_ecus = {
"CA:FE:A6:D2:84:9D",
"ecuserial3",
"secondary_ecu_serial"};
74 UptaneTestCommon::verifyEcus(temp_dir, expected_ecus);
75 EXPECT_EQ(http->registration_count, 1);
82 std::vector<std::string> expected_ecus = {
"CA:FE:A6:D2:84:9D",
"secondary_ecu_serial"};
83 UptaneTestCommon::verifyEcus(temp_dir, expected_ecus);
84 EXPECT_EQ(http->registration_count, 2);
93 auto http = std::make_shared<HttpFakeRegistration>(temp_dir.Path(), fake_meta_dir);
94 Config conf = UptaneTestCommon::makeTestConfig(temp_dir, http->tls_server);
95 auto storage = INvStorage::newStorage(conf.storage);
100 aktualizr.
AddSecondary(std::make_shared<Primary::VirtualSecondary>(ecu_config));
103 std::vector<std::string> expected_ecus = {
"CA:FE:A6:D2:84:9D",
"ecuserial3",
"secondary_ecu_serial"};
104 UptaneTestCommon::verifyEcus(temp_dir, expected_ecus);
105 EXPECT_EQ(http->registration_count, 1);
111 ecu_config.ecu_serial =
"ecuserial4";
112 aktualizr.
AddSecondary(std::make_shared<Primary::VirtualSecondary>(ecu_config));
115 std::vector<std::string> expected_ecus = {
"CA:FE:A6:D2:84:9D",
"ecuserial4",
"secondary_ecu_serial"};
116 UptaneTestCommon::verifyEcus(temp_dir, expected_ecus);
117 EXPECT_EQ(http->registration_count, 2);
122 int main(
int argc,
char** argv) {
123 ::testing::InitGoogleTest(&argc, argv);
126 logger_set_threshold(boost::log::trivial::trace);
129 fake_meta_dir = tmp_dir.Path();
132 return RUN_ALL_TESTS();
void AddSecondary(const std::shared_ptr< SecondaryInterface > &secondary)
Add new Secondary to aktualizr.
Configuration object for an aktualizr instance running on a Primary ECU.
This class provides the main APIs necessary for launching and controlling libaktualizr.
void Initialize()
Initialize aktualizr.