Test starting application with OBF: password 55/81955/1
authormark.j.leonard <mark.j.leonard@gmail.com>
Mon, 11 Mar 2019 15:37:58 +0000 (15:37 +0000)
committermark.j.leonard <mark.j.leonard@gmail.com>
Mon, 11 Mar 2019 15:37:58 +0000 (15:37 +0000)
Test an uncovered code path. Remove the unnecessary declaration of the
Jetty OBF: prefix constant String. Ensure that the Spring Application
exits before the next JUnit test runs.

Change-Id: Iceb2e79a923359c15ca6ad366c2ac94a63e381b0
Issue-ID: AAI-2229
Signed-off-by: mark.j.leonard <mark.j.leonard@gmail.com>
src/main/java/org/onap/aai/babel/BabelApplication.java
src/test/java/org/onap/aai/babel/TestApplication.java

index 267642e..9eaa0ce 100644 (file)
@@ -2,8 +2,8 @@
  * ============LICENSE_START=======================================================
  * org.onap.aai
  * ================================================================================
- * Copyright © 2017-2019 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2019 European Software Marketing Ltd.
+ * Copyright (c) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (c) 2017-2019 European Software Marketing Ltd.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -23,21 +23,24 @@ package org.onap.aai.babel;
 
 import java.util.HashMap;
 import org.eclipse.jetty.util.security.Password;
+import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.boot.builder.SpringApplicationBuilder;
 import org.springframework.boot.web.support.SpringBootServletInitializer;
+import org.springframework.context.ConfigurableApplicationContext;
 import org.springframework.context.annotation.ImportResource;
 
 @SpringBootApplication
 @ImportResource("classpath:babel-beans.xml")
 public class BabelApplication extends SpringBootServletInitializer {
 
-    private static final String OBFS_PATTERN = "OBF:";
+    private static ConfigurableApplicationContext context;
 
     /**
      * Spring Boot Initialization.
      * 
-     * @param args main args
+     * @param args
+     *            main args
      */
     public static void main(String[] args) {
         String keyStorePassword = System.getProperty("KEY_STORE_PASSWORD");
@@ -45,15 +48,19 @@ public class BabelApplication extends SpringBootServletInitializer {
             throw new IllegalArgumentException("Env property KEY_STORE_PASSWORD not set");
         }
         HashMap<String, Object> props = new HashMap<>();
-        String decryptedValue =
-                keyStorePassword.startsWith(OBFS_PATTERN) ? Password.deobfuscate(keyStorePassword) : keyStorePassword;
+        String decryptedValue = keyStorePassword.startsWith(Password.__OBFUSCATE) ? //
+                Password.deobfuscate(keyStorePassword) : keyStorePassword;
         props.put("server.ssl.key-store-password", decryptedValue);
 
         String requireClientAuth = System.getenv("REQUIRE_CLIENT_AUTH");
         props.put("server.ssl.client-auth",
                 Boolean.FALSE.toString().equalsIgnoreCase(requireClientAuth) ? "want" : "need");
 
-        new BabelApplication().configure(new SpringApplicationBuilder(BabelApplication.class).properties(props))
-                .run(args);
+        context = new BabelApplication()
+                .configure(new SpringApplicationBuilder(BabelApplication.class).properties(props)).run(args);
+    }
+
+    public static void exit() {
+        SpringApplication.exit(context);
     }
 }
index 2821dc1..8c9ca5e 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