mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(s3): apply AWS's CreateBucket region rules in every partition (#4494)
* fix(s3): apply AWS's CreateBucket region rules in every partition CreateBucket follows the rules moto verified against AWS: the us-east-1 endpoint takes any LocationConstraint but its own (InvalidLocationConstraint), and every other regional endpoint requires a constraint naming exactly its region, answering IllegalLocationConstraintException otherwise. The signing region alone no longer places a bucket, so a China or GovCloud client must send the constraint, which the AWS SDKs do. GetBucketLocation still answers an empty constraint only for us-east-1, in every partition. WAF's CLOUDFRONT scope lives in the partition's implicit global region and is refused with WAFInvalidParameterException where the partition has no CloudFront. Lightsail lists no regions outside the commercial partition. Region fallbacks read the configured default where a resolver or config is in scope, and PreSignedUrlGenerator gains an overload that signs for a given region. The region-literal category of the partition guardrail is now gated; every remaining literal carries a stated reason. Tests that created buckets under a regional signing scope with no constraint now send one, and S3IntegrationTest's case that pinned the old signing-region placement is replaced by the rejection and its positive twin. Part of #4272 * fix(s3,wafv2): answer a us-east-1 constraint off its endpoint as a mismatch, and gate the CLOUDFRONT scope on every operation A CreateBucket on a regional endpoint other than us-east-1 with LocationConstraint us-east-1 is just another mismatched region, IllegalLocationConstraintException, as moto's aws_verified test_create_bucket_with_wrong_location_constraint records; InvalidLocationConstraint belongs to the us-east-1 endpoint alone (test_bucket_create_force_us_east_1). The body parse no longer rejects us-east-1 early, and bucketRegionForCreate checks the endpoint mismatch first. WAF's CLOUDFRONT scope was refused in partitions without CloudFront only when creating a resource; validateScope, which every operation already calls, now applies the same check, so a List or Get for that scope answers the same WAFInvalidParameterException. * fix(wafv2): check the CLOUDFRONT scope against the region each call is about The previous change checked the scope in validateScope against the request region, but CloudFormation calls the service outside any request, where that region falls back to the deployment default: under a GovCloud default a commercial stack's CLOUDFRONT WebACL was refused on create, update and delete. WafV2Handler now checks Scope=CLOUDFRONT against the region the API request was sent to, before dispatch, so every operation still answers the same error; validateScope checks the enum only, and a create keeps its check against the region it is given where the ARN is built.
This commit is contained in:
1 parent
1b176bda0d
commit
0cfb467cac
60 files changed
+534
-116
No files matched your search
+101
@@ -0,0 +1,101 @@
|
||||
package io.github.hectorvent.floci.core.common;
|
||||
|
||||
import io.github.hectorvent.floci.testing.PartitionCleanup;
|
||||
import io.github.hectorvent.floci.testing.PartitionMatrix;
|
||||
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.response.Response;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* Behaviour that AWS gates on the partition rather than on a literal region: a WAF CLOUDFRONT
|
||||
* scope exists only where CloudFront does and lives in the partition's implicit global region,
|
||||
* and Lightsail exists only in the commercial partition.
|
||||
*/
|
||||
@QuarkusTest
|
||||
class PartitionRegionGatesIntegrationTest {
|
||||
|
||||
private static final String JSON_1_1 = "application/x-amz-json-1.1";
|
||||
|
||||
@RegisterExtension
|
||||
final PartitionCleanup cleanup = new PartitionCleanup();
|
||||
|
||||
@BeforeAll
|
||||
static void configureRestAssured() {
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
}
|
||||
|
||||
private static Response createIpSet(String region, String name) {
|
||||
return given()
|
||||
.header("Authorization", PartitionMatrix.sigV4Auth(region, "wafv2"))
|
||||
.header("X-Amz-Target", "AWSWAF_20190729.CreateIPSet")
|
||||
.contentType(JSON_1_1)
|
||||
.body("{\"Name\":\"" + name + "\",\"Scope\":\"CLOUDFRONT\",\"IPAddressVersion\":\"IPV4\",\"Addresses\":[\"10.0.0.0/8\"]}")
|
||||
.when().post("/");
|
||||
}
|
||||
|
||||
@Test
|
||||
void cloudFrontScopeIsRejectedWhereThePartitionHasNoCloudFront() {
|
||||
createIpSet("us-gov-west-1", "gov-" + Long.toString(System.nanoTime(), 36)).then().statusCode(400)
|
||||
.body("__type", containsString("WAFInvalidParameterException"))
|
||||
.body("Reason", containsString("aws-us-gov"));
|
||||
}
|
||||
|
||||
/** The scope is unavailable for every operation in such a partition, not only for creates. */
|
||||
@Test
|
||||
void cloudFrontScopeListsAreRejectedWhereThePartitionHasNoCloudFront() {
|
||||
for (String action : new String[] {"ListIPSets", "ListWebACLs"}) {
|
||||
given()
|
||||
.header("Authorization", PartitionMatrix.sigV4Auth("us-gov-west-1", "wafv2"))
|
||||
.header("X-Amz-Target", "AWSWAF_20190729." + action)
|
||||
.contentType(JSON_1_1)
|
||||
.body("{\"Scope\":\"CLOUDFRONT\"}")
|
||||
.when().post("/")
|
||||
.then().statusCode(400)
|
||||
.body("__type", containsString("WAFInvalidParameterException"))
|
||||
.body("Reason", containsString("aws-us-gov"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void cloudFrontScopeLivesInThePartitionsImplicitGlobalRegion() {
|
||||
String name = "cn-" + Long.toString(System.nanoTime(), 36);
|
||||
Response created = createIpSet("cn-north-1", name);
|
||||
created.then().statusCode(200);
|
||||
String arn = created.jsonPath().getString("Summary.ARN");
|
||||
String id = created.jsonPath().getString("Summary.Id");
|
||||
String lockToken = created.jsonPath().getString("Summary.LockToken");
|
||||
cleanup.register(() -> given()
|
||||
.header("Authorization", PartitionMatrix.sigV4Auth("cn-north-1", "wafv2"))
|
||||
.header("X-Amz-Target", "AWSWAF_20190729.DeleteIPSet")
|
||||
.contentType(JSON_1_1)
|
||||
.body("{\"Name\":\"" + name + "\",\"Scope\":\"CLOUDFRONT\",\"Id\":\"" + id + "\",\"LockToken\":\"" + lockToken + "\"}")
|
||||
.when().post("/"));
|
||||
assertTrue(arn.startsWith("arn:aws-cn:wafv2:cn-northwest-1:000000000000:global/ipset/" + name + "/"), arn);
|
||||
}
|
||||
|
||||
@Test
|
||||
void lightsailRegionsAreEmptyOutsideTheCommercialPartition() {
|
||||
given()
|
||||
.header("Authorization", PartitionMatrix.sigV4Auth("cn-north-1", "lightsail"))
|
||||
.header("X-Amz-Target", "Lightsail_20161128.GetRegions")
|
||||
.contentType(JSON_1_1)
|
||||
.body("{}")
|
||||
.when().post("/").then().statusCode(200)
|
||||
.body("regions", hasSize(0));
|
||||
given()
|
||||
.header("Authorization", PartitionMatrix.sigV4Auth("us-east-1", "lightsail"))
|
||||
.header("X-Amz-Target", "Lightsail_20161128.GetRegions")
|
||||
.contentType(JSON_1_1)
|
||||
.body("{}")
|
||||
.when().post("/").then().statusCode(200)
|
||||
.body("regions", hasSize(4));
|
||||
}
|
||||
}
|
||||
+6
-2
@@ -34,6 +34,9 @@ class CloudFormationDeletionPolicyIntegrationTest {
|
||||
|
||||
private static final String CUSTOM_AUTH =
|
||||
"AWS4-HMAC-SHA256 Credential=111122223333/20260205/eu-west-1/cloudformation/aws4_request";
|
||||
/** CUSTOM_AUTH signs for eu-west-1, whose S3 endpoint requires a matching LocationConstraint, as on AWS. */
|
||||
private static final String EU_WEST_1_BUCKET =
|
||||
"<CreateBucketConfiguration><LocationConstraint>eu-west-1</LocationConstraint></CreateBucketConfiguration>";
|
||||
|
||||
@Test
|
||||
void deletingNestedStacksDoesNotExhaustOperationWorkers() throws InterruptedException {
|
||||
@@ -336,7 +339,8 @@ class CloudFormationDeletionPolicyIntegrationTest {
|
||||
|
||||
@Test
|
||||
void nestedStackIsPhysicallyDeletedWhenRemovedFromTemplateOnUpdate() throws InterruptedException {
|
||||
given().header("Authorization", CUSTOM_AUTH).when().put("/nested-stack-templates").then().statusCode(200);
|
||||
given().header("Authorization", CUSTOM_AUTH).contentType("application/xml").body(EU_WEST_1_BUCKET)
|
||||
.when().put("/nested-stack-templates").then().statusCode(200);
|
||||
String childTemplate = "{\"Resources\": {\"Queue\": {\"Type\": \"AWS::SQS::Queue\"}}}";
|
||||
given()
|
||||
.header("Authorization", CUSTOM_AUTH)
|
||||
@@ -436,7 +440,7 @@ class CloudFormationDeletionPolicyIntegrationTest {
|
||||
""".formatted(templateUrl);
|
||||
String stackName = "parent-nested-lambda-update-" + suffix;
|
||||
|
||||
given().header("Authorization", CUSTOM_AUTH)
|
||||
given().header("Authorization", CUSTOM_AUTH).contentType("application/xml").body(EU_WEST_1_BUCKET)
|
||||
.when().put("/" + bucketName).then().statusCode(200);
|
||||
given().header("Authorization", CUSTOM_AUTH)
|
||||
.contentType("application/json").body(nestedLambdaTemplate(functionName, 3))
|
||||
|
||||
+10
-3
@@ -7,6 +7,7 @@ import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.github.hectorvent.floci.testutil.S3RequestSigner;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.response.Response;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import jakarta.inject.Inject;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -88,7 +89,7 @@ class CloudTrailSelfDeliveryTest {
|
||||
String trailName = "loop-trail-" + suffix;
|
||||
S3RequestSigner s3 = S3RequestSigner.signedAs("test", "test").inRegion(region);
|
||||
|
||||
createBucket(bucket, s3);
|
||||
createBucket(bucket, region, s3);
|
||||
// Runs last: the emulator is shared, and a leftover bucket shows up in every later
|
||||
// cross-region listing (ResourceExplorer scans all resources).
|
||||
cleanup.register(() -> deleteBucketAndObjects(bucket, s3));
|
||||
@@ -163,8 +164,14 @@ class CloudTrailSelfDeliveryTest {
|
||||
.when().post("/");
|
||||
}
|
||||
|
||||
private static void createBucket(String name, S3RequestSigner signer) {
|
||||
given().filter(signer).when().put("/" + name).then().statusCode(200);
|
||||
/** A regional endpoint other than us-east-1 requires a LocationConstraint naming its region, as on AWS. */
|
||||
private static void createBucket(String name, String region, S3RequestSigner signer) {
|
||||
RequestSpecification request = given().filter(signer);
|
||||
if (!"us-east-1".equals(region)) {
|
||||
request = request.contentType("application/xml").body("<CreateBucketConfiguration><LocationConstraint>"
|
||||
+ region + "</LocationConstraint></CreateBucketConfiguration>");
|
||||
}
|
||||
request.when().put("/" + name).then().statusCode(200);
|
||||
}
|
||||
|
||||
private static void putObject(String bucket, String key, String body, S3RequestSigner signer) {
|
||||
|
||||
+1
@@ -72,6 +72,7 @@ class RedshiftContainerManagerTest {
|
||||
when(lifecycleManager.getDockerClient()).thenReturn(dockerClient);
|
||||
when(config.services().redshift().imageVersion()).thenReturn("postgres:16-alpine");
|
||||
when(config.services().redshift().dockerNetwork()).thenReturn(Optional.empty());
|
||||
when(config.defaultRegion()).thenReturn("us-east-1");
|
||||
|
||||
// Default mock for execCreateCmd/execStartCmd/inspectExecCmd to make waitForReady succeed instantly
|
||||
ExecCreateCmd defaultCreateCmd = mock(ExecCreateCmd.class, org.mockito.Mockito.RETURNS_SELF);
|
||||
|
||||
@@ -441,14 +441,30 @@ class S3IntegrationTest {
|
||||
.statusCode(204);
|
||||
}
|
||||
|
||||
/**
|
||||
* A regional endpoint requires a LocationConstraint naming its region (moto's
|
||||
* {@code aws_verified} matrix); only the us-east-1 endpoint accepts an empty body. The
|
||||
* signing region alone never places a bucket.
|
||||
*/
|
||||
@Test
|
||||
@Order(21)
|
||||
void createBucketUsesSigningRegionWhenBodyEmpty() {
|
||||
void createBucketWithoutConstraintOnARegionalEndpointIsRejected() {
|
||||
String bucket = "signed-region-bucket";
|
||||
String regionalAuth =
|
||||
"AWS4-HMAC-SHA256 Credential=test/20260325/eu-west-1/s3/aws4_request, SignedHeaders=host;x-amz-date, Signature=test";
|
||||
|
||||
given()
|
||||
.header("Authorization",
|
||||
"AWS4-HMAC-SHA256 Credential=test/20260325/eu-west-1/s3/aws4_request, SignedHeaders=host;x-amz-date, Signature=test")
|
||||
.header("Authorization", regionalAuth)
|
||||
.when()
|
||||
.put("/" + bucket)
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body(containsString("<Code>IllegalLocationConstraintException</Code>"));
|
||||
|
||||
given()
|
||||
.header("Authorization", regionalAuth)
|
||||
.contentType("application/xml")
|
||||
.body("<CreateBucketConfiguration><LocationConstraint>eu-west-1</LocationConstraint></CreateBucketConfiguration>")
|
||||
.when()
|
||||
.put("/" + bucket)
|
||||
.then()
|
||||
@@ -457,10 +473,10 @@ class S3IntegrationTest {
|
||||
|
||||
given()
|
||||
.when()
|
||||
.head("/" + bucket)
|
||||
.get("/" + bucket + "?location")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.header("x-amz-bucket-region", equalTo("eu-west-1"));
|
||||
.body(containsString(">eu-west-1</LocationConstraint>"));
|
||||
|
||||
given()
|
||||
.when()
|
||||
|
||||
+10
-4
@@ -33,7 +33,7 @@ class S3PartitionBucketPolicyIamEnforcementIntegrationTest {
|
||||
String key = "guarded.txt";
|
||||
S3RequestSigner china = createAccountAdmin("cn-admin-" + suffix).inRegion("cn-north-1");
|
||||
|
||||
createBucket(bucket, china);
|
||||
createBucket(bucket, "cn-north-1", china);
|
||||
putObject(bucket, key, china);
|
||||
putBucketPolicy(bucket, denyObjectReadWritePolicy("aws-cn", bucket), china);
|
||||
|
||||
@@ -48,7 +48,7 @@ class S3PartitionBucketPolicyIamEnforcementIntegrationTest {
|
||||
String key = "guarded.txt";
|
||||
S3RequestSigner commercial = createAccountAdmin("us-admin-" + suffix);
|
||||
|
||||
createBucket(bucket, commercial);
|
||||
createBucket(bucket, "us-east-1", commercial);
|
||||
putObject(bucket, key, commercial);
|
||||
putBucketPolicy(bucket, denyObjectReadWritePolicy("aws", bucket), commercial);
|
||||
|
||||
@@ -93,8 +93,14 @@ class S3PartitionBucketPolicyIamEnforcementIntegrationTest {
|
||||
.body(containsString("AccessDenied"));
|
||||
}
|
||||
|
||||
private static void createBucket(String bucket, S3RequestSigner signer) {
|
||||
given().filter(signer).when().put("/" + bucket).then().statusCode(200);
|
||||
/** A regional endpoint other than us-east-1 requires a LocationConstraint naming its region, as on AWS. */
|
||||
private static void createBucket(String bucket, String region, S3RequestSigner signer) {
|
||||
RequestSpecification request = given().filter(signer);
|
||||
if (!"us-east-1".equals(region)) {
|
||||
request = request.contentType("application/xml").body("<CreateBucketConfiguration><LocationConstraint>"
|
||||
+ region + "</LocationConstraint></CreateBucketConfiguration>");
|
||||
}
|
||||
request.when().put("/" + bucket).then().statusCode(200);
|
||||
}
|
||||
|
||||
private static void putObject(String bucket, String key, S3RequestSigner signer) {
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
package io.github.hectorvent.floci.services.s3;
|
||||
|
||||
import io.github.hectorvent.floci.testing.PartitionCleanup;
|
||||
import io.github.hectorvent.floci.testing.PartitionMatrix;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
|
||||
/**
|
||||
* S3's CreateBucket region rules are the same in every partition (moto's {@code aws_verified}
|
||||
* matrix): the {@code us-east-1} endpoint takes any constraint but its own, and every other
|
||||
* regional endpoint requires a constraint naming exactly its region. In a China deployment the
|
||||
* constraint is therefore mandatory, which is what the China SDKs send.
|
||||
*/
|
||||
@QuarkusTest
|
||||
class S3PartitionIntegrationTest {
|
||||
|
||||
private static final String UNSPECIFIED =
|
||||
"The unspecified location constraint is incompatible for the region specific endpoint this request was sent to.";
|
||||
|
||||
@RegisterExtension
|
||||
final PartitionCleanup cleanup = new PartitionCleanup();
|
||||
|
||||
private static RequestSpecification s3(String region) {
|
||||
return given().header("Authorization", PartitionMatrix.sigV4Auth(region, "s3"));
|
||||
}
|
||||
|
||||
private static String constraint(String region) {
|
||||
return "<CreateBucketConfiguration><LocationConstraint>" + region
|
||||
+ "</LocationConstraint></CreateBucketConfiguration>";
|
||||
}
|
||||
|
||||
private String bucketName(String label) {
|
||||
return "partition-" + label + "-" + Long.toString(System.nanoTime(), 36);
|
||||
}
|
||||
|
||||
private void deleteLater(String region, String bucket) {
|
||||
cleanup.register(() -> s3(region).delete("/" + bucket));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aChinaEndpointRequiresItsOwnLocationConstraint() {
|
||||
String bucket = bucketName("cn");
|
||||
s3("cn-north-1").put("/" + bucket).then().statusCode(400)
|
||||
.body(containsString("<Code>IllegalLocationConstraintException</Code>"))
|
||||
.body(containsString("<Message>" + UNSPECIFIED + "</Message>"));
|
||||
|
||||
s3("cn-north-1").contentType("application/xml").body(constraint("cn-north-1"))
|
||||
.put("/" + bucket).then().statusCode(200);
|
||||
deleteLater("cn-north-1", bucket);
|
||||
|
||||
s3("cn-north-1").get("/" + bucket + "?location").then().statusCode(200)
|
||||
.body(containsString(">cn-north-1</LocationConstraint>"));
|
||||
|
||||
s3("cn-north-1").contentType("application/xml").body(constraint("cn-north-1"))
|
||||
.put("/" + bucket).then().statusCode(409)
|
||||
.body(containsString("<Code>BucketAlreadyOwnedByYou</Code>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aRegionalEndpointRejectsAnotherRegionsConstraint() {
|
||||
String bucket = bucketName("mismatch");
|
||||
s3("us-west-2").contentType("application/xml").body(constraint("eu-central-1"))
|
||||
.put("/" + bucket).then().statusCode(400)
|
||||
.body(containsString("<Code>IllegalLocationConstraintException</Code>"))
|
||||
.body(containsString("<Message>The eu-central-1 location constraint is incompatible for the "
|
||||
+ "region specific endpoint this request was sent to.</Message>"));
|
||||
s3("cn-north-1").contentType("application/xml").body(constraint("cn-northwest-1"))
|
||||
.put("/" + bucket).then().statusCode(400)
|
||||
.body(containsString("<Code>IllegalLocationConstraintException</Code>"));
|
||||
// us-east-1 is only InvalidLocationConstraint on its own endpoint; anywhere else it is
|
||||
// just another mismatched region.
|
||||
s3("us-west-2").contentType("application/xml").body(constraint("us-east-1"))
|
||||
.put("/" + bucket).then().statusCode(400)
|
||||
.body(containsString("<Code>IllegalLocationConstraintException</Code>"))
|
||||
.body(containsString("<Message>The us-east-1 location constraint is incompatible for the "
|
||||
+ "region specific endpoint this request was sent to.</Message>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void theGlobalEndpointTakesAnyConstraintButItsOwn() {
|
||||
String bucket = bucketName("global");
|
||||
s3("us-east-1").contentType("application/xml").body(constraint("eu-west-1"))
|
||||
.put("/" + bucket).then().statusCode(200);
|
||||
deleteLater("us-east-1", bucket);
|
||||
s3("us-east-1").get("/" + bucket + "?location").then().statusCode(200)
|
||||
.body(containsString(">eu-west-1</LocationConstraint>"));
|
||||
|
||||
s3("us-east-1").contentType("application/xml").body(constraint("us-east-1"))
|
||||
.put("/" + bucketName("invalid")).then().statusCode(400)
|
||||
.body(containsString("<Code>InvalidLocationConstraint</Code>"))
|
||||
.body(containsString("<Message>The specified location-constraint is not valid.</Message>"));
|
||||
|
||||
String virginia = bucketName("virginia");
|
||||
s3("us-east-1").put("/" + virginia).then().statusCode(200);
|
||||
deleteLater("us-east-1", virginia);
|
||||
s3("us-east-1").get("/" + virginia + "?location").then().statusCode(200)
|
||||
.body(containsString("<LocationConstraint xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"/>"));
|
||||
}
|
||||
}
|
||||
+4
-1
@@ -220,7 +220,10 @@ class SesImportJobV2IntegrationTest {
|
||||
String s3AuthA = accountAuth("111111111111", "s3");
|
||||
String bucketA = BUCKET + "-a";
|
||||
|
||||
given().header("Authorization", s3AuthA).when().put("/" + bucketA).then().statusCode(200);
|
||||
// A regional S3 endpoint requires a LocationConstraint naming its region, as on AWS.
|
||||
given().header("Authorization", s3AuthA).contentType("application/xml")
|
||||
.body("<CreateBucketConfiguration><LocationConstraint>eu-west-3</LocationConstraint></CreateBucketConfiguration>")
|
||||
.when().put("/" + bucketA).then().statusCode(200);
|
||||
given().header("Authorization", s3AuthA).contentType("text/plain").body("account-a@example.com,BOUNCE\n")
|
||||
.when().put("/" + bucketA + "/suppress.csv").then().statusCode(200);
|
||||
|
||||
|
||||
+3
-1
@@ -59,6 +59,8 @@ class AslExecutorResultWriterTest {
|
||||
// An exported Map run is retained through the service, so a Map state needs one to run.
|
||||
Instance<StepFunctionsService> sfnService = mock(Instance.class);
|
||||
when(sfnService.get()).thenReturn(mock(StepFunctionsService.class));
|
||||
EmulatorConfig config = mock(EmulatorConfig.class);
|
||||
when(config.defaultRegion()).thenReturn("us-east-1");
|
||||
executor = new AslExecutor(
|
||||
mock(LambdaExecutorService.class),
|
||||
mock(LambdaFunctionStore.class),
|
||||
@@ -76,7 +78,7 @@ class AslExecutorResultWriterTest {
|
||||
mapper,
|
||||
new JsonataEvaluator(mapper),
|
||||
sfnService,
|
||||
mock(EmulatorConfig.class),
|
||||
config,
|
||||
null,
|
||||
null);
|
||||
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
package io.github.hectorvent.floci.services.wafv2;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.StorageFactory;
|
||||
import io.github.hectorvent.floci.services.wafv2.model.WebAcl;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* CloudFormation calls the service outside any request, where the request region falls back to
|
||||
* the deployment default. The CLOUDFRONT scope must follow the region the caller passes, so a
|
||||
* GovCloud default neither refuses a commercial stack's WebACL nor admits a GovCloud one.
|
||||
*/
|
||||
class WafV2CloudFrontScopeTest {
|
||||
|
||||
private WafV2Service service;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
StorageFactory storageFactory = mock(StorageFactory.class);
|
||||
when(storageFactory.create(anyString(), anyString(), any()))
|
||||
.thenAnswer(invocation -> AccountAwareStorageBackend.inMemory("000000000000"));
|
||||
service = new WafV2Service(storageFactory, new RegionResolver("us-gov-west-1", "000000000000"),
|
||||
new ObjectMapper());
|
||||
}
|
||||
|
||||
@Test
|
||||
void aCommercialStackCreatesItsCloudFrontWebAclUnderAGovCloudDefault() {
|
||||
WebAcl acl = service.createWebAcl(new WebAcl(), "CLOUDFRONT", "edge", "us-east-1");
|
||||
|
||||
assertTrue(acl.getArn().startsWith("arn:aws:wafv2:us-east-1:000000000000:global/webacl/edge/"),
|
||||
acl.getArn());
|
||||
assertEquals("edge", service.getWebAcl("CLOUDFRONT", acl.getId(), "edge").getName());
|
||||
service.deleteWebAcl("CLOUDFRONT", acl.getId(), "edge", acl.getLockToken());
|
||||
}
|
||||
|
||||
@Test
|
||||
void aGovCloudStackIsRefusedTheCloudFrontScope() {
|
||||
AwsException error = assertThrows(AwsException.class,
|
||||
() -> service.createWebAcl(new WebAcl(), "CLOUDFRONT", "edge", "us-gov-west-1"));
|
||||
|
||||
assertEquals("WAFInvalidParameterException", error.getErrorCode());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user