Repository: nifi-minifi
Updated Branches:
  refs/heads/master 6f528bbc1 -> 47cf2209e


MINIFI-40 - Defaulting to empty string for keystore, truststore, sslProtocol, 
keystoreType, keystorePassword, keyPassword, truststoreType

This closes #19

Signed-off-by: Joseph Percivall <[email protected]>


Project: http://git-wip-us.apache.org/repos/asf/nifi-minifi/repo
Commit: http://git-wip-us.apache.org/repos/asf/nifi-minifi/commit/47cf2209
Tree: http://git-wip-us.apache.org/repos/asf/nifi-minifi/tree/47cf2209
Diff: http://git-wip-us.apache.org/repos/asf/nifi-minifi/diff/47cf2209

Branch: refs/heads/master
Commit: 47cf2209e046b7910d3e0ca324fee9e77607c854
Parents: 6f528bb
Author: Bryan Rosander <[email protected]>
Authored: Fri Jun 17 16:48:50 2016 -0400
Committer: Joseph Percivall <[email protected]>
Committed: Mon Jun 27 14:33:52 2016 -0400

----------------------------------------------------------------------
 minifi-bootstrap/pom.xml                        |  7 ++
 .../util/schema/SecurityPropertiesSchema.java   | 37 ++++-----
 .../schema/SecurityPropertiesSchemaTest.java    | 80 ++++++++++++++++++++
 3 files changed, 106 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/nifi-minifi/blob/47cf2209/minifi-bootstrap/pom.xml
----------------------------------------------------------------------
diff --git a/minifi-bootstrap/pom.xml b/minifi-bootstrap/pom.xml
index 2616190..114396b 100644
--- a/minifi-bootstrap/pom.xml
+++ b/minifi-bootstrap/pom.xml
@@ -79,6 +79,13 @@ limitations under the License.
             <groupId>org.apache.nifi</groupId>
             <artifactId>nifi-framework-core</artifactId>
             <version>0.6.0</version>
+            <exclusions>
+                <!-- excluding for IDE purposes, this jar doesn't wind up in 
the lib/bootstrap folder so isn't safe to use in bootstrap project -->
+                <exclusion>
+                    <groupId>org.apache.nifi</groupId>
+                    <artifactId>nifi-properties</artifactId>
+                </exclusion>
+            </exclusions>
         </dependency>
     </dependencies>
 

http://git-wip-us.apache.org/repos/asf/nifi-minifi/blob/47cf2209/minifi-bootstrap/src/main/java/org/apache/nifi/minifi/bootstrap/util/schema/SecurityPropertiesSchema.java
----------------------------------------------------------------------
diff --git 
a/minifi-bootstrap/src/main/java/org/apache/nifi/minifi/bootstrap/util/schema/SecurityPropertiesSchema.java
 
