From dfcf7669a1221faa060a87f5f3964f2badf682ef Mon Sep 17 00:00:00 2001 From: ac892247 Date: Thu, 31 Oct 2024 17:03:31 +0100 Subject: [PATCH] align passticket tests with updated status codes, remove invalid test Signed-off-by: ac892247 --- integration-tests/build.gradle | 1 + .../integration/zaas/PassTicketTest.java | 29 ++++--------------- .../apiml/zaas/zaas/ZaasExceptionHandler.java | 11 +++++++ 3 files changed, 17 insertions(+), 24 deletions(-) diff --git a/integration-tests/build.gradle b/integration-tests/build.gradle index c0089cd121..43bed0e7d8 100644 --- a/integration-tests/build.gradle +++ b/integration-tests/build.gradle @@ -436,6 +436,7 @@ task runZaasTest(type: Test) { description "Run Zaas tests only" outputs.cacheIf { false } + systemProperty "environment.offPlatform", true systemProperties System.getProperties() useJUnitPlatform { diff --git a/integration-tests/src/test/java/org/zowe/apiml/integration/zaas/PassTicketTest.java b/integration-tests/src/test/java/org/zowe/apiml/integration/zaas/PassTicketTest.java index cec6b8aba2..b659693ebd 100644 --- a/integration-tests/src/test/java/org/zowe/apiml/integration/zaas/PassTicketTest.java +++ b/integration-tests/src/test/java/org/zowe/apiml/integration/zaas/PassTicketTest.java @@ -19,7 +19,6 @@ import org.junit.jupiter.params.provider.MethodSource; import org.zowe.apiml.passticket.PassTicketService; import org.zowe.apiml.ticket.TicketRequest; -import org.zowe.apiml.util.TestWithStartedInstances; import org.zowe.apiml.util.categories.ZaasTest; import org.zowe.apiml.util.config.ConfigReader; @@ -41,19 +40,13 @@ import static org.hamcrest.core.IsNot.not; import static org.zowe.apiml.integration.zaas.ZaasTestUtil.COOKIE; import static org.zowe.apiml.integration.zaas.ZaasTestUtil.ZAAS_TICKET_URI; -import static org.zowe.apiml.util.SecurityUtils.USERNAME; -import static org.zowe.apiml.util.SecurityUtils.generateZoweJwtWithLtpa; -import static org.zowe.apiml.util.SecurityUtils.getConfiguredSslConfig; -import static org.zowe.apiml.util.SecurityUtils.getZosmfJwtTokenFromGw; -import static org.zowe.apiml.util.SecurityUtils.getZosmfLtpaToken; -import static org.zowe.apiml.util.SecurityUtils.personalAccessToken; -import static org.zowe.apiml.util.SecurityUtils.validOktaAccessToken; +import static org.zowe.apiml.util.SecurityUtils.*; /** * Verify integration of the API ML PassTicket support with the zOS provider of the PassTicket. */ @ZaasTest -class PassTicketTest implements TestWithStartedInstances { +class PassTicketTest { private final static String APPLICATION_NAME = ConfigReader.environmentConfiguration().getDiscoverableClientConfiguration().getApplId(); @@ -186,6 +179,7 @@ void givenNoApplicationName() { .body("messages.find { it.messageNumber == 'ZWEAG140E' }.messageContent", equalTo(expectedMessage)); //@formatter:on } + @Test void givenGetHTTPMethod_thenReturnNotAllowed() { String expectedMessage = "Authentication method 'GET' is not supported for URL '/zaas/scheme/ticket'"; @@ -216,7 +210,7 @@ void givenInvalidApplicationName() { .when() .post(ZAAS_TICKET_URI) .then() - .statusCode(is(SC_BAD_REQUEST)) + .statusCode(is(SC_INTERNAL_SERVER_ERROR)) .body("messages.find { it.messageNumber == 'ZWEAG141E' }.messageContent", containsString(expectedMessage)); //@formatter:on } @@ -236,19 +230,6 @@ void givenLongApplicationName() { //@formatter:on } - @Test - void givenNoContentType() { - //@formatter:off - given() - .body(new TicketRequest(APPLICATION_NAME)) - .cookie(COOKIE, jwt) - .when() - .post(ZAAS_TICKET_URI) - .then() - .statusCode(is(SC_NOT_FOUND)); - //@formatter:on - } - @Test void givenInvalidContentType() { //@formatter:off @@ -259,7 +240,7 @@ void givenInvalidContentType() { .when() .post(ZAAS_TICKET_URI) .then() - .statusCode(is(SC_NOT_FOUND)); + .statusCode(is(SC_UNSUPPORTED_MEDIA_TYPE)); //@formatter:on } diff --git a/zaas-service/src/main/java/org/zowe/apiml/zaas/zaas/ZaasExceptionHandler.java b/zaas-service/src/main/java/org/zowe/apiml/zaas/zaas/ZaasExceptionHandler.java index 3ce00f3f73..d4c984b378 100644 --- a/zaas-service/src/main/java/org/zowe/apiml/zaas/zaas/ZaasExceptionHandler.java +++ b/zaas-service/src/main/java/org/zowe/apiml/zaas/zaas/ZaasExceptionHandler.java @@ -22,6 +22,7 @@ import org.springframework.security.access.AccessDeniedException; import org.springframework.security.core.AuthenticationException; import org.springframework.util.Assert; +import org.springframework.web.HttpMediaTypeNotSupportedException; import org.springframework.web.HttpRequestMethodNotSupportedException; import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ExceptionHandler; @@ -209,4 +210,14 @@ public ResponseEntity handleInternalException(Exception exceptio .body(messageView); } + @ExceptionHandler(HttpMediaTypeNotSupportedException.class) + public ResponseEntity handleUnsupportedMediaException(HttpMediaTypeNotSupportedException exception) { + log.debug("Requested media type is not supported", exception); + ApiMessageView messageView = messageService.createMessage("org.zowe.apiml.common.unsupportedMediaType").mapToView(); + return ResponseEntity + .status(HttpStatus.UNSUPPORTED_MEDIA_TYPE) + .contentType(MediaType.APPLICATION_JSON) + .body(messageView); + } + }