briansolo1985 commented on code in PR #8028:
URL: https://github.com/apache/nifi/pull/8028#discussion_r1396853662


##########
minifi/minifi-nar-bundles/minifi-framework-bundle/minifi-framework/minifi-framework-core/src/test/java/org/apache/nifi/minifi/c2/command/FlowPropertyEncryptorTest.java:
##########
@@ -0,0 +1,338 @@
+/*
+ * 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.minifi.c2.command;
+
+import static java.util.Map.entry;
+import static java.util.UUID.randomUUID;
+import static java.util.stream.Collectors.toMap;
+import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic;
+import static 
org.apache.nifi.controller.serialization.FlowSerializer.ENC_PREFIX;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.stream.Stream;
+import org.apache.nifi.c2.protocol.component.api.Bundle;
+import org.apache.nifi.c2.protocol.component.api.ComponentManifest;
+import org.apache.nifi.c2.protocol.component.api.ControllerServiceDefinition;
+import org.apache.nifi.c2.protocol.component.api.ProcessorDefinition;
+import org.apache.nifi.c2.protocol.component.api.PropertyDescriptor;
+import org.apache.nifi.c2.protocol.component.api.RuntimeManifest;
+import org.apache.nifi.controller.flow.VersionedDataflow;
+import org.apache.nifi.encrypt.PropertyEncryptor;
+import org.apache.nifi.flow.VersionedConfigurableExtension;
+import org.apache.nifi.flow.VersionedControllerService;
+import org.apache.nifi.flow.VersionedParameter;
+import org.apache.nifi.flow.VersionedParameterContext;
+import org.apache.nifi.flow.VersionedProcessGroup;
+import org.apache.nifi.flow.VersionedProcessor;
+import org.apache.nifi.flow.VersionedPropertyDescriptor;
+import org.apache.nifi.minifi.commons.service.FlowSerDeService;
+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;
+
+@ExtendWith(MockitoExtension.class)
+public class FlowPropertyEncryptorTest {
+
+    private static final String PROCESSOR_TYPE_1 = "processor_type_1";
+    private static final String PROCESSOR_TYPE_2 = "processor_type_2";
+    private static final String PROCESSOR_TYPE_3 = "processor_type_3";
+    private static final String CONTROLLER_SERVICE_TYPE_1 = 
"controller_service_type_1";
+    private static final String CONTROLLER_SERVICE_TYPE_2 = 
"controller_service_type_2";
+    private static final String CONTROLLER_SERVICE_TYPE_3 = 
"controller_service_type_3";
+
+    private static final String SENSITIVE_PROPERTY_NAME_PREFIX = "sensitive";
+
+    private static final String NON_SENSITIVE_1 = "non-sensitive-1";
+    private static final String SENSITIVE_1 = SENSITIVE_PROPERTY_NAME_PREFIX + 
"-1";
+    private static final String NON_SENSITIVE_2 = "non-sensitive-2";
+    private static final String SENSITIVE_3 = SENSITIVE_PROPERTY_NAME_PREFIX + 
"-3";
+
+    private static final Map<String, String> PARAMETERS1 = Map.of(
+        NON_SENSITIVE_1, NON_SENSITIVE_1,
+        SENSITIVE_1, SENSITIVE_1
+    );
+    private static final Map<String, String> PARAMETERS2 = Map.of(
+        NON_SENSITIVE_2, NON_SENSITIVE_2
+    );
+
+    private static final Map<String, String> PARAMETERS3 = Map.of(
+        SENSITIVE_3, SENSITIVE_3
+    );
+    private static final Map<String, VersionedPropertyDescriptor> DESCRIPTORS1 
= Map.of(
+        NON_SENSITIVE_1, versionedPropertyDescriptor(NON_SENSITIVE_1, false),
+        SENSITIVE_1, versionedPropertyDescriptor(SENSITIVE_1, true)
+    );
+    private static final Map<String, VersionedPropertyDescriptor> DESCRIPTORS2 
= Map.of(
+        NON_SENSITIVE_2, versionedPropertyDescriptor(NON_SENSITIVE_2, false)
+    );
+    private static final Map<String, VersionedPropertyDescriptor> DESCRIPTORS3 
= Map.of(
+        SENSITIVE_3, versionedPropertyDescriptor(SENSITIVE_3, true)
+    );
+
+
+    @Mock
+    private PropertyEncryptor mockPropertyEncryptor;
+    @Mock
+    private RuntimeManifest mockRunTimeManifest;
+
+    private FlowSerDeService flowSerDeService;
+    private FlowPropertyEncryptor testEncryptor;
+
+    private static VersionedPropertyDescriptor 
versionedPropertyDescriptor(String name, boolean isSensitive) {
+        VersionedPropertyDescriptor versionedPropertyDescriptor = new 
VersionedPropertyDescriptor();
+        versionedPropertyDescriptor.setName(name);
+        versionedPropertyDescriptor.setSensitive(isSensitive);
+        return versionedPropertyDescriptor;
+    }
+
+    @BeforeEach
+    public void setup() {
+        
when(mockPropertyEncryptor.encrypt(anyString())).thenReturn(randomAlphabetic(5));
+        flowSerDeService = FlowSerDeService.defaultInstance();
+        testEncryptor = new FlowPropertyEncryptor(mockPropertyEncryptor, 
flowSerDeService, mockRunTimeManifest);
+    }
+
+    @Test
+    public void shouldEncryptParameterContextsSensitiveVariables() {
+        // given

Review Comment:
   Removed the comments



##########
minifi/minifi-nar-bundles/minifi-framework-bundle/minifi-framework/minifi-framework-core/src/main/java/org/apache/nifi/minifi/c2/command/FlowPropertyEncryptor.java:
##########
@@ -0,0 +1,167 @@
+/*
+ * 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.minifi.c2.command;
+
+import static java.lang.String.format;
+import static java.util.Optional.ofNullable;
+import static java.util.function.Predicate.not;
+import static java.util.stream.Collectors.toMap;
+import static java.util.stream.Collectors.toSet;
+import static java.util.stream.Stream.concat;
+import static org.apache.commons.lang3.StringUtils.EMPTY;
+import static 
org.apache.nifi.controller.serialization.FlowSerializer.ENC_PREFIX;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Optional;
+import java.util.Set;
+import java.util.function.Function;
+import java.util.stream.Stream;
+import org.apache.nifi.c2.protocol.component.api.DefinedType;
+import org.apache.nifi.c2.protocol.component.api.PropertyDescriptor;
+import org.apache.nifi.c2.protocol.component.api.RuntimeManifest;
+import org.apache.nifi.controller.flow.VersionedDataflow;
+import org.apache.nifi.encrypt.PropertyEncryptor;
+import org.apache.nifi.flow.VersionedConfigurableExtension;
+import org.apache.nifi.flow.VersionedParameter;
+import org.apache.nifi.flow.VersionedProcessGroup;
+import org.apache.nifi.flow.VersionedPropertyDescriptor;
+import org.apache.nifi.minifi.commons.service.FlowSerDeService;
+
+public class FlowPropertyEncryptor {

Review Comment:
   Introduced the interface



-- 
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: issues-unsubscr...@nifi.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to