MCPcopy Create free account
hub / github.com/apache/nifi-minifi-cpp / main

Function main

extensions/http-curl/tests/C2ConfigEncryption.cpp:27–56  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25#include "utils/EncryptionProvider.h"
26
27int 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}

Callers

nothing calls this directly

Calls 12

parse_cmdline_argsFunction · 0.85
copy_fileFunction · 0.85
createTempDirectoryMethod · 0.80
setKeyDirMethod · 0.80
setC2RestResponseMethod · 0.80
getC2RestUrlMethod · 0.80
concat_pathFunction · 0.50
setMethod · 0.45
getConfigurationMethod · 0.45
setUrlMethod · 0.45
runMethod · 0.45
decryptMethod · 0.45

Tested by

no test coverage detected