Skip to content

Commit 5bc13cf

Browse files
Remove ANY_REGION
1 parent 5aed2eb commit 5bc13cf

File tree

9 files changed

+44
-25
lines changed

9 files changed

+44
-25
lines changed

modules/repository-s3/src/javaRestTest/java/org/elasticsearch/repositories/s3/RepositoryS3RestReloadCredentialsIT.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
package org.elasticsearch.repositories.s3;
1111

12+
import fixture.aws.DynamicRegionSupplier;
1213
import fixture.s3.S3HttpFixture;
1314

1415
import org.elasticsearch.client.Request;
@@ -24,8 +25,8 @@
2425
import org.junit.rules.TestRule;
2526

2627
import java.io.IOException;
28+
import java.util.function.Supplier;
2729

28-
import static fixture.aws.AwsCredentialsUtils.ANY_REGION;
2930
import static fixture.aws.AwsCredentialsUtils.mutableAccessKey;
3031
import static org.hamcrest.CoreMatchers.containsString;
3132
import static org.hamcrest.Matchers.allOf;
@@ -39,17 +40,19 @@ public class RepositoryS3RestReloadCredentialsIT extends ESRestTestCase {
3940

4041
private static volatile String repositoryAccessKey;
4142

43+
private static final Supplier<String> regionSupplier = new DynamicRegionSupplier();
4244
public static final S3HttpFixture s3Fixture = new S3HttpFixture(
4345
true,
4446
BUCKET,
4547
BASE_PATH,
46-
mutableAccessKey(() -> repositoryAccessKey, ANY_REGION, "s3")
48+
mutableAccessKey(() -> repositoryAccessKey, regionSupplier, "s3")
4749
);
4850

4951
private static final MutableSettingsProvider keystoreSettings = new MutableSettingsProvider();
5052

5153
public static ElasticsearchCluster cluster = ElasticsearchCluster.local()
5254
.module("repository-s3")
55+
.systemProperty("aws.region", regionSupplier)
5356
.keystore(keystoreSettings)
5457
.setting("s3.client.default.endpoint", s3Fixture::getAddress)
5558
.build();

modules/repository-s3/src/javaRestTest/java/org/elasticsearch/repositories/s3/RepositoryS3SessionCredentialsRestIT.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
package org.elasticsearch.repositories.s3;
1111

12+
import fixture.aws.DynamicRegionSupplier;
1213
import fixture.s3.S3HttpFixture;
1314

1415
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakFilters;
@@ -20,7 +21,8 @@
2021
import org.junit.rules.RuleChain;
2122
import org.junit.rules.TestRule;
2223

23-
import static fixture.aws.AwsCredentialsUtils.ANY_REGION;
24+
import java.util.function.Supplier;
25+
2426
import static fixture.aws.AwsCredentialsUtils.fixedAccessKeyAndToken;
2527

2628
@ThreadLeakFilters(filters = { TestContainersThreadFilter.class })
@@ -35,15 +37,17 @@ public class RepositoryS3SessionCredentialsRestIT extends AbstractRepositoryS3Re
3537
private static final String SESSION_TOKEN = PREFIX + "session-token";
3638
private static final String CLIENT = "session_credentials_client";
3739

40+
private static final Supplier<String> regionSupplier = new DynamicRegionSupplier();
3841
private static final S3HttpFixture s3Fixture = new S3HttpFixture(
3942
true,
4043
BUCKET,
4144
BASE_PATH,
42-
fixedAccessKeyAndToken(ACCESS_KEY, SESSION_TOKEN, ANY_REGION, "s3")
45+
fixedAccessKeyAndToken(ACCESS_KEY, SESSION_TOKEN, regionSupplier, "s3")
4346
);
4447

4548
public static ElasticsearchCluster cluster = ElasticsearchCluster.local()
4649
.module("repository-s3")
50+
.systemProperty("aws.region", regionSupplier)
4751
.keystore("s3.client." + CLIENT + ".access_key", ACCESS_KEY)
4852
.keystore("s3.client." + CLIENT + ".secret_key", SECRET_KEY)
4953
.keystore("s3.client." + CLIENT + ".session_token", SESSION_TOKEN)

modules/repository-s3/src/yamlRestTest/java/org/elasticsearch/repositories/s3/RepositoryS3ClientYamlTestSuiteIT.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
package org.elasticsearch.repositories.s3;
1111

12+
import fixture.aws.DynamicRegionSupplier;
1213
import fixture.s3.S3HttpFixture;
1314

1415
import com.carrotsearch.randomizedtesting.annotations.Name;
@@ -23,7 +24,8 @@
2324
import org.junit.rules.RuleChain;
2425
import org.junit.rules.TestRule;
2526

26-
import static fixture.aws.AwsCredentialsUtils.ANY_REGION;
27+
import java.util.function.Supplier;
28+
2729
import static fixture.aws.AwsCredentialsUtils.fixedAccessKey;
2830

2931
@ThreadLeakFilters(filters = { TestContainersThreadFilter.class })
@@ -33,15 +35,17 @@ public class RepositoryS3ClientYamlTestSuiteIT extends AbstractRepositoryS3Clien
3335
private static final String ACCESS_KEY = "RepositoryS3ClientYamlTestSuiteIT-access-key";
3436
private static final String SECRET_KEY = "RepositoryS3ClientYamlTestSuiteIT-secret-key";
3537

38+
private static final Supplier<String> regionSupplier = new DynamicRegionSupplier();
3639
private static final S3HttpFixture s3Fixture = new S3HttpFixture(
3740
true,
3841
"bucket",
3942
"base_path_integration_tests",
40-
fixedAccessKey(ACCESS_KEY, ANY_REGION, "s3")
43+
fixedAccessKey(ACCESS_KEY, regionSupplier, "s3")
4144
);
4245

4346
public static ElasticsearchCluster cluster = ElasticsearchCluster.local()
4447
.module("repository-s3")
48+
.systemProperty("aws.region", regionSupplier)
4549
.keystore("s3.client.integration_test_permanent.access_key", ACCESS_KEY)
4650
.keystore("s3.client.integration_test_permanent.secret_key", SECRET_KEY)
4751
.setting("s3.client.integration_test_permanent.endpoint", s3Fixture::getAddress)

test/fixtures/aws-fixture-utils/src/main/java/fixture/aws/AwsCredentialsUtils.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,6 @@
2323
public enum AwsCredentialsUtils {
2424
;
2525

26-
/**
27-
* Region supplier which matches any region.
28-
*/
29-
// TODO NOMERGE: replace with DynamicRegionSupplier.
30-
public static final Supplier<String> ANY_REGION = () -> "*";
31-
3226
/**
3327
* @return an authorization predicate that ensures the authorization header matches the given access key, region and service name.
3428
* @see <a href="https://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-auth-using-authorization-header.html">AWS v4 Signatures</a>
@@ -72,11 +66,6 @@ public static boolean isValidAwsV4SignedAuthorizationHeader(
7266
return false;
7367
}
7468

75-
if (region.equals("*")) {
76-
// skip region validation; TODO NOMERGE eliminate this when region is fixed in all tests
77-
return authorizationHeader.contains("/" + serviceName + "/aws4_request, ");
78-
}
79-
8069
final var remainder = authorizationHeader.substring(expectedPrefix.length() + "YYYYMMDD".length() /* skip over date field */);
8170
return remainder.startsWith("/" + region + "/" + serviceName + "/aws4_request, ");
8271
}

