diff options
author | Remigiusz Janeczek <remigiusz.janeczek@nokia.com> | 2019-10-07 14:47:02 +0200 |
---|---|---|
committer | Remigiusz Janeczek <remigiusz.janeczek@nokia.com> | 2019-10-09 09:18:51 +0200 |
commit | 66a03964d15e5df6655f58a2450f60fb03dc717e (patch) | |
tree | 3ad814432ae2e194cdb0f0a07a26ca695ab204b2 | |
parent | 124e11e9e7ea4652f8a538093ab48df9f575ce2a (diff) |
Add tests for healthcheck port requests in ApiAuthInterception
Issue-ID: DCAEGEN2-1819
Change-Id: Id4f333e856bd5bbef14d4322a8eb7c01575f4796
Signed-off-by: Remigiusz Janeczek <remigiusz.janeczek@nokia.com>
-rw-r--r-- | src/test/java/org/onap/dcae/restapi/ApiAuthInterceptionTest.java | 36 |
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()); + } + } |