Skip to content

Commit

Permalink
align passticket tests with updated status codes, remove invalid test
Browse files Browse the repository at this point in the history
Signed-off-by: ac892247 <[email protected]>
  • Loading branch information
achmelo committed Oct 31, 2024
1 parent 7d56ab9 commit dfcf766
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 24 deletions.
1 change: 1 addition & 0 deletions integration-tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ task runZaasTest(type: Test) {
description "Run Zaas tests only"

outputs.cacheIf { false }
systemProperty "environment.offPlatform", true

systemProperties System.getProperties()
useJUnitPlatform {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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();

Expand Down Expand Up @@ -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'";
Expand Down Expand Up @@ -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
}
Expand All @@ -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
Expand All @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -209,4 +210,14 @@ public ResponseEntity<ApiMessageView> handleInternalException(Exception exceptio
.body(messageView);
}

@ExceptionHandler(HttpMediaTypeNotSupportedException.class)
public ResponseEntity<ApiMessageView> 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);
}

}

0 comments on commit dfcf766

Please sign in to comment.