8 #include <boost/filesystem.hpp>
10 #include "logging/logging.h"
11 #include "uptane_repo.h"
12 #include "utilities/utils.h"
16 MetaFake(
const boost::filesystem::path &meta_dir_in)
17 : meta_dir(meta_dir_in), work_dir(meta_dir /
"fake_meta"), repo(work_dir,
"2021-07-04T16:33:27Z",
"id0") {
18 repo.generateRepo(KeyType::kED25519);
25 void create_testData(
void) {
26 boost::filesystem::path file_name;
31 file_name =
"dummy_firmware.txt";
32 repo.addImage(work_dir / file_name, file_name,
"dummy",
"", delegation);
34 file_name =
"primary_firmware.txt";
36 repo.addImage(work_dir / file_name, file_name, hwid,
"", delegation);
37 repo.addTarget(file_name.string(), hwid,
"CA:FE:A6:D2:84:9D",
"");
39 file_name =
"secondary_firmware.txt";
40 hwid =
"secondary_hw";
41 repo.addImage(work_dir / file_name, file_name, hwid,
"", delegation);
42 repo.addTarget(file_name.string(), hwid,
"secondary_ecu_serial",
"");
45 rename(
"_hasupdates");
50 file_name =
"dummy_firmware.txt";
51 repo.addImage(work_dir / file_name, file_name,
"dummy",
"", delegation);
59 file_name =
"dummy_firmware.txt";
60 repo.addImage(work_dir / file_name, file_name,
"dummy",
"", delegation);
62 file_name =
"secondary_firmware.txt";
64 repo.addImage(work_dir / file_name, file_name, hwid,
"", delegation);
65 repo.addTarget(file_name.string(), hwid,
"sec_serial1",
"");
67 file_name =
"secondary_firmware2.txt";
69 repo.addImage(work_dir / file_name, file_name, hwid,
"", delegation);
70 repo.addTarget(file_name.string(), hwid,
"sec_serial2",
"");
76 Utils::copyDir(work_dir / ImageRepo::dir, meta_dir /
"repo");
77 Utils::copyDir(work_dir / DirectorRepo::dir, meta_dir /
"director");
78 if (!boost::filesystem::exists(meta_dir /
"campaigner") &&
79 boost::filesystem::is_directory(
"tests/test_data/campaigner")) {
80 Utils::copyDir(
"tests/test_data/campaigner", meta_dir /
"campaigner");
84 void create_image(
void) {
85 std::string content =
"Just to increment timestamp, ignore it\n";
86 Utils::writeFile(work_dir /
"dummy_firmware.txt", content);
87 content =
"This is a dummy firmware file (should never be downloaded)\n";
88 Utils::writeFile(work_dir /
"primary_firmware.txt", content);
89 content =
"This is content";
90 Utils::writeFile(work_dir /
"secondary_firmware.txt", content);
91 content =
"This is more content\n";
92 Utils::writeFile(work_dir /
"secondary_firmware2.txt", content);
96 backup_files.push_back(work_dir / DirectorRepo::dir /
"targets.json");
97 backup_content.push_back(Utils::readFile(backup_files[0],
false));
99 backup_files.push_back(work_dir / ImageRepo::dir /
"snapshot.json");
100 backup_content.push_back(Utils::readFile(backup_files[1],
false));
102 backup_files.push_back(work_dir / ImageRepo::dir /
"targets.json");
103 backup_content.push_back(Utils::readFile(backup_files[2],
false));
105 backup_files.push_back(work_dir / ImageRepo::dir /
"timestamp.json");
106 backup_content.push_back(Utils::readFile(backup_files[3],
false));
110 for (
unsigned int i = 0; i < backup_files.size(); i++) {
111 Utils::writeFile(backup_files[i], backup_content[i]);
115 void rename(
const std::string &appendix) {
116 for (
unsigned int i = 0; i < backup_files.size(); i++) {
117 boost::filesystem::rename(backup_files[i],
118 (backup_files[i].parent_path() / backup_files[i].stem()).
string() + appendix +
".json");
123 boost::filesystem::path meta_dir;
124 boost::filesystem::path work_dir;
126 std::vector<boost::filesystem::path> backup_files;
127 std::vector<std::string> backup_content;