test/fixtures/s3-fixture/src/main/java/fixture/s3/S3HttpFixture.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
import java.util.concurrent.ExecutorService;
2727
import java.util.concurrent.TimeUnit;
2828
import java.util.function.BiPredicate;
29+
import java.util.function.Supplier;
2930

30-
import static fixture.aws.AwsCredentialsUtils.ANY_REGION;
3131
import static fixture.aws.AwsCredentialsUtils.checkAuthorization;
3232
import static fixture.aws.AwsCredentialsUtils.fixedAccessKey;
3333
import static fixture.aws.AwsFixtureUtils.getLocalFixtureAddress;
@@ -44,8 +44,8 @@ public class S3HttpFixture extends ExternalResource {
4444
private final String basePath;
4545
private final BiPredicate<String, String> authorizationPredicate;
4646

47-
public S3HttpFixture(boolean enabled) {
48-
this(enabled, "bucket", "base_path_integration_tests", fixedAccessKey("s3_test_access_key", ANY_REGION, "s3"));
47+
public S3HttpFixture(boolean enabled, Supplier<String> regionSupplier) {
48+
this(enabled, "bucket", "base_path_integration_tests", fixedAccessKey("s3_test_access_key", regionSupplier, "s3"));
4949
}
5050

5151
public S3HttpFixture(boolean enabled, String bucket, String basePath, BiPredicate<String, String> authorizationPredicate) {

x-pack/plugin/repositories-metering-api/qa/s3/src/javaRestTest/java/org/elasticsearch/xpack/repositories/metering/s3/S3RepositoriesMeteringIT.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import fixture.s3.S3HttpFixture;
1010

1111
import org.elasticsearch.common.settings.Settings;
12+
import org.elasticsearch.common.util.LazyInitializable;
13+
import org.elasticsearch.test.ESTestCase;
1214
import org.elasticsearch.test.cluster.ElasticsearchCluster;
1315
import org.elasticsearch.test.cluster.local.distribution.DistributionType;
1416
import org.elasticsearch.xpack.repositories.metering.AbstractRepositoriesMeteringAPIRestTestCase;
@@ -18,15 +20,18 @@
1820

1921
import java.util.List;
2022
import java.util.Map;
23+
import java.util.function.Supplier;
2124

2225
public class S3RepositoriesMeteringIT extends AbstractRepositoriesMeteringAPIRestTestCase {
2326

2427
static final boolean USE_FIXTURE = Boolean.parseBoolean(System.getProperty("tests.use.fixture", "true"));
2528

26-
public static final S3HttpFixture s3Fixture = new S3HttpFixture(USE_FIXTURE);
29+
private static final Supplier<String> regionSupplier = new LazyInitializable<>(ESTestCase::randomIdentifier)::getOrCompute;
30+
public static final S3HttpFixture s3Fixture = new S3HttpFixture(USE_FIXTURE, regionSupplier);
2731

2832
public static ElasticsearchCluster cluster = ElasticsearchCluster.local()
2933
.distribution(DistributionType.DEFAULT)
34+
.systemProperty("aws.region", regionSupplier)
3035
.keystore("s3.client.repositories_metering.access_key", System.getProperty("s3AccessKey"))
3136
.keystore("s3.client.repositories_metering.secret_key", System.getProperty("s3SecretKey"))
3237
.setting("xpack.license.self_generated.type", "trial")

x-pack/plugin/searchable-snapshots/qa/s3/src/javaRestTest/java/org/elasticsearch/xpack/searchablesnapshots/s3/S3SearchableSnapshotsCredentialsReloadIT.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
package org.elasticsearch.xpack.searchablesnapshots.s3;
99

10+
import fixture.aws.DynamicRegionSupplier;
1011
import fixture.s3.S3HttpFixture;
1112
import io.netty.handler.codec.http.HttpMethod;
1213

@@ -33,9 +34,9 @@
3334

3435
import java.io.ByteArrayOutputStream;
3536
import java.io.IOException;
37+
import java.util.function.Supplier;
3638
import java.util.function.UnaryOperator;
3739

38-
import static fixture.aws.AwsCredentialsUtils.ANY_REGION;
3940
import static fixture.aws.AwsCredentialsUtils.mutableAccessKey;
4041
import static org.hamcrest.CoreMatchers.containsString;
4142
import static org.hamcrest.Matchers.allOf;
@@ -47,18 +48,20 @@ public class S3SearchableSnapshotsCredentialsReloadIT extends ESRestTestCase {
4748

4849
private static volatile String repositoryAccessKey;
4950

51+
private static final Supplier<String> regionSupplier = new DynamicRegionSupplier();
5052
public static final S3HttpFixture s3Fixture = new S3HttpFixture(
5153
true,
5254
BUCKET,
5355
BASE_PATH,
54-
mutableAccessKey(() -> repositoryAccessKey, ANY_REGION, "s3")
56+
mutableAccessKey(() -> repositoryAccessKey, regionSupplier, "s3")
5557
);
5658

5759
private static final MutableSettingsProvider keystoreSettings = new MutableSettingsProvider();
5860

5961
public static ElasticsearchCluster cluster = ElasticsearchCluster.local()
6062
.distribution(DistributionType.DEFAULT)
6163
.setting("xpack.license.self_generated.type", "trial")
64+
.systemProperty("aws.region", regionSupplier)
6265
.keystore(keystoreSettings)
6366
.setting("xpack.searchable.snapshot.shared_cache.size", "4kB")
6467
.setting("xpack.searchable.snapshot.shared_cache.region_size", "4kB")

x-pack/plugin/searchable-snapshots/qa/s3/src/javaRestTest/java/org/elasticsearch/xpack/searchablesnapshots/s3/S3SearchableSnapshotsIT.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77
package org.elasticsearch.xpack.searchablesnapshots.s3;
88

9+
import fixture.aws.DynamicRegionSupplier;
910
import fixture.s3.S3HttpFixture;
1011

1112
import org.elasticsearch.common.settings.Settings;
@@ -16,16 +17,20 @@
1617
import org.junit.rules.RuleChain;
1718
import org.junit.rules.TestRule;
1819

20+
import java.util.function.Supplier;
21+
1922
import static org.hamcrest.Matchers.blankOrNullString;
2023
import static org.hamcrest.Matchers.not;
2124

2225
public class S3SearchableSnapshotsIT extends AbstractSearchableSnapshotsRestTestCase {
2326
static final boolean USE_FIXTURE = Boolean.parseBoolean(System.getProperty("tests.use.fixture", "true"));
2427

25-
public static final S3HttpFixture s3Fixture = new S3HttpFixture(USE_FIXTURE);
28+
private static final Supplier<String> regionSupplier = new DynamicRegionSupplier();
29+
public static final S3HttpFixture s3Fixture = new S3HttpFixture(USE_FIXTURE, regionSupplier);
2630

2731
public static ElasticsearchCluster cluster = ElasticsearchCluster.local()
2832
.distribution(DistributionType.DEFAULT)
33+
.systemProperty("aws.region", regionSupplier)
2934
.keystore("s3.client.searchable_snapshots.access_key", System.getProperty("s3AccessKey"))
3035
.keystore("s3.client.searchable_snapshots.secret_key", System.getProperty("s3SecretKey"))
3136
.setting("xpack.license.self_generated.type", "trial")

x-pack/plugin/snapshot-based-recoveries/qa/s3/src/javaRestTest/java/org/elasticsearch/xpack/snapshotbasedrecoveries/recovery/S3SnapshotBasedRecoveryIT.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,30 @@
1010
import fixture.s3.S3HttpFixture;
1111

1212
import org.elasticsearch.common.settings.Settings;
13+
import org.elasticsearch.common.util.LazyInitializable;
14+
import org.elasticsearch.test.ESTestCase;
1315
import org.elasticsearch.test.cluster.ElasticsearchCluster;
1416
import org.elasticsearch.test.cluster.local.distribution.DistributionType;
1517
import org.junit.ClassRule;
1618
import org.junit.rules.RuleChain;
1719
import org.junit.rules.TestRule;
1820

21+
import java.util.function.Supplier;
22+
1923
import static org.hamcrest.Matchers.blankOrNullString;
2024
import static org.hamcrest.Matchers.not;
2125

2226
public class S3SnapshotBasedRecoveryIT extends AbstractSnapshotBasedRecoveryRestTestCase {
2327

2428
static final boolean USE_FIXTURE = Boolean.parseBoolean(System.getProperty("tests.use.fixture", "true"));
2529

26-
public static final S3HttpFixture s3Fixture = new S3HttpFixture(USE_FIXTURE);
30+
private static final Supplier<String> regionSupplier = new LazyInitializable<>(ESTestCase::randomIdentifier)::getOrCompute;
31+
public static final S3HttpFixture s3Fixture = new S3HttpFixture(USE_FIXTURE, regionSupplier);
2732

2833
public static ElasticsearchCluster cluster = ElasticsearchCluster.local()
2934
.distribution(DistributionType.DEFAULT)
3035
.nodes(3)
36+
.systemProperty("aws.region", regionSupplier)
3137
.keystore("s3.client.snapshot_based_recoveries.access_key", System.getProperty("s3AccessKey"))
3238
.keystore("s3.client.snapshot_based_recoveries.secret_key", System.getProperty("s3SecretKey"))
3339
.setting("xpack.license.self_generated.type", "trial")

0 commit comments

Comments
 (0)