aboutsummaryrefslogtreecommitdiffstats
path: root/src/test
diff options
context:
space:
mode:
authorTony Hansen <tony@att.com>2019-10-13 00:45:21 +0000
committerGerrit Code Review <gerrit@onap.org>2019-10-13 00:45:21 +0000
commitb9a91b3967a5b415d91bf00454b428bb93a567b6 (patch)
tree74f297ab20c75fd784b6d50d698b03aafbfe2c62 /src/test
parent4d4cd07c6f99a0db9e7cc69fbd43f50ef7e06942 (diff)
parent66a03964d15e5df6655f58a2450f60fb03dc717e (diff)
Merge "Add tests for healthcheck port requests in ApiAuthInterception"
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/org/onap/dcae/restapi/ApiAuthInterceptionTest.java36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/test/java/org/onap/dcae/restapi/ApiAuthInterceptionTest.java b/src/test/java/org/onap/dcae/restapi/ApiAuthInterceptionTest.java
index e6d67cf4..c80b56cb 100644
--- a/src/test/java/org/onap/dcae/restapi/ApiAuthInterceptionTest.java
+++ b/src/test/java/org/onap/dcae/restapi/ApiAuthInterceptionTest.java
@@ -174,4 +174,40 @@ public class ApiAuthInterceptionTest {
verify(response).setStatus(HttpStatus.UNAUTHORIZED.value());
verify(writer).write(ApiException.UNAUTHORIZED_USER.toJSON().toString());
}
+
+ @Test
+ public void shouldSucceedForHealthcheckOnHealthcheckPort() throws IOException {
+ // given
+ final HttpServletRequest request =
+ MockMvcRequestBuilders
+ .get("/healthcheck")
+ .buildRequest(null);
+
+ when(settings.authMethod()).thenReturn(AuthMethodType.CERT_BASIC_AUTH.value());
+ when(settings.httpPort()).thenReturn(request.getServerPort());
+
+ // when
+ final boolean isAuthorized = sut.preHandle(request, response, obj);
+
+ // then
+ assertTrue(isAuthorized);
+ }
+
+ @Test
+ public void shouldFailDueToNotPermittedOperationOnHealthcheckPort() throws IOException {
+ // given
+ final HttpServletRequest request = createEmptyRequest();
+
+ when(settings.authMethod()).thenReturn(AuthMethodType.CERT_BASIC_AUTH.value());
+ when(settings.httpPort()).thenReturn(request.getServerPort());
+ when(response.getWriter()).thenReturn(writer);
+
+ // when
+ final boolean isAuthorized = sut.preHandle(request, response, obj);
+
+ // then
+ assertFalse(isAuthorized);
+ verify(response).setStatus(HttpStatus.BAD_REQUEST.value());
+ }
+
}