Skip to content

Commit

Permalink
Fix TokenBackwardsCompatibilityIT
Browse files Browse the repository at this point in the history
  • Loading branch information
jkakavas committed Dec 7, 2018
1 parent ff242e8 commit 8d1496b
Showing 1 changed file with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void testGeneratingTokenInOldCluster() throws Exception {
}
}

Request createTokenRequest = new Request("POST", "/_security/oauth2/token");
Request createTokenRequest = new Request("POST", "/_xpack/security/oauth2/token");
createTokenRequest.setJsonEntity(
"{\n" +
" \"username\": \"test_user\",\n" +
Expand All @@ -61,7 +61,7 @@ public void testGeneratingTokenInOldCluster() throws Exception {
Map<String, Object> responseMap = entityAsMap(response);
String token = (String) responseMap.get("access_token");
assertNotNull(token);
assertTokenWorks(token);
assertTokenWorks(token, true);

Request indexRequest1 = new Request("PUT", "token_backwards_compatibility_it/doc/old_cluster_token1");
indexRequest1.setJsonEntity(
Expand All @@ -70,13 +70,13 @@ public void testGeneratingTokenInOldCluster() throws Exception {
"}");
client().performRequest(indexRequest1);

Request createSecondTokenRequest = new Request("POST", "/_security/oauth2/token");
Request createSecondTokenRequest = new Request("POST", "/_xpack/security/oauth2/token");
createSecondTokenRequest.setEntity(createTokenRequest.getEntity());
response = client().performRequest(createSecondTokenRequest);
responseMap = entityAsMap(response);
token = (String) responseMap.get("access_token");
assertNotNull(token);
assertTokenWorks(token);
assertTokenWorks(token, true);
Request indexRequest2 = new Request("PUT", "token_backwards_compatibility_it/doc/old_cluster_token2");
indexRequest2.setJsonEntity(
"{\n" +
Expand All @@ -91,7 +91,7 @@ public void testTokenWorksInMixedOrUpgradedCluster() throws Exception {
Response getResponse = client().performRequest(new Request("GET", "token_backwards_compatibility_it/doc/old_cluster_token1"));
assertOK(getResponse);
Map<String, Object> source = (Map<String, Object>) entityAsMap(getResponse).get("_source");
assertTokenWorks((String) source.get("token"));
assertTokenWorks((String) source.get("token"), false);
}

public void testMixedCluster() throws Exception {
Expand All @@ -109,7 +109,7 @@ public void testMixedCluster() throws Exception {
assertTokenDoesNotWork(token);

// create token and refresh on version that supports it
Request createTokenRequest = new Request("POST", "/_/security/oauth2/token");
Request createTokenRequest = new Request("POST", "/_security/oauth2/token");
createTokenRequest.setJsonEntity(
"{\n" +
" \"username\": \"test_user\",\n" +
Expand Down Expand Up @@ -198,7 +198,12 @@ public void testUpgradedCluster() throws Exception {
}

private void assertTokenWorks(String token) throws IOException {
Request request = new Request("GET", "/_security/_authenticate");
assertTokenWorks(token, false);
}

private void assertTokenWorks(String token, boolean oldCluster) throws IOException {
Request request = oldCluster ? new Request("GET", "/_xpack/security/_authenticate") :
new Request("GET", "/_security/_authenticate");
RequestOptions.Builder options = request.getOptions().toBuilder();
options.addHeader(HttpHeaders.AUTHORIZATION, "Bearer " + token);
request.setOptions(options);
Expand Down

0 comments on commit 8d1496b

Please sign in to comment.