From 66a03964d15e5df6655f58a2450f60fb03dc717e Mon Sep 17 00:00:00 2001 From: Remigiusz Janeczek Date: Mon, 7 Oct 2019 14:47:02 +0200 Subject: Add tests for healthcheck port requests in ApiAuthInterception Issue-ID: DCAEGEN2-1819 Change-Id: Id4f333e856bd5bbef14d4322a8eb7c01575f4796 Signed-off-by: Remigiusz Janeczek --- .../onap/dcae/restapi/ApiAuthInterceptionTest.java | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) 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()); + } + } -- cgit 1.2.3-korg