fgerlits commented on code in PR #1895:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1895#discussion_r1916890303
##########
libminifi/test/unit/JsonFlowSerializerTests.cpp:
##########
@@ -731,19 +732,173 @@ TEST_CASE("The encrypted flow configuration cannot be
decrypted with an incorrec
core::flow::AdaptiveConfiguration
json_configuration_before{configuration_context};
const auto schema = core::flow::FlowSchema::getNiFiFlowJson();
- const auto config_json_with_nifi_schema =
utils::string::join_pack(config_json_with_nifi_schema_part_1,
config_json_with_nifi_schema_part_2);
+ const auto config_json_with_nifi_schema =
minifi::utils::string::join_pack(config_json_with_nifi_schema_part_1,
config_json_with_nifi_schema_part_2);
const auto process_group_before =
json_configuration_before.getRootFromPayload(config_json_with_nifi_schema);
REQUIRE(process_group_before);
rapidjson::Document doc;
rapidjson::ParseResult res = doc.Parse(config_json_with_nifi_schema.data(),
config_json_with_nifi_schema.size());
REQUIRE(res);
const auto flow_serializer = core::json::JsonFlowSerializer{std::move(doc)};
- std::string config_json_encrypted =
flow_serializer.serialize(*process_group_before, schema, encryption_provider,
{});
+ std::string config_json_encrypted =
flow_serializer.serialize(*process_group_before, schema, encryption_provider,
{}, {});
- const utils::crypto::Bytes different_secret_key =
utils::string::from_hex("ea55b7d0edc22280c9547e4d89712b3fae74f96d82f240a004fb9fbd0640eec7");
- configuration_context.sensitive_values_encryptor =
utils::crypto::EncryptionProvider{different_secret_key};
+ const minifi::utils::crypto::Bytes different_secret_key =
minifi::utils::string::from_hex("ea55b7d0edc22280c9547e4d89712b3fae74f96d82f240a004fb9fbd0640eec7");
+ configuration_context.sensitive_values_encryptor =
minifi::utils::crypto::EncryptionProvider{different_secret_key};
core::flow::AdaptiveConfiguration
json_configuration_after{configuration_context};
-
REQUIRE_THROWS_AS(json_configuration_after.getRootFromPayload(config_json_encrypted),
utils::crypto::EncryptionError);
+
REQUIRE_THROWS_AS(json_configuration_after.getRootFromPayload(config_json_encrypted),
minifi::utils::crypto::EncryptionError);
}
+
+TEST_CASE("Parameter provider generated parameter context is serialized
correctly") {
Review Comment:
OK, some code duplication is acceptable in unit tests if it makes the logic
clearer.
##########
libminifi/src/utils/StringUtils.cpp:
##########
@@ -602,4 +602,12 @@ std::string repeat(std::string_view str, size_t count) {
return result;
}
+std::optional<std::string> partAfterLastOccurrenceOf(std::string_view input,
char delimiter) {
+ const size_t last_pos = input.find_last_of(delimiter);
+ if (last_pos == std::string::npos) {
+ return std::nullopt;
+ }
+ return std::string{input.substr(last_pos + 1)};
+}
Review Comment:
This works, but as far as I can see, in all cases where this is used, we use
the full input if the return value is `nullopt`. So the code could be made
simpler if the helper function returned the full input in these cases:
```suggestion
std::string partAfterLastOccurrenceOf(std::string_view input, char
delimiter) {
const size_t last_pos = input.find_last_of(delimiter);
if (last_pos == std::string::npos) {
return {input};
}
return {input.substr(last_pos + 1)};
}
```
(this will do one extra allocation in some cases, but I don't think we need
to worry about that)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]