summaryrefslogtreecommitdiffstats
path: root/src/test
diff options
context:
space:
mode:
authormark.j.leonard <mark.j.leonard@gmail.com>2019-02-15 11:30:00 +0000
committermark.j.leonard <mark.j.leonard@gmail.com>2019-02-15 17:11:43 +0000
commit66372969d78dde14097209808358479635c0e8d0 (patch)
treef96c54a92604472157393bca4ff2f700b9074d62 /src/test
parent209cd56d7f2f885a94fc5f937c4376fc0ffbd922 (diff)
Create Application tests for KEY_STORE_PASSWORD
Add a dummy keystore file for testing exceptions relating to opening the key store (for the server cert) with an incorrect password. This is intended to increase code coverage. Make AAIMicroServiceAuthCore non-static to avoid some issues with Spring initialization. Change-Id: Ic512bd0934210fb016da9731e65ec0d858fa4ff7 Issue-ID: AAI-2057 Signed-off-by: mark.j.leonard <mark.j.leonard@gmail.com>
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/org/onap/aai/validation/TestApplication.java41
-rw-r--r--src/test/java/org/onap/aai/validation/auth/MicroServiceAuthTest.java31
-rw-r--r--src/test/resources/model-validation/instance-validator/auth/auth_policy.json55
-rw-r--r--src/test/resources/model-validation/instance-validator/auth/tomcat_keystorebin0 -> 32 bytes
-rw-r--r--src/test/resources/model-validation/instance-validator/validation-service-auth.properties2
-rw-r--r--src/test/resources/test-application.properties24
6 files changed, 132 insertions, 21 deletions
diff --git a/src/test/java/org/onap/aai/validation/TestApplication.java b/src/test/java/org/onap/aai/validation/TestApplication.java
index 3dfa177..9f66df9 100644
--- a/src/test/java/org/onap/aai/validation/TestApplication.java
+++ b/src/test/java/org/onap/aai/validation/TestApplication.java
@@ -20,6 +20,9 @@
*/
package org.onap.aai.validation;
+import java.io.IOException;
+import org.hamcrest.Description;
+import org.hamcrest.TypeSafeMatcher;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@@ -33,7 +36,7 @@ import org.springframework.test.context.TestPropertySource;
*
*/
@SpringBootTest(classes = ValidationServiceApplication.class)
-@TestPropertySource(locations = {"classpath:oxm-reader/schemaIngest.properties", "classpath:application.properties"})
+@TestPropertySource(locations = {"classpath:oxm-reader/schemaIngest.properties", "classpath:test-application.properties"})
@ContextConfiguration(locations = {"classpath:validation-service-beans.xml"})
public class TestApplication {
@@ -63,4 +66,40 @@ public class TestApplication {
ValidationServiceApplication.main(new String[] {});
}
+ @Test
+ public void testApplicationWithEmptyKeyStorePassword() {
+ System.setProperty("KEY_STORE_PASSWORD", "");
+ final CauseMatcher expectedCause = new CauseMatcher(IOException.class, "password was incorrect");
+ expectedEx.expectCause(expectedCause);
+ ValidationServiceApplication.main(new String[] {});
+ }
+
+ @Test
+ public void testApplicationWithIncorrectKeyStorePassword() {
+ System.setProperty("KEY_STORE_PASSWORD", "test");
+ final CauseMatcher expectedCause = new CauseMatcher(IOException.class, "password was incorrect");
+ expectedEx.expectCause(expectedCause);
+ ValidationServiceApplication.main(new String[] {});
+ }
+
+ private static class CauseMatcher extends TypeSafeMatcher<Throwable> {
+
+ private final Class<? extends Throwable> type;
+ private final String expectedMessage;
+
+ public CauseMatcher(Class<? extends Throwable> type, String expectedMessage) {
+ this.type = type;
+ this.expectedMessage = expectedMessage;
+ }
+
+ @Override
+ protected boolean matchesSafely(Throwable item) {
+ return item.getClass().isAssignableFrom(type) && item.getMessage().contains(expectedMessage);
+ }
+
+ @Override
+ public void describeTo(Description description) {
+ description.appendValue(type).appendText(" and message ").appendValue(expectedMessage);
+ }
+ }
}
diff --git a/src/test/java/org/onap/aai/validation/auth/MicroServiceAuthTest.java b/src/test/java/org/onap/aai/validation/auth/MicroServiceAuthTest.java
index f9bd177..7217224 100644
--- a/src/test/java/org/onap/aai/validation/auth/MicroServiceAuthTest.java
+++ b/src/test/java/org/onap/aai/validation/auth/MicroServiceAuthTest.java
@@ -1,7 +1,10 @@
-/*
- * ============LICENSE_START===================================================
- * Copyright (c) 2018 Amdocs
- * ============================================================================
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright (c) 2018-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (c) 2018-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.
* You may obtain a copy of the License at
@@ -13,8 +16,9 @@
* 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.
- * ============LICENSE_END=====================================================
+ * ============LICENSE_END=========================================================
*/
+
package org.onap.aai.validation.auth;
import static org.hamcrest.CoreMatchers.equalTo;
@@ -35,19 +39,16 @@ import org.junit.Test;
import org.mockito.Mockito;
import org.onap.aai.auth.AAIAuthException;
import org.onap.aai.auth.AAIMicroServiceAuth;
-import org.onap.aai.auth.AAIMicroServiceAuthCore;
import org.onap.aai.validation.config.ValidationServiceAuthConfig;
import org.springframework.mock.web.MockHttpServletRequest;
/**
* Tests @{link AAIMicroServiceAuth}
*/
-
public class MicroServiceAuthTest {
static {
- System.setProperty("APP_HOME", ".");
- System.setProperty("CONFIG_HOME", Paths.get(System.getProperty("user.dir"), "src/test/resources").toString());
+ System.setProperty("CONFIG_HOME", Paths.get("src/test/resources").toString());
}
private static final String VALID_ADMIN_USER = "cn=common-name, ou=org-unit, o=org, l=location, st=state, c=us";
@@ -62,15 +63,9 @@ public class MicroServiceAuthTest {
*/
@Test(expected = AAIAuthException.class)
public void missingPolicyFile() throws AAIAuthException, IOException {
- String defaultFile = AAIMicroServiceAuthCore.getDefaultAuthFileName();
- try {
- AAIMicroServiceAuthCore.setDefaultAuthFileName("invalid.default.file");
- ValidationServiceAuthConfig authConfig = new ValidationServiceAuthConfig();
- authConfig.setAuthPolicyFile("invalid.file.name");
- new AAIMicroServiceAuth(authConfig);
- } finally {
- AAIMicroServiceAuthCore.setDefaultAuthFileName(defaultFile);
- }
+ ValidationServiceAuthConfig authConfig = new ValidationServiceAuthConfig();
+ authConfig.setAuthPolicyFile("invalid.file.name");
+ new AAIMicroServiceAuth(authConfig);
}
/**
diff --git a/src/test/resources/model-validation/instance-validator/auth/auth_policy.json b/src/test/resources/model-validation/instance-validator/auth/auth_policy.json
new file mode 100644
index 0000000..2bf63d1
--- /dev/null
+++ b/src/test/resources/model-validation/instance-validator/auth/auth_policy.json
@@ -0,0 +1,55 @@
+{"roles": [
+ {
+ "name": "admin",
+ "functions": [
+ {
+ "name": "actions",
+ "methods": [
+ {"name": "GET"},
+ {"name": "DELETE"},
+ {"name": "PUT"}
+ ]
+ },
+ {
+ "name": "validate",
+ "methods": [{"name": "POST"}]
+ }
+ ],
+ "users": [
+ {"username": "CN=common-name, OU=org-unit, O=org, L=location, ST=state, C=US"},
+ {"username": "CN=test, OU=qa, O=Test Ltd, L=London, ST=London, C=GB"}
+ ]
+ },
+ {
+ "name": "ops",
+ "functions": [{
+ "name": "actions",
+ "methods": [{"name": "POST"}]
+ }],
+ "users": [
+ {"username": "CN=common-name, OU=org-unit, O=org, L=location, ST=state, C=US"},
+ {"username": "CN=test, OU=qa, O=Test Ltd, L=London, ST=London, C=GB"}
+ ]
+ },
+ {
+ "name": "basicauth",
+ "functions": [{
+ "name": "util",
+ "methods": [{"name": "GET"}]
+ }],
+ "users": [{
+ "user": "aai",
+ "pass": "OBF:1u2a1t2v1vgb1s3g1s3m1vgj1t3b1u30"
+ }]
+ },
+ {
+ "name": "nofuncauth",
+ "functions": [{
+ "name": "nofuncutil"
+ }],
+ "users": [{
+ "user": "aai",
+ "pass": "OBF:1u2a1t2v1vgb1s3g1s3m1vgj1t3b1u30"
+ }]
+ }
+]}
diff --git a/src/test/resources/model-validation/instance-validator/auth/tomcat_keystore b/src/test/resources/model-validation/instance-validator/auth/tomcat_keystore
new file mode 100644
index 0000000..f7dc0ea
--- /dev/null
+++ b/src/test/resources/model-validation/instance-validator/auth/tomcat_keystore
Binary files differ
diff --git a/src/test/resources/model-validation/instance-validator/validation-service-auth.properties b/src/test/resources/model-validation/instance-validator/validation-service-auth.properties
index 1c1ed97..8e07a2a 100644
--- a/src/test/resources/model-validation/instance-validator/validation-service-auth.properties
+++ b/src/test/resources/model-validation/instance-validator/validation-service-auth.properties
@@ -14,5 +14,5 @@
# limitations under the License.
# ============LICENSE_END=====================================================
-auth.policy.file=appconfig-local/auth/auth_policy.json
+auth.policy.file=${CONFIG_HOME}/auth/auth_policy.json
auth.authentication.disable=false \ No newline at end of file
diff --git a/src/test/resources/test-application.properties b/src/test/resources/test-application.properties
index 38b2962..c703e85 100644
--- a/src/test/resources/test-application.properties
+++ b/src/test/resources/test-application.properties
@@ -1,6 +1,28 @@
+# ============LICENSE_START=======================================================
+# org.onap.aai
+# ================================================================================
+# Copyright (c) 2018-2019 AT&T Intellectual Property. All rights reserved.
+# Copyright (c) 2018-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.
+# 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.
+# ============LICENSE_END=========================================================
+
+APP_HOME=.
+CONFIG_HOME=src/test/resources
+
consumer.topic.names=aai-event,aai-data-export
publisher.topic.names=aai-data-integrity
-topics.properties.location=src/test/resources/topic-config/
+topics.properties.location=${CONFIG_HOME}/topic-config/
server.ssl.key-store=