refactor tests - bad creds

This commit is contained in:
Dusan Jakub
2023-09-19 22:22:39 +02:00
parent 24159f7dcb
commit 95cf6152b6
2 changed files with 16 additions and 3 deletions

View File

@@ -59,6 +59,17 @@ public class AuthCodeGrantTest {
assertThat(accessTokenResponse.accessToken(), is(notNullValue()));
}
@Test
public void badCredentials() throws IOException {
AuthorizationCodeFlow flow = new AuthorizationCodeFlow(authUrl, CLIENT)
.scope("scope1 scope2");
LoginScreen loginScreen = flow.start().expectLogin();
loginScreen.submit("x", "bbb").expectError("Invalid credentials")
.submit("bob", "bbb").expectError("Invalid credentials")
.submit("bob", "password").expectSuccess();
}
@Test
public void authCodeGrant_invalidResponseType() throws IOException {
AuthorizationCodeFlow flow = new AuthorizationCodeFlow(authUrl, CLIENT)

View File

@@ -12,9 +12,11 @@ import static org.hamcrest.MatcherAssert.assertThat;
public class LoginScreen {
private final FormElement form;
private final Document document;
public LoginScreen(Document doc) {
this.form = doc.expectForm("form");
public LoginScreen(Document document) {
this.form = document.expectForm("form");
this.document = document;
}
public Result submit(String username, String password) throws IOException {
@@ -36,7 +38,7 @@ public class LoginScreen {
}
private LoginScreen expectError(String error) {
assertThat(Objects.requireNonNull(form.getElementById("error-popup")).text(), containsString(error));
assertThat(Objects.requireNonNull(document.getElementById("error-popup")).text(), containsString(error));
return this;
}