b/minifi-bootstrap/src/main/java/org/apache/nifi/minifi/bootstrap/util/schema/SecurityPropertiesSchema.java
index 96a9261..a303125 100644
--- 
a/minifi-bootstrap/src/main/java/org/apache/nifi/minifi/bootstrap/util/schema/SecurityPropertiesSchema.java
+++ 
b/minifi-bootstrap/src/main/java/org/apache/nifi/minifi/bootstrap/util/schema/SecurityPropertiesSchema.java
@@ -52,32 +52,32 @@ public class SecurityPropertiesSchema extends BaseSchema {
     }
 
     public SecurityPropertiesSchema(Map map) {
-        keystore = getOptionalKeyAsType(map, KEYSTORE_KEY, String.class, 
SECURITY_PROPS_KEY, null);
+        keystore = getOptionalKeyAsType(map, KEYSTORE_KEY, String.class, 
SECURITY_PROPS_KEY, "");
 
-        keystoreType = getOptionalKeyAsType(map, KEYSTORE_TYPE_KEY, 
String.class, SECURITY_PROPS_KEY, null);
-        if (keystoreType != null) {
+        keystoreType = getOptionalKeyAsType(map, KEYSTORE_TYPE_KEY, 
String.class, SECURITY_PROPS_KEY, "");
+        if (!isNullOrEmpty(keystoreType)) {
             if (validateStoreType(keystoreType)) {
                 addValidationIssue(KEYSTORE_TYPE_KEY, SECURITY_PROPS_KEY, "it 
is not a supported type (must be either PKCS12 or JKS format)");
             }
         }
 
-        keystorePassword = getOptionalKeyAsType(map, KEYSTORE_PASSWORD_KEY, 
String.class, SECURITY_PROPS_KEY, null);
+        keystorePassword = getOptionalKeyAsType(map, KEYSTORE_PASSWORD_KEY, 
String.class, SECURITY_PROPS_KEY, "");
 
-        keyPassword = getOptionalKeyAsType(map, KEY_PASSWORD_KEY, 
String.class, SECURITY_PROPS_KEY, null);
+        keyPassword = getOptionalKeyAsType(map, KEY_PASSWORD_KEY, 
String.class, SECURITY_PROPS_KEY, "");
 
-        truststore = getOptionalKeyAsType(map, TRUSTSTORE_KEY, String.class, 
SECURITY_PROPS_KEY, null);
+        truststore = getOptionalKeyAsType(map, TRUSTSTORE_KEY, String.class, 
SECURITY_PROPS_KEY, "");
 
-        truststoreType = getOptionalKeyAsType(map, TRUSTSTORE_TYPE_KEY, 
String.class, SECURITY_PROPS_KEY, null);
-        if (truststoreType != null) {
+        truststoreType = getOptionalKeyAsType(map, TRUSTSTORE_TYPE_KEY, 
String.class, SECURITY_PROPS_KEY, "");
+        if (!isNullOrEmpty(truststoreType)) {
             if (validateStoreType(truststoreType)) {
                 addValidationIssue(TRUSTSTORE_TYPE_KEY, SECURITY_PROPS_KEY, 
"it is not a supported type (must be either PKCS12 or JKS format)");
             }
         }
 
-        truststorePassword = getOptionalKeyAsType(map, 
TRUSTSTORE_PASSWORD_KEY, String.class, SECURITY_PROPS_KEY, null);
+        truststorePassword = getOptionalKeyAsType(map, 
TRUSTSTORE_PASSWORD_KEY, String.class, SECURITY_PROPS_KEY, "");
 
-        sslProtocol = getOptionalKeyAsType(map, SSL_PROTOCOL_KEY, 
String.class, SECURITY_PROPS_KEY, null);
-        if (sslProtocol != null) {
+        sslProtocol = getOptionalKeyAsType(map, SSL_PROTOCOL_KEY, 
String.class, SECURITY_PROPS_KEY, "");
+        if (!isNullOrEmpty(sslProtocol)) {
             switch (sslProtocol) {
                 case "SSL":
                     break;
@@ -97,17 +97,14 @@ public class SecurityPropertiesSchema extends BaseSchema {
                     addValidationIssue(SSL_PROTOCOL_KEY, SECURITY_PROPS_KEY, 
"it is not an allowable value of SSL protocol");
                     break;
             }
-        }
-
-        if (sslProtocol != null) {
-            if (keystore == null) {
+            if (isNullOrEmpty(keystore)) {
                 validationIssues.add("When the '" + SSL_PROTOCOL_KEY + "' key 
of '" + SECURITY_PROPS_KEY + "' is set, the '" + KEYSTORE_KEY + "' must also be 
set");
-            } else if (keystoreType == null || keystorePassword == null || 
keyPassword == null) {
+            } else if (isNullOrEmpty(keystoreType) || 
isNullOrEmpty(keystorePassword) || isNullOrEmpty(keyPassword)) {
                 validationIssues.add("When the '" + KEYSTORE_KEY + "' key of 
'" + SECURITY_PROPS_KEY + "' is set, the '" + KEYSTORE_TYPE_KEY + "', '" + 
KEYSTORE_PASSWORD_KEY +
                         "' and '" + KEY_PASSWORD_KEY + "' all must also be 
set");
             }
 
-            if (truststore != null && (truststoreType == null || 
truststorePassword == null)) {
+            if (!isNullOrEmpty(truststore) && (isNullOrEmpty(truststoreType) 
|| isNullOrEmpty(truststorePassword))) {
                 validationIssues.add("When the '" + TRUSTSTORE_KEY + "' key of 
'" + SECURITY_PROPS_KEY + "' is set, the '" + TRUSTSTORE_TYPE_KEY + "' and '" +
                         TRUSTSTORE_PASSWORD_KEY + "' must also be set");
             }
@@ -123,7 +120,7 @@ public class SecurityPropertiesSchema extends BaseSchema {
     }
 
     public boolean useSSL() {
-        return sslProtocol != null && !(sslProtocol.isEmpty());
+        return !isNullOrEmpty(sslProtocol);
     }
 
     public String getKeystore() {
@@ -161,4 +158,8 @@ public class SecurityPropertiesSchema extends BaseSchema {
     public SensitivePropsSchema getSensitiveProps() {
         return sensitiveProps;
     }
+
+    private static boolean isNullOrEmpty(final String string) {
+        return string == null || string.isEmpty();
+    }
 }

http://git-wip-us.apache.org/repos/asf/nifi-minifi/blob/47cf2209/minifi-bootstrap/src/test/java/org/apache/nifi/minifi/bootstrap/util/schema/SecurityPropertiesSchemaTest.java
----------------------------------------------------------------------
diff --git 
a/minifi-bootstrap/src/test/java/org/apache/nifi/minifi/bootstrap/util/schema/SecurityPropertiesSchemaTest.java
 
b/minifi-bootstrap/src/test/java/org/apache/nifi/minifi/bootstrap/util/schema/SecurityPropertiesSchemaTest.java
new file mode 100644
index 0000000..ee889d2
--- /dev/null
+++ 
b/minifi-bootstrap/src/test/java/org/apache/nifi/minifi/bootstrap/util/schema/SecurityPropertiesSchemaTest.java
@@ -0,0 +1,80 @@
+/*
+ * 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.bootstrap.util.schema;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.HashMap;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+public class SecurityPropertiesSchemaTest {
+    private SecurityPropertiesSchema securityPropertiesSchema;
+
+    @Before
+    public void setup() {
+        securityPropertiesSchema = new SecurityPropertiesSchema(new HashMap());
+    }
+
+    @Test
+    public void testKeystoreDefault() {
+        assertEquals("", securityPropertiesSchema.getKeystore());
+    }
+
+    @Test
+    public void testTruststoreDefault() {
+        assertEquals("", securityPropertiesSchema.getTruststore());
+    }
+
+    @Test
+    public void testSslProtocolDefault() {
+        assertEquals("", securityPropertiesSchema.getSslProtocol());
+    }
+
+    @Test
+    public void testKeystoreTypeDefault() {
+        assertEquals("", securityPropertiesSchema.getKeystoreType());
+    }
+
+    @Test
+    public void testKeyStorePasswdDefault() {
+        assertEquals("", securityPropertiesSchema.getKeystorePassword());
+    }
+
+    @Test
+    public void testKeyPasswordDefault() {
+        assertEquals("", securityPropertiesSchema.getKeyPassword());
+    }
+
+    @Test
+    public void testTruststoreTypeDefault() {
+        assertEquals("", securityPropertiesSchema.getTruststoreType());
+    }
+
+    @Test
+    public void testTruststorePasswdDefault() {
+        assertEquals("", securityPropertiesSchema.getTruststorePassword());
+    }
+
+    @Test
+    public void testEmptyMapConstructorValid() {
+        assertTrue(securityPropertiesSchema.isValid());
+    }
+}

Reply via email to