joewitt commented on code in PR #11955:
URL: https://github.com/apache/nifi/pull/11955#discussion_r4742930738
##########
nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/controller/StandardSearchContext.java:
##########
@@ -58,12 +60,41 @@ public String getAnnotationData() {
public PropertyValue getProperty(final PropertyDescriptor property) {
final String configuredValue =
processorNode.getRawPropertyValue(property);
final ResourceContext resourceContext = new
StandardResourceContext(new StandardResourceReferenceFactory(), property);
- return new StandardPropertyValue(resourceContext, configuredValue ==
null ? property.getDefaultValue() : configuredValue, controllerServiceLookup,
ParameterLookup.EMPTY);
+ final ParameterLookup parameterLookup = new
SensitivityMatchingParameterLookup(processorNode.getParameterLookup(),
property.isSensitive());
+ return new StandardPropertyValue(resourceContext, configuredValue ==
null ? property.getDefaultValue() : configuredValue, controllerServiceLookup,
parameterLookup);
}
@Override
public Map<PropertyDescriptor, String> getProperties() {
return processorNode.getRawPropertyValues();
}
+ /**
+ * Resolves only Parameters whose sensitivity matches the sensitivity of
the Property, consistent with Parameter resolution at runtime
+ */
Review Comment:
Updated the Javadoc with your wording in 806b7b18a8b. Thanks for confirming
the mixed-reference behavior is acceptable.
##########
nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/web/controller/TestStandardSearchContext.java:
##########
@@ -0,0 +1,132 @@
+/*
+ * 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.
+ */
+package org.apache.nifi.web.controller;
+
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.components.Validator;
+import org.apache.nifi.components.resource.ResourceCardinality;
+import org.apache.nifi.components.resource.ResourceType;
+import org.apache.nifi.controller.ControllerServiceLookup;
+import org.apache.nifi.controller.ProcessorNode;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.parameter.Parameter;
+import org.apache.nifi.parameter.ParameterLookup;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import java.util.Map;
+import java.util.Optional;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+class TestStandardSearchContext {
+
+ private static final String SCRIPTS_DIR_PARAMETER = "scripts.dir";
+
+ private static final String SECRET_PARAMETER = "secret";
+
+ private static final String SECRET_VALUE = "s3cr3t";
+
+ private static final PropertyDescriptor SCRIPT_FILE = new
PropertyDescriptor.Builder()
+ .name("Script File")
+ .required(false)
+ .addValidator(Validator.VALID)
+ .identifiesExternalResource(ResourceCardinality.SINGLE,
ResourceType.FILE)
+ .expressionLanguageSupported(ExpressionLanguageScope.ENVIRONMENT)
+ .build();
+
+ private static final PropertyDescriptor PASSWORD = new
PropertyDescriptor.Builder()
+ .name("Password")
+ .required(false)
+ .sensitive(true)
+ .addValidator(Validator.VALID)
+ .build();
+
+ @Mock
+ private ProcessorNode processorNode;
+
+ @Mock
+ private ControllerServiceLookup controllerServiceLookup;
+
+ private StandardSearchContext context;
+
+ @BeforeEach
+ void setContext() {
+ final Map<String, Parameter> parameters = Map.of(
+ SCRIPTS_DIR_PARAMETER, new
Parameter.Builder().name(SCRIPTS_DIR_PARAMETER).value("/opt/scripts").sensitive(false).build(),
+ SECRET_PARAMETER, new
Parameter.Builder().name(SECRET_PARAMETER).value(SECRET_VALUE).sensitive(true).build()
+ );
+ when(processorNode.getParameterLookup()).thenReturn(new
MapParameterLookup(parameters));
+
+ context = new StandardSearchContext("search-me", processorNode,
controllerServiceLookup);
+ }
+
+ @Test
+ void getPropertyEvaluatedResolvesParameter() {
+
when(processorNode.getRawPropertyValue(SCRIPT_FILE)).thenReturn("#{scripts.dir}/file.groovy");
+
+ assertEquals("/opt/scripts/file.groovy",
context.getProperty(SCRIPT_FILE).evaluateAttributeExpressions().getValue());
+ }
+
+ @Test
+ void getPropertyValueRemainsRaw() {
+
when(processorNode.getRawPropertyValue(SCRIPT_FILE)).thenReturn("#{scripts.dir}/file.groovy");
+
+ assertEquals("#{scripts.dir}/file.groovy",
context.getProperty(SCRIPT_FILE).getValue());
+ }
+
+ @Test
+ void
getPropertyEvaluatedExcludesSensitiveParameterForNonSensitiveProperty() {
+
when(processorNode.getRawPropertyValue(SCRIPT_FILE)).thenReturn("#{secret}");
+
+ final String evaluated =
context.getProperty(SCRIPT_FILE).evaluateAttributeExpressions().getValue();
+
+ assertFalse(evaluated != null && evaluated.contains(SECRET_VALUE));
+ }
+
+ @Test
+ void
getPropertyEvaluatedExcludesNonSensitiveParameterForSensitiveProperty() {
+
when(processorNode.getRawPropertyValue(PASSWORD)).thenReturn("#{scripts.dir}");
+
+ final String evaluated =
context.getProperty(PASSWORD).evaluateAttributeExpressions().getValue();
+
+ assertFalse(evaluated != null && evaluated.contains("/opt/scripts"));
+ }
Review Comment:
Done in 806b7b18a8b. The sensitivity mismatch tests now assert exact strings
(`""` for `#{secret}` on a non-sensitive property and for `#{scripts.dir}` on a
sensitive one). I added a mixed reference case (`#{scripts.dir}/#{secret}`
evaluates to `/opt/scripts/`) and a null `ParameterLookup` case
(`/file.groovy`).
--
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]