Skip to content

Commit e1dd0e7

Browse files
committed
Differentiate service account tokens in GCS tests (#48382)
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).
1 parent 852622d commit e1dd0e7

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

plugins/repository-gcs/src/test/java/org/elasticsearch/repositories/gcs/GoogleCloudStorageBlobStoreRepositoryTests.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,6 @@
7878
@SuppressForbidden(reason = "this test uses a HttpServer to emulate a Google Cloud Storage endpoint")
7979
public class GoogleCloudStorageBlobStoreRepositoryTests extends ESMockAPIBasedRepositoryIntegTestCase {
8080

81-
private static byte[] serviceAccount;
82-
8381
@Override
8482
protected String repositoryType() {
8583
return GoogleCloudStorageRepository.TYPE;
@@ -114,16 +112,13 @@ protected HttpHandler createErroneousHttpHandler(final HttpHandler delegate) {
114112

115113
@Override
116114
protected Settings nodeSettings(int nodeOrdinal) {
117-
if (serviceAccount == null) {
118-
serviceAccount = TestUtils.createServiceAccount(random());
119-
}
120-
121115
final Settings.Builder settings = Settings.builder();
122116
settings.put(super.nodeSettings(nodeOrdinal));
123117
settings.put(ENDPOINT_SETTING.getConcreteSettingForNamespace("test").getKey(), httpServerUrl());
124118
settings.put(TOKEN_URI_SETTING.getConcreteSettingForNamespace("test").getKey(), httpServerUrl() + "/token");
125119

126120
final MockSecureSettings secureSettings = new MockSecureSettings();
121+
final byte[] serviceAccount = TestUtils.createServiceAccount(random());
127122
secureSettings.setFile(CREDENTIALS_FILE_SETTING.getConcreteSettingForNamespace("test").getKey(), serviceAccount);
128123
settings.setSecureSettings(secureSettings);
129124
return settings.build();
@@ -410,6 +405,15 @@ private static class GoogleErroneousHttpHandler extends ErroneousHttpHandler {
410405

411406
@Override
412407
protected String requestUniqueId(HttpExchange exchange) {
408+
if ("/token".equals(exchange.getRequestURI().getPath())) {
409+
try {
410+
// token content is unique per node (not per request)
411+
return Streams.readFully(exchange.getRequestBody()).utf8ToString();
412+
} catch (IOException e) {
413+
throw new AssertionError("Unable to read token request body", e);
414+
}
415+
}
416+
413417
final String range = exchange.getRequestHeaders().getFirst("Content-Range");
414418
return exchange.getRemoteAddress().toString()
415419
+ " " + exchange.getRequestMethod()

0 commit comments

Comments
 (0)