This repository was archived by the owner on May 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove test repo meta from test/test_data/repo, generate data from test code using aktualizr-repo Signed-off-by: cheng.xiang <ext-cheng.xiang@here.com>
- Loading branch information
1 parent
3c26e78
commit ef2f7c6
Showing
38 changed files
with
206 additions
and
174 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
#ifndef METAFAKE_H_ | ||
#define METAFAKE_H_ | ||
|
||
#include <boost/filesystem.hpp> | ||
#include <fstream> | ||
#include <string> | ||
#include <vector> | ||
|
||
#include "logging/logging.h" | ||
#include "utilities/utils.h" | ||
#include "uptane_repo.h" | ||
|
||
enum BackupList { | ||
}; | ||
|
||
class MetaFake { | ||
public: | ||
MetaFake(const boost::filesystem::path &meta_dir_in) | ||
: meta_dir(meta_dir_in), repo(meta_dir_in, "2021-07-04T16:33:27Z", "id0") { | ||
// generate original repo data | ||
repo.generateRepo(KeyType::kRSA2048); | ||
backup(); | ||
create_image(); | ||
create_testData(); | ||
} | ||
|
||
private: | ||
void create_testData(void) { | ||
boost::filesystem::path file_name; | ||
Delegation delegation; | ||
|
||
// add image for "has update" meta | ||
file_name = "dummy_firmware.txt"; | ||
repo.addImage(meta_dir / file_name, file_name, delegation); | ||
|
||
file_name = "primary_firmware.txt"; | ||
repo.addImage(meta_dir / file_name, file_name, delegation); | ||
repo.addTarget(file_name.string(), "primary_hw", "CA:FE:A6:D2:84:9D"); | ||
|
||
file_name = "secondary_firmware.txt"; | ||
repo.addImage(meta_dir / file_name, file_name, delegation); | ||
repo.addTarget(file_name.string(), "secondary_hw", "secondary_ecu_serial"); | ||
|
||
repo.signTargets(); | ||
rename("_hasupdates"); | ||
|
||
// add image for "no update" meta | ||
restore(); | ||
|
||
file_name = "dummy_firmware.txt"; | ||
repo.addImage(meta_dir / file_name, file_name, delegation); | ||
|
||
repo.signTargets(); | ||
rename("_noupdates"); | ||
|
||
// add image for "multi secondary ecu" meta | ||
restore(); | ||
|
||
file_name = "dummy_firmware.txt"; | ||
repo.addImage(meta_dir / file_name, file_name, delegation); | ||
|
||
file_name = "secondary_firmware.txt"; | ||
repo.addImage(meta_dir / file_name, file_name, delegation); | ||
repo.addTarget(file_name.string(), "sec_hwid1", "sec_serial1"); | ||
|
||
file_name = "secondary_firmware2.txt"; | ||
repo.addImage(meta_dir / file_name, file_name, delegation); | ||
repo.addTarget(file_name.string(), "sec_hwid2", "sec_serial2"); | ||
|
||
repo.signTargets(); | ||
rename("_multisec"); | ||
delete_backup(); | ||
} | ||
|
||
void create_image(void) { | ||
std::string content = "Just to increment timestamp, ignore it\n"; | ||
Utils::writeFile(meta_dir / "dummy_firmware.txt", content); | ||
content = "This is a dummy firmware file (should never be downloaded)\n"; | ||
Utils::writeFile(meta_dir / "primary_firmware.txt", content); | ||
content = "This is content"; | ||
Utils::writeFile(meta_dir / "secondary_firmware.txt", content); | ||
content = "This is more content\n"; | ||
Utils::writeFile(meta_dir / "secondary_firmware2.txt", content); | ||
} | ||
|
||
void backup(void) { | ||
backup_files.push_back(meta_dir / "repo/director/targets.json"); | ||
backup_content.push_back(Utils::readFile(backup_files[0], false)); | ||
|
||
backup_files.push_back(meta_dir / "repo/image/snapshot.json"); | ||
backup_content.push_back(Utils::readFile(backup_files[1], false)); | ||
|
||
backup_files.push_back(meta_dir / "repo/image/targets.json"); | ||
backup_content.push_back(Utils::readFile(backup_files[2], false)); | ||
|
||
backup_files.push_back(meta_dir / "repo/image/timestamp.json"); | ||
backup_content.push_back(Utils::readFile(backup_files[3], false)); | ||
} | ||
|
||
void restore(void) { | ||
for (unsigned int i=0; i < backup_files.size(); i++) { | ||
Utils::writeFile(backup_files[i], backup_content[i]); | ||
} | ||
} | ||
|
||
void delete_backup(void) { | ||
for (unsigned int i=0; i < backup_files.size(); i++) { | ||
boost::filesystem::remove(backup_files[i]); | ||
} | ||
} | ||
|
||
void rename(const std::string &appendix) { | ||
for (unsigned int i=0; i < backup_files.size(); i++) { | ||
boost::filesystem::rename(backup_files[i], | ||
(backup_files[i].parent_path() / backup_files[i].stem()).string() + appendix + ".json"); | ||
} | ||
} | ||
|
||
private: | ||
boost::filesystem::path meta_dir; | ||
UptaneRepo repo; | ||
std::vector<boost::filesystem::path> backup_files; | ||
std::vector<std::string> backup_content; | ||
}; | ||
|
||
#endif // METAFAKE_H |
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 @@ | ||
../../../src/libaktualizr/campaign/test/campaigns_sample.json |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.