Skip to content

Commit

Permalink
fix: ErrorRoutingIT test (#2977)
Browse files Browse the repository at this point in the history
* fix: ErrorRoutingIT test failure message

- correct the order of actual vs. expected, such that
the test failure message is correct
- before this commit, the failure message is:
```
java.lang.AssertionError: Check status code from /error429 is 200 expected:<429> but was:<200>
```
which is not correct

* fix: ErrorRoutingIT

- the test is intended to access /error429 as a browser would
and expects a 200 response (due to this request mapping:
https://github.com/cloudfoundry/uaa/blob/0a28b5c5aa33c68a5cdb20f23812d5187135b4a8/server/src/main/java/org/cloudfoundry/identity/uaa/home/HomeController.java#L155 and NOT https://github.com/cloudfoundry/uaa/blob/0a28b5c5aa33c68a5cdb20f23812d5187135b4a8/server/src/main/java/org/cloudfoundry/identity/uaa/home/HomeController.java#L144)

- however, in some environments where this test is run, the test
does not access the /error429 like a browser would (e.g. does not
have the request header "Accept: text/html" by default), so explictly
adding this header to the test setup to better emulate a browser
request
  • Loading branch information
peterhaochen47 authored Jul 23, 2024
1 parent 0a28b5c commit e96fac7
Showing 1 changed file with 2 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ public void testRequestRejectedExceptionErrorPage() throws IOException {
private String CallErrorPageAndCheckHttpStatusCode(String errorPath, String method, int codeExpected) throws IOException {
HttpURLConnection cn = (HttpURLConnection)new URL(baseUrl + errorPath).openConnection();
cn.setRequestMethod(method);
cn.setRequestProperty("Accept", "text/html");
// connection initiate
cn.connect();
Assert.assertEquals("Check status code from " + errorPath + " is " + codeExpected, cn.getResponseCode(), codeExpected);
Assert.assertEquals("Check status code from " + errorPath + " is " + codeExpected, codeExpected, cn.getResponseCode());
return getResponseBody(cn);
}

Expand Down

0 comments on commit e96fac7

Please sign in to comment.