Skip to content

Commit

Permalink
Differentiate service account tokens in GCS tests (#48382)
Browse files Browse the repository at this point in the history
This commit changes the test so that each node use a specific 
service account and private key. It also changes how unique 
request ids are generated for refresh token request using the 
token itself, so that error count will be specific per node (each 
node should execute a single refresh token request as tokens 
are valid for 1 hour).
  • Loading branch information
tlrx authored Oct 23, 2019
1 parent a079516 commit ed667be
Showing 1 changed file with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@
@SuppressForbidden(reason = "this test uses a HttpServer to emulate a Google Cloud Storage endpoint")
public class GoogleCloudStorageBlobStoreRepositoryTests extends ESMockAPIBasedRepositoryIntegTestCase {

private static byte[] serviceAccount;

@Override
protected String repositoryType() {
return GoogleCloudStorageRepository.TYPE;
Expand Down Expand Up @@ -113,16 +111,13 @@ protected HttpHandler createErroneousHttpHandler(final HttpHandler delegate) {

@Override
protected Settings nodeSettings(int nodeOrdinal) {
if (serviceAccount == null) {
serviceAccount = TestUtils.createServiceAccount(random());
}

final Settings.Builder settings = Settings.builder();
settings.put(super.nodeSettings(nodeOrdinal));
settings.put(ENDPOINT_SETTING.getConcreteSettingForNamespace("test").getKey(), httpServerUrl());
settings.put(TOKEN_URI_SETTING.getConcreteSettingForNamespace("test").getKey(), httpServerUrl() + "/token");

final MockSecureSettings secureSettings = new MockSecureSettings();
final byte[] serviceAccount = TestUtils.createServiceAccount(random());
secureSettings.setFile(CREDENTIALS_FILE_SETTING.getConcreteSettingForNamespace("test").getKey(), serviceAccount);
settings.setSecureSettings(secureSettings);
return settings.build();
Expand Down Expand Up @@ -403,6 +398,15 @@ private static class GoogleErroneousHttpHandler extends ErroneousHttpHandler {

@Override
protected String requestUniqueId(HttpExchange exchange) {
if ("/token".equals(exchange.getRequestURI().getPath())) {
try {
// token content is unique per node (not per request)
return Streams.readFully(exchange.getRequestBody()).utf8ToString();
} catch (IOException e) {
throw new AssertionError("Unable to read token request body", e);
}
}

final String range = exchange.getRequestHeaders().getFirst("Content-Range");
return exchange.getRemoteAddress().toString()
+ " " + exchange.getRequestMethod()
Expand Down

0 comments on commit ed667be

Please sign in to comment.