szaszm commented on code in PR #2063: URL: https://github.com/apache/nifi-minifi-cpp/pull/2063#discussion_r2536029204
########## libminifi/test/unit/VariableRegistryTests.cpp: ########## @@ -0,0 +1,73 @@ +/** + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "properties/Configure.h" +#include "core/VariableRegistry.h" +#include "unit/Catch.h" + +TEST_CASE("VariableRegistry default test") { + namespace minifi = org::apache::nifi::minifi; + const std::shared_ptr<minifi::Configure> configuration = std::make_shared<minifi::ConfigureImpl>(); + configuration->set("foo", "foo_val"); + configuration->set("bar", "bar_val"); + configuration->set("foo_password", "secret password"); + const auto variable_registry = minifi::core::VariableRegistryImpl(configuration); + CHECK(variable_registry.getConfigurationProperty("foo") == "foo_val"); + CHECK(variable_registry.getConfigurationProperty("bar") == "bar_val"); + CHECK_FALSE(variable_registry.getConfigurationProperty("foo_password")); // passwords are blacklisted +} + +TEST_CASE("VariableRegistry whitelist test") { Review Comment: I'd add an empty whitelist test ########## core-framework/include/core/VariableRegistry.h: ########## @@ -40,53 +44,37 @@ class VariableRegistryImpl : public virtual VariableRegistry { ~VariableRegistryImpl() override = default; - bool getConfigurationProperty(const std::string &property, std::string &value) const override { - auto prop = variable_registry_.find(property); - if (prop != variable_registry_.end()) { - value = prop->second; - return true; + [[nodiscard]] std::optional<std::string> getConfigurationProperty(const std::string_view key) const override { + const auto it = variable_registry_.find(key); + if (it == variable_registry_.end()) { + return std::nullopt; } - return false; + return it->second; } protected: void loadVariableRegistry() { - std::string registry_values; - - auto options = configuration_->getConfiguredKeys(); - std::string white_list_opt = "minifi.variable.registry.whitelist", white_list; - std::string black_list_opt = "minifi.variable.registry.blacklist", black_list; + gsl_Assert(configuration_); + auto options = configuration_->get(Configuration::minifi_variable_registry_whitelist) + .transform([](std::string&& list) { return utils::string::split(std::move(list), ","); }) + .value_or(configuration_->getConfiguredKeys()); Review Comment: does this work correctly if the whitelist is empty? that would be a valid optional, so it wouldn't fall back to the default in value_or. -- 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]
