Skip to content

Commit

Permalink
test refactorings
Browse files Browse the repository at this point in the history
Check error text now in body instead of URL parameter.
The error itself should be checked but now in body only and no longer in URL parameter
  • Loading branch information
strehle committed Aug 5, 2021
1 parent f597d81 commit e9e1014
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,12 @@ public String error401(Model model, HttpServletRequest request) {

@RequestMapping("/oauth_error")
public String error_oauth(Model model, HttpServletRequest request) {
String exception = (String) request.getSession().getAttribute("oauth_error");
String OAUTH_ERROR = "oauth_error";
String exception = (String) request.getSession().getAttribute(OAUTH_ERROR);

if (exception != null) {
model.addAttribute("oauth_error", exception);
request.getSession().removeAttribute("oauth_error");
if (hasText(exception)) {
model.addAttribute(OAUTH_ERROR, exception);
request.getSession().removeAttribute(OAUTH_ERROR);
}
return "external_auth_error";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
</div>
<img src="/resources/images/sad_cloud.png" th:src="@{/resources/images/sad_cloud.png}" role="presentation" />
</div>
<h2 th:text="${saml_error}">
<h2 th:if="${saml_error}" th:text="${saml_error}">
</h2>
<h2 th:text="${oauth_error}">
<h2 th:if="${oauth_error}" th:text="${oauth_error}">
</h2>
</div>
</body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
import static org.cloudfoundry.identity.uaa.oauth.token.ClaimConstants.SUB;
import static org.cloudfoundry.identity.uaa.oauth.token.TokenConstants.GRANT_TYPE_AUTHORIZATION_CODE;
import static org.cloudfoundry.identity.uaa.provider.ExternalIdentityProviderDefinition.USER_NAME_ATTRIBUTE_NAME;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.not;
Expand All @@ -84,7 +85,6 @@
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;

@RunWith(SpringJUnit4ClassRunner.class)
Expand Down Expand Up @@ -243,7 +243,7 @@ private void login(String zoneUrl, String userName, String password) {
assertNotNull(beforeLogin);
assertNotNull(beforeLogin.getValue());
webDriver.findElement(By.linkText("My OIDC Provider")).click();
Assert.assertThat(webDriver.getCurrentUrl(), containsString(baseUrl));
assertThat(webDriver.getCurrentUrl(), containsString(baseUrl));

webDriver.findElement(By.name("username")).sendKeys(userName);
webDriver.findElement(By.name("password")).sendKeys(password);
Expand Down Expand Up @@ -376,9 +376,10 @@ public void login_with_wrong_keys() throws Exception {
webDriver.findElement(By.name("password")).sendKeys("koala");
webDriver.findElement(By.xpath("//input[@value='Sign in']")).click();

Assert.assertThat(webDriver.getCurrentUrl(), containsString(zoneUrl + "/oauth_error"));
assertThat(webDriver.getCurrentUrl(), containsString(zoneUrl + "/oauth_error"));
// no error as parameter sent
Assert.assertThat(webDriver.getCurrentUrl(), not(containsString("?error=")));
assertThat(webDriver.getCurrentUrl(), not(containsString("?error=")));
assertThat(webDriver.findElement(By.cssSelector("h2")).getText(), containsString("There was an error when authenticating against the external identity provider"));

List<String> cookies = IntegrationTestUtils.getAccountChooserCookies(zoneUrl, webDriver);
assertThat(cookies, not(Matchers.hasItem(startsWith("Saved-Account-"))));
Expand Down

0 comments on commit e9e1014

Please sign in to comment.