Skip to content

Commit

Permalink
fix IT
Browse files Browse the repository at this point in the history
Signed-off-by: Pavel Jareš <[email protected]>
  • Loading branch information
pj892031 committed Jun 30, 2023
1 parent 4e91f64 commit bd0c71d
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ class LoginTest implements TestWithStartedInstances {
private final static String PASSWORD = ConfigReader.environmentConfiguration().getCredentials().getPassword();
private final static String INVALID_USERNAME = "incorrectUser";
private final static String INVALID_PASSWORD = "incorrectPassword";
private final static String EXPIRED_PASSWORD = "expiredPassword";

protected static URI[] loginUrlsSource() {
return new URI[]{LOGIN_ENDPOINT_URL, LOGIN_ENDPOINT_URL_OLD_FORMAT};
Expand Down Expand Up @@ -165,7 +164,7 @@ void givenInvalidCredentialsInBody(URI loginUrl) {
void givenInvalidCredentialsInHeader(URI loginUrl) {
String expectedMessage = "Invalid username or password for URL '" + getPath(loginUrl) + "'";

String headerValue = Base64.getEncoder().encodeToString((INVALID_USERNAME + ":" + INVALID_PASSWORD).getBytes(StandardCharsets.UTF_8));
String headerValue = "Basic " + Base64.getEncoder().encodeToString((INVALID_USERNAME + ":" + INVALID_PASSWORD).getBytes(StandardCharsets.UTF_8));

given()
.contentType(JSON)
Expand All @@ -179,39 +178,6 @@ void givenInvalidCredentialsInHeader(URI loginUrl) {
);
}

@ParameterizedTest(name = "givenExpiredAccountCredentialsInBody {index} {0} ")
@MethodSource("org.zowe.apiml.integration.authentication.providers.LoginTest#loginUrlsSource")
void givenExpiredAccountCredentialsInBody(URI loginUrl) {
LoginRequest loginRequest = new LoginRequest(INVALID_USERNAME, EXPIRED_PASSWORD.toCharArray());

given()
.contentType(JSON)
.body(loginRequest)
.when()
.post(loginUrl)
.then()
.statusCode(is(SC_UNAUTHORIZED))
.body(
"messages.find { it.messageNumber == 'ZWEAT412E' }.messageContent", containsString("expire")
);
}

@ParameterizedTest(name = "givenExpiredAccountCredentialsInHeader {index} {0} ")
@MethodSource("org.zowe.apiml.integration.authentication.providers.LoginTest#loginUrlsSource")
void givenExpiredAccountCredentialsInHeader(URI loginUrl) {
String headerValue = Base64.getEncoder().encodeToString((INVALID_USERNAME + ":" + EXPIRED_PASSWORD).getBytes(StandardCharsets.UTF_8));

given()
.contentType(JSON)
.header(HttpHeaders.AUTHORIZATION, headerValue)
.when()
.post(loginUrl)
.then()
.statusCode(is(SC_UNAUTHORIZED))
.body(
"messages.find { it.messageNumber == 'ZWEAT412E' }.messageContent", containsString("expire")
);
}
}

@Nested
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,25 @@
package org.zowe.apiml.integration.authentication.providers;

import io.restassured.RestAssured;
import org.apache.http.HttpHeaders;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.zowe.apiml.security.common.login.LoginRequest;
import org.zowe.apiml.util.SecurityUtils;
import org.zowe.apiml.util.TestWithStartedInstances;
import org.zowe.apiml.util.categories.SAFAuthTest;
import org.zowe.apiml.util.config.ConfigReader;

import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.util.Base64;

import static io.restassured.RestAssured.given;
import static io.restassured.http.ContentType.JSON;
import static org.apache.http.HttpStatus.SC_UNAUTHORIZED;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNot.not;
Expand Down Expand Up @@ -52,4 +61,47 @@ void givenValidCredentialsInBody(URI loginUrl) {
}
}
}

@Nested
class ExpiredPassword {

private final String USERNAME = ConfigReader.environmentConfiguration().getCredentials().getUser();
private final String EXPIRED_PASSWORD = "expiredPassword";

@ParameterizedTest(name = "givenExpiredAccountCredentialsInBody {index} {0} ")
@MethodSource("org.zowe.apiml.integration.authentication.providers.LoginTest#loginUrlsSource")
void givenExpiredAccountCredentialsInBody(URI loginUrl) {
LoginRequest loginRequest = new LoginRequest(USERNAME, EXPIRED_PASSWORD.toCharArray());

given()
.contentType(JSON)
.body(loginRequest)
.when()
.post(loginUrl)
.then()
.statusCode(is(SC_UNAUTHORIZED))
.body(
"messages.find { it.messageNumber == 'ZWEAT412E' }.messageContent", containsString("expire")
);
}

@ParameterizedTest(name = "givenExpiredAccountCredentialsInHeader {index} {0} ")
@MethodSource("org.zowe.apiml.integration.authentication.providers.LoginTest#loginUrlsSource")
void givenExpiredAccountCredentialsInHeader(URI loginUrl) {
String headerValue = "Basic " + Base64.getEncoder().encodeToString((USERNAME + ":" + EXPIRED_PASSWORD).getBytes(StandardCharsets.UTF_8));

given()
.contentType(JSON)
.header(HttpHeaders.AUTHORIZATION, headerValue)
.when()
.post(loginUrl)
.then()
.statusCode(is(SC_UNAUTHORIZED))
.body(
"messages.find { it.messageNumber == 'ZWEAT412E' }.messageContent", containsString("expire")
);
}

}

}

0 comments on commit bd0c71d

Please sign in to comment.