Move REQUIRE_CLIENT_AUTH code to start script
[aai/babel.git] / src / test / java / org / onap / aai / babel / TestApplication.java
index 2821dc1..bb43b40 100644 (file)
@@ -22,6 +22,7 @@
 package org.onap.aai.babel;
 
 import java.io.IOException;
+import org.eclipse.jetty.util.security.Password;
 import org.hamcrest.Description;
 import org.hamcrest.TypeSafeMatcher;
 import org.junit.Before;
@@ -36,6 +37,9 @@ public class TestApplication {
     @Rule
     public ExpectedException expectedEx = ExpectedException.none();
 
+    /**
+     * Initialize System Properties.
+     */
     @Before
     public void init() {
         System.setProperty("APP_HOME", ".");
@@ -47,6 +51,14 @@ public class TestApplication {
     public void testApplicationStarts() {
         System.setProperty("KEY_STORE_PASSWORD", "password");
         BabelApplication.main(new String[] {});
+        BabelApplication.exit();
+    }
+
+    @Test
+    public void testApplicationStartsWithObfuscatedPassword() {
+        System.setProperty("KEY_STORE_PASSWORD", Password.obfuscate("password"));
+        BabelApplication.main(new String[] {});
+        BabelApplication.exit();
     }
 
     @Test
@@ -81,6 +93,20 @@ public class TestApplication {
         BabelApplication.main(new String[] {});
     }
 
+    /**
+     * This test asserts that if the KEY_STORE_PASSWORD System Property is set (and is not empty) then the value is
+     * passed to Jetty, debobfuscated, and used to open the key store, even if the resulting password value is actually
+     * an empty string.
+     */
+    @Test
+    public void testApplicationWithBlankObfuscatedKeyStorePassword() {
+        // Note that "OBF:" is correctly deobfuscated and results in an empty string.
+        System.setProperty("KEY_STORE_PASSWORD", "OBF:");
+        final CauseMatcher expectedCause = new CauseMatcher(IOException.class, "password was incorrect");
+        expectedEx.expectCause(expectedCause);
+        BabelApplication.main(new String[] {});
+    }
+
     private static class CauseMatcher extends TypeSafeMatcher<Throwable> {
 
         private final Class<? extends Throwable> type;