| 25 | #include "utils/EncryptionProvider.h" |
| 26 | |
| 27 | int main(int argc, char **argv) { |
| 28 | const cmd_args args = parse_cmdline_args(argc, argv, "update"); |
| 29 | TestController controller; |
| 30 | // copy config file to temporary location as it will get overridden |
| 31 | char tmp_format[] = "/var/tmp/c2.XXXXXX"; |
| 32 | std::string home_path = controller.createTempDirectory(tmp_format); |
| 33 | std::string live_config_file = utils::file::FileUtils::concat_path(home_path, "config.yml"); |
| 34 | utils::file::FileUtils::copy_file(args.test_file, live_config_file); |
| 35 | // the C2 server will update the flow with the contents of args.test_file |
| 36 | // which will be encrypted and persisted to the temporary live_config_file |
| 37 | C2UpdateHandler handler(args.test_file); |
| 38 | VerifyC2Update harness(10000); |
| 39 | harness.getConfiguration()->set(minifi::Configure::nifi_flow_configuration_encrypt, "true"); |
| 40 | harness.setKeyDir(args.key_dir); |
| 41 | harness.setUrl(args.url, &handler); |
| 42 | handler.setC2RestResponse(harness.getC2RestUrl(), "configuration", "true"); |
| 43 | |
| 44 | harness.run(live_config_file, args.key_dir); |
| 45 | |
| 46 | auto encryptor = utils::crypto::EncryptionProvider::create(args.key_dir); |
| 47 | assert(encryptor); |
| 48 | |
| 49 | std::ifstream encrypted_file{live_config_file, std::ios::binary}; |
| 50 | std::string decrypted_config = encryptor->decrypt(std::string(std::istreambuf_iterator<char>(encrypted_file), {})); |
| 51 | |
| 52 | std::ifstream original_file{args.test_file, std::ios::binary}; |
| 53 | std::string original_config{std::istreambuf_iterator<char>(original_file), {}}; |
| 54 | |
| 55 | assert(decrypted_config == original_config); |
| 56 | } |
nothing calls this directly
no test coverage detected