2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (c) 2017-2019 AT&T Intellectual Property. All rights reserved.
6 * Copyright (c) 2017-2019 European Software Marketing Ltd.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.aai.babel;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
26 import static org.junit.jupiter.api.Assertions.assertThrows;
27 import static org.junit.jupiter.api.Assertions.assertTrue;
29 import java.io.IOException;
30 import org.eclipse.jetty.util.security.Password;
31 import org.hamcrest.Description;
32 import org.hamcrest.TypeSafeMatcher;
33 import org.junit.jupiter.api.BeforeEach;
34 import org.junit.jupiter.api.Test;
35 import org.junit.rules.ExpectedException;
36 import org.springframework.boot.test.context.SpringBootTest;
37 import org.springframework.context.ApplicationContextException;
39 @SpringBootTest(classes = BabelApplication.class)
40 public class TestApplication {
43 * Initialize System Properties.
47 System.setProperty("APP_HOME", ".");
48 System.setProperty("CONFIG_HOME", "src/test/resources");
49 System.setProperty("server.ssl.key-store", "src/test/resources/auth/keystore.jks");
53 public void testApplicationStarts() {
54 assertDoesNotThrow(() -> {
55 System.setProperty("KEY_STORE_PASSWORD", "password");
56 BabelApplication.main(new String[]{});
57 BabelApplication.exit();
62 public void testApplicationStartsWithObfuscatedPassword() {
63 assertDoesNotThrow(() -> {
64 System.setProperty("KEY_STORE_PASSWORD", Password.obfuscate("password"));
65 BabelApplication.main(new String[]{});
66 BabelApplication.exit();
71 public void testApplicationWithNullArgs() {
72 Throwable exception = assertThrows(IllegalArgumentException.class, () -> {
73 System.setProperty("KEY_STORE_PASSWORD", "test");
74 BabelApplication.main(null);
76 assertTrue(exception.getMessage().contains("Args must not be null"));
80 public void testApplicationWithEmptyKeyStorePassword() {
81 Throwable exception = assertThrows(IllegalArgumentException.class, () -> {
82 System.setProperty("KEY_STORE_PASSWORD", "");
83 BabelApplication.main(new String[]{});
85 assertTrue(exception.getMessage().contains("roperty KEY_STORE_PASSWORD not set"));
89 public void testApplicationWithNullKeyStorePassword() {
90 Throwable exception = assertThrows(IllegalArgumentException.class, () -> {
91 System.clearProperty("KEY_STORE_PASSWORD");
92 BabelApplication.main(new String[]{});
94 assertTrue(exception.getMessage().contains("roperty KEY_STORE_PASSWORD not set"));
98 public void testApplicationWithIncorrectKeyStorePassword() {
99 Throwable exception = assertThrows(ApplicationContextException.class, () -> {
100 System.setProperty("KEY_STORE_PASSWORD", "test");
101 BabelApplication.main(new String[]{});
106 * This test asserts that if the KEY_STORE_PASSWORD System Property is set (and is not empty) then the value is
107 * passed to Jetty, debobfuscated, and used to open the key store, even if the resulting password value is actually
111 public void testApplicationWithBlankObfuscatedKeyStorePassword() {
112 // Note that "OBF:" is correctly deobfuscated and results in an empty string.
113 Throwable exception = assertThrows(ApplicationContextException.class, () -> {
114 System.setProperty("KEY_STORE_PASSWORD", "OBF:");
115 BabelApplication.main(new String[]{});