Skip to content

Commit

Permalink
Fix OAuth2 Web UI authentication filter tests
Browse files Browse the repository at this point in the history
Some of OAuth2 authentication Web UI tests were using `Bearer`
authorization header for which support has been removed.
  • Loading branch information
lukasz-walkiewicz authored and kokosing committed Jan 12, 2021
1 parent b777864 commit e80712b
Showing 1 changed file with 14 additions and 16 deletions.
Expand Up @@ -66,7 +66,6 @@
import static io.trino.server.security.oauth2.TestingHydraService.TTL_ACCESS_TOKEN_IN_SECONDS;
import static io.trino.server.ui.OAuthWebUiCookie.OAUTH2_COOKIE;
import static java.lang.String.format;
import static javax.ws.rs.core.HttpHeaders.AUTHORIZATION;
import static javax.ws.rs.core.HttpHeaders.LOCATION;
import static javax.ws.rs.core.Response.Status.OK;
import static javax.ws.rs.core.Response.Status.SEE_OTHER;
Expand Down Expand Up @@ -181,10 +180,8 @@ public void testInvalidToken()
.signWith(signatureAlgorithm, keyGenerator.generateKeyPair().getPrivate())
.compact();

try (Response response = httpClient.newCall(
uiCall()
.header(AUTHORIZATION, "Bearer " + token)
.build())
try (Response response = httpClientUsingCookie(new Cookie.Builder(OAUTH2_COOKIE, token).build())
.newCall(uiCall().build())
.execute()) {
assertUnauthorizedUICall(response);
}
Expand All @@ -210,11 +207,7 @@ public void testExpiredAccessToken()
Cookie cookie = driver.manage().getCookieNamed(OAUTH2_COOKIE);
assertThat(cookie).withFailMessage(OAUTH2_COOKIE + " is missing").isNotNull();
Thread.sleep((TTL_ACCESS_TOKEN_IN_SECONDS + 1) * 1000L); // wait for the token expiration
try (Response response = httpClient.newCall(
uiCall()
.header(AUTHORIZATION, "Bearer " + cookie.getValue())
.build())
.execute()) {
try (Response response = httpClientUsingCookie(cookie).newCall(uiCall().build()).execute()) {
assertUnauthorizedUICall(response);
}
}));
Expand Down Expand Up @@ -303,6 +296,16 @@ private void assertAccessToken(Jws<Claims> jwt)

private void assertUICallWithCookie(Cookie cookie)
throws IOException
{
OkHttpClient httpClient = httpClientUsingCookie(cookie);
// pass access token in Trino UI cookie
assertThat(httpClient.newCall(uiCall().build())
.execute()
.code())
.isEqualTo(OK.getStatusCode());
}

private static OkHttpClient httpClientUsingCookie(Cookie cookie)
{
OkHttpClient.Builder httpClientBuilder = new OkHttpClient.Builder();
setupInsecureSsl(httpClientBuilder);
Expand All @@ -327,12 +330,7 @@ public List<okhttp3.Cookie> loadForRequest(HttpUrl url)
.build());
}
});

// pass access token in Presto UI cookie
assertThat(httpClientBuilder.build().newCall(uiCall().build())
.execute()
.code())
.isEqualTo(OK.getStatusCode());
return httpClientBuilder.build();
}

private static int findAvailablePort()
Expand Down

0 comments on commit e80712b

Please sign in to comment.