|
55 | 55 | import java.util.stream.Collectors;
|
56 | 56 |
|
57 | 57 | import static org.elasticsearch.test.SecuritySettingsSource.SECURITY_REQUEST_OPTIONS;
|
58 |
| -import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoTimeout; |
59 | 58 | import static org.hamcrest.Matchers.containsString;
|
60 | 59 | import static org.hamcrest.Matchers.equalTo;
|
61 | 60 |
|
@@ -256,19 +255,20 @@ public void testRefreshingToken() throws IOException {
|
256 | 255 | CreateTokenResponse response = restClient.security().createToken(CreateTokenRequest.passwordGrant(
|
257 | 256 | SecuritySettingsSource.TEST_USER_NAME, SecuritySettingsSourceField.TEST_PASSWORD.toCharArray()), SECURITY_REQUEST_OPTIONS);
|
258 | 257 | assertNotNull(response.getRefreshToken());
|
259 |
| - // get cluster health with token |
260 |
| - assertNoTimeout(client() |
261 |
| - .filterWithHeader(Collections.singletonMap("Authorization", "Bearer " + response.getAccessToken())) |
262 |
| - .admin().cluster().prepareHealth().get()); |
263 |
| - |
| 258 | + // Assert that we can authenticate with the access token |
| 259 | + AuthenticateResponse authResponse = restClient.security().authenticate(RequestOptions.DEFAULT.toBuilder().addHeader("Authorization", |
| 260 | + "Bearer " + response.getAccessToken()).build()); |
| 261 | + assertThat(authResponse.getUser().getUsername(), equalTo(SecuritySettingsSource.TEST_USER_NAME)); |
264 | 262 | CreateTokenResponse refreshResponse = restClient.security()
|
265 | 263 | .createToken(CreateTokenRequest.refreshTokenGrant(response.getRefreshToken()), SECURITY_REQUEST_OPTIONS);
|
266 | 264 | assertNotNull(refreshResponse.getRefreshToken());
|
267 | 265 | assertNotEquals(refreshResponse.getRefreshToken(), response.getRefreshToken());
|
268 | 266 | assertNotEquals(refreshResponse.getAccessToken(), response.getAccessToken());
|
269 | 267 |
|
270 |
| - assertNoTimeout(client().filterWithHeader(Collections.singletonMap("Authorization", "Bearer " + refreshResponse.getAccessToken())) |
271 |
| - .admin().cluster().prepareHealth().get()); |
| 268 | + // Assert that we can authenticate with the refreshed access token |
| 269 | + authResponse = restClient.security().authenticate(RequestOptions.DEFAULT.toBuilder().addHeader("Authorization", |
| 270 | + "Bearer " + refreshResponse.getAccessToken()).build()); |
| 271 | + assertThat(authResponse.getUser().getUsername(), equalTo(SecuritySettingsSource.TEST_USER_NAME)); |
272 | 272 | }
|
273 | 273 |
|
274 | 274 | public void testRefreshingInvalidatedToken() throws IOException {
|
@@ -466,10 +466,10 @@ public void testAuthenticateWithWrongToken() throws Exception {
|
466 | 466 | CreateTokenResponse response = restClient.security().createToken(CreateTokenRequest.passwordGrant(
|
467 | 467 | SecuritySettingsSource.TEST_USER_NAME, SecuritySettingsSourceField.TEST_PASSWORD.toCharArray()), SECURITY_REQUEST_OPTIONS);
|
468 | 468 | assertNotNull(response.getRefreshToken());
|
469 |
| - // First check that the correct access token works by getting cluster health with token |
470 |
| - assertNoTimeout(client() |
471 |
| - .filterWithHeader(Collections.singletonMap("Authorization", "Bearer " + response.getAccessToken())) |
472 |
| - .admin().cluster().prepareHealth().get()); |
| 469 | + // Assert that we can authenticate with the access token |
| 470 | + AuthenticateResponse authResponse = restClient.security().authenticate(RequestOptions.DEFAULT.toBuilder().addHeader("Authorization", |
| 471 | + "Bearer " + response.getAccessToken()).build()); |
| 472 | + assertThat(authResponse.getUser().getUsername(), equalTo(SecuritySettingsSource.TEST_USER_NAME)); |
473 | 473 | // Now attempt to authenticate with an invalid access token string
|
474 | 474 | RequestOptions wrongAuthOptions =
|
475 | 475 | RequestOptions.DEFAULT.toBuilder().addHeader("Authorization", "Bearer " + randomAlphaOfLengthBetween(0, 128)).build();
|
|
0 commit comments