mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(cloudfront): add CloudFront KeyValueStore support (#8108)
This commit is contained in:
1 parent
2beb3b6c0d
commit
9831603f67
25 files changed
+2021
-17
No files matched your search
@@ -854,6 +854,27 @@ class PartitionCrossServiceSmokeIntegrationTest {
|
||||
created.xmlPath().getString("FunctionSummary.FunctionMetadata.FunctionARN"));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource(PartitionMatrix.NON_COMMERCIAL_CASES)
|
||||
void cloudFrontKeyValueStoreArn(PartitionCase partitionCase) {
|
||||
String region = offered(partitionCase, "cloudfront");
|
||||
String name = unique("smoke-kvs", partitionCase);
|
||||
String body = """
|
||||
<CreateKeyValueStoreRequest xmlns="http://cloudfront.amazonaws.com/doc/2020-05-31/">
|
||||
<Name>%s</Name>
|
||||
</CreateKeyValueStoreRequest>
|
||||
""".formatted(name);
|
||||
Response created = signed(region, "cloudfront")
|
||||
.contentType("application/xml")
|
||||
.body(body)
|
||||
.when().post("/2020-05-31/key-value-store").then().statusCode(201).extract().response();
|
||||
String etag = created.header("ETag");
|
||||
cleanup.register(() -> signed(region, "cloudfront")
|
||||
.header("If-Match", etag)
|
||||
.when().delete("/2020-05-31/key-value-store/" + name));
|
||||
PartitionMatrix.assertGlobalArnIn(partitionCase, created.xmlPath().getString("KeyValueStore.ARN"));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource(PartitionMatrix.NON_COMMERCIAL_CASES)
|
||||
void ramResourceShareArn(PartitionCase partitionCase) {
|
||||
|
||||
+463
@@ -0,0 +1,463 @@
|
||||
package io.floci.aws.services.cloudfront;
|
||||
|
||||
import io.floci.aws.core.common.XmlParser;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.response.Response;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Base64;
|
||||
import java.util.UUID;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.hamcrest.xml.HasXPath.hasXPath;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
/** CloudFront key value stores: the control plane under /2020-05-31 and the cloudfront-keyvaluestore data plane. */
|
||||
@QuarkusTest
|
||||
class CloudFrontKeyValueStoreIntegrationTest {
|
||||
|
||||
private static final String CLOUDFRONT = "/2020-05-31/";
|
||||
private static final String DATA_PLANE = "/key-value-stores/";
|
||||
private static final String XML = "application/xml";
|
||||
private static final String NS = "http://cloudfront.amazonaws.com/doc/2020-05-31/";
|
||||
private static final String FUNCTION_CODE = "function handler(event) { return event.request; }";
|
||||
private static final String SIGV4A_AUTHORIZATION = "AWS4-ECDSA-P256-SHA256 "
|
||||
+ "Credential=000000000000/20260101/cloudfront-keyvaluestore/aws4_request, "
|
||||
+ "SignedHeaders=host;x-amz-date, Signature=00";
|
||||
|
||||
private record Store(String name, String arn, String etag, String dataEtag) {}
|
||||
|
||||
private static String uniqueName() {
|
||||
return "kvs-" + UUID.randomUUID().toString().substring(0, 8);
|
||||
}
|
||||
|
||||
private static Store createStore(String name, String comment) {
|
||||
Response created = given().contentType(XML)
|
||||
.body("<CreateKeyValueStoreRequest xmlns=\"%s\"><Name>%s</Name><Comment>%s</Comment></CreateKeyValueStoreRequest>"
|
||||
.formatted(NS, name, comment))
|
||||
.when().post(CLOUDFRONT + "key-value-store");
|
||||
created.then().statusCode(201);
|
||||
String xml = created.asString();
|
||||
String arn = XmlParser.extractFirst(xml, "ARN", null);
|
||||
Response described = given().urlEncodingEnabled(false).header("Authorization", SIGV4A_AUTHORIZATION)
|
||||
.when().get(DATA_PLANE + encoded(arn));
|
||||
described.then().statusCode(200);
|
||||
return new Store(name, arn, created.header("ETag"), described.header("ETag"));
|
||||
}
|
||||
|
||||
private static String encoded(String value) {
|
||||
return URLEncoder.encode(value, StandardCharsets.UTF_8).replace("+", "%20");
|
||||
}
|
||||
|
||||
private static String storePath(Store store) {
|
||||
return DATA_PLANE + encoded(store.arn());
|
||||
}
|
||||
|
||||
private static RequestSpecification dataPlane() {
|
||||
return given().urlEncodingEnabled(false).header("Authorization", SIGV4A_AUTHORIZATION);
|
||||
}
|
||||
|
||||
private static Response putKey(Store store, String etag, String key, String value) {
|
||||
return dataPlane().header("If-Match", etag).contentType("application/json")
|
||||
.body("{\"Value\":\"%s\"}".formatted(value))
|
||||
.when().put(storePath(store) + "/keys/" + encoded(key));
|
||||
}
|
||||
|
||||
private static String createFunction(String name, String runtime, String kvsArn) {
|
||||
String associations = kvsArn == null ? ""
|
||||
: "<KeyValueStoreAssociations><Quantity>1</Quantity><Items><KeyValueStoreAssociation>"
|
||||
+ "<KeyValueStoreARN>" + kvsArn + "</KeyValueStoreARN>"
|
||||
+ "</KeyValueStoreAssociation></Items></KeyValueStoreAssociations>";
|
||||
return """
|
||||
<CreateFunctionRequest xmlns="%s">
|
||||
<Name>%s</Name>
|
||||
<FunctionConfig><Comment>kvs</Comment><Runtime>%s</Runtime>%s</FunctionConfig>
|
||||
<FunctionCode>%s</FunctionCode>
|
||||
</CreateFunctionRequest>
|
||||
""".formatted(NS, name, runtime, associations,
|
||||
Base64.getEncoder().encodeToString(FUNCTION_CODE.getBytes(StandardCharsets.UTF_8)));
|
||||
}
|
||||
|
||||
// ── Control plane ─────────────────────────────────────────────────────────
|
||||
|
||||
@Test
|
||||
void controlPlaneCreatesDescribesListsUpdatesAndDeletes() {
|
||||
String name = uniqueName();
|
||||
|
||||
Response created = given().contentType(XML)
|
||||
.body("<CreateKeyValueStoreRequest xmlns=\"%s\"><Name>%s</Name><Comment>first</Comment></CreateKeyValueStoreRequest>"
|
||||
.formatted(NS, name))
|
||||
.when().post(CLOUDFRONT + "key-value-store");
|
||||
created.then()
|
||||
.statusCode(201)
|
||||
.header("ETag", notNullValue())
|
||||
.header("Location", containsString("/key-value-store/" + name))
|
||||
.body(hasXPath("local-name(/*)", equalTo("KeyValueStore")))
|
||||
.body(hasXPath("namespace-uri(/*)", equalTo(NS)))
|
||||
.body(hasXPath("/*[local-name()='KeyValueStore']/*[local-name()='Status']", equalTo("READY")));
|
||||
String arn = XmlParser.extractFirst(created.asString(), "ARN", null);
|
||||
assertNotNull(arn);
|
||||
assertEquals(true, arn.matches("arn:aws:cloudfront::\\d{12}:key-value-store/[0-9a-f-]{36}"));
|
||||
|
||||
Response described = given().when().get(CLOUDFRONT + "key-value-store/" + name);
|
||||
described.then().statusCode(200).header("ETag", equalTo(created.header("ETag")));
|
||||
assertEquals(arn, XmlParser.extractFirst(described.asString(), "ARN", null));
|
||||
|
||||
given().when().get(CLOUDFRONT + "key-value-store")
|
||||
.then().statusCode(200)
|
||||
.body(hasXPath("local-name(/*)", equalTo("KeyValueStoreList")))
|
||||
.body(hasXPath("//*[local-name()='KeyValueStore']/*[local-name()='Name'][text()='" + name + "']"));
|
||||
|
||||
Response updated = given().contentType(XML).header("If-Match", created.header("ETag"))
|
||||
.body("<UpdateKeyValueStoreRequest xmlns=\"%s\"><Comment>second</Comment></UpdateKeyValueStoreRequest>"
|
||||
.formatted(NS))
|
||||
.when().put(CLOUDFRONT + "key-value-store/" + name);
|
||||
updated.then().statusCode(200);
|
||||
assertNotEquals(created.header("ETag"), updated.header("ETag"));
|
||||
assertEquals("second", XmlParser.extractFirst(updated.asString(), "Comment", null));
|
||||
|
||||
given().header("If-Match", updated.header("ETag"))
|
||||
.when().delete(CLOUDFRONT + "key-value-store/" + name)
|
||||
.then().statusCode(204);
|
||||
given().when().get(CLOUDFRONT + "key-value-store/" + name).then().statusCode(404);
|
||||
}
|
||||
|
||||
@Test
|
||||
void controlPlaneErrorsUseTheModeledCodes() {
|
||||
Store store = createStore(uniqueName(), "errors");
|
||||
|
||||
given().contentType(XML)
|
||||
.body("<CreateKeyValueStoreRequest xmlns=\"%s\"><Name>%s</Name></CreateKeyValueStoreRequest>"
|
||||
.formatted(NS, store.name()))
|
||||
.when().post(CLOUDFRONT + "key-value-store")
|
||||
.then().statusCode(409).body(hasXPath("//*[local-name()='Code']", equalTo("EntityAlreadyExists")));
|
||||
given().when().get(CLOUDFRONT + "key-value-store/does-not-exist")
|
||||
.then().statusCode(404).body(hasXPath("//*[local-name()='Code']", equalTo("EntityNotFound")));
|
||||
given().contentType(XML)
|
||||
.body("<CreateKeyValueStoreRequest xmlns=\"%s\"><Name>not valid!</Name></CreateKeyValueStoreRequest>"
|
||||
.formatted(NS))
|
||||
.when().post(CLOUDFRONT + "key-value-store")
|
||||
.then().statusCode(400).body(hasXPath("//*[local-name()='Code']", equalTo("InvalidArgument")));
|
||||
given().header("If-Match", "stale")
|
||||
.when().delete(CLOUDFRONT + "key-value-store/" + store.name())
|
||||
.then().statusCode(400).body(hasXPath("//*[local-name()='Code']", equalTo("InvalidIfMatchVersion")));
|
||||
}
|
||||
|
||||
// ── Data plane ────────────────────────────────────────────────────────────
|
||||
|
||||
@Test
|
||||
void dataPlaneRoundTripsKeysThroughAPercentEncodedArn() {
|
||||
Store store = createStore(uniqueName(), "data plane");
|
||||
|
||||
Response put = putKey(store, store.dataEtag(), "demo.example.com", "3-5-19-1234");
|
||||
put.then().statusCode(200)
|
||||
.body("ItemCount", equalTo(1))
|
||||
.body("TotalSizeInBytes", equalTo("demo.example.com".length() + "3-5-19-1234".length()))
|
||||
.header("ETag", notNullValue());
|
||||
assertNotEquals(store.dataEtag(), put.header("ETag"));
|
||||
|
||||
dataPlane().when().get(storePath(store) + "/keys/" + encoded("demo.example.com"))
|
||||
.then().statusCode(200)
|
||||
.body("Key", equalTo("demo.example.com"))
|
||||
.body("Value", equalTo("3-5-19-1234"))
|
||||
.body("ItemCount", equalTo(1));
|
||||
|
||||
dataPlane().when().get(storePath(store))
|
||||
.then().statusCode(200)
|
||||
.body("KvsARN", equalTo(store.arn()))
|
||||
.body("ItemCount", equalTo(1))
|
||||
.body("Status", equalTo("READY"))
|
||||
.body("Created", notNullValue())
|
||||
.header("ETag", equalTo(put.header("ETag")));
|
||||
|
||||
dataPlane().header("If-Match", put.header("ETag"))
|
||||
.when().delete(storePath(store) + "/keys/" + encoded("demo.example.com"))
|
||||
.then().statusCode(200).body("ItemCount", equalTo(0));
|
||||
dataPlane().when().get(storePath(store) + "/keys/" + encoded("demo.example.com"))
|
||||
.then().statusCode(404)
|
||||
.header("X-Amzn-Errortype", equalTo("ResourceNotFoundException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aKeyMayContainSlashesAndSpaces() {
|
||||
Store store = createStore(uniqueName(), "odd keys");
|
||||
String key = "tenant/a b?c";
|
||||
|
||||
putKey(store, store.dataEtag(), key, "v1").then().statusCode(200);
|
||||
|
||||
dataPlane().when().get(storePath(store) + "/keys/" + encoded(key))
|
||||
.then().statusCode(200).body("Key", equalTo(key)).body("Value", equalTo("v1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void dataPlaneWritesNeedTheCurrentEtag() {
|
||||
Store store = createStore(uniqueName(), "etag");
|
||||
Response first = putKey(store, store.dataEtag(), "a", "1");
|
||||
first.then().statusCode(200);
|
||||
|
||||
putKey(store, store.dataEtag(), "b", "2").then()
|
||||
.statusCode(400)
|
||||
.header("X-Amzn-Errortype", equalTo("ValidationException"));
|
||||
dataPlane().contentType("application/json").body("{\"Value\":\"2\"}")
|
||||
.when().put(storePath(store) + "/keys/b")
|
||||
.then().statusCode(400)
|
||||
.header("X-Amzn-Errortype", equalTo("ValidationException"));
|
||||
putKey(store, first.header("ETag"), "b", "2").then().statusCode(200).body("ItemCount", equalTo(2));
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateKeysRejectsMoreThanFiftyEntriesAndAPutWithoutAValue() {
|
||||
Store store = createStore(uniqueName(), "limits");
|
||||
|
||||
StringBuilder puts = new StringBuilder();
|
||||
for (int i = 0; i < 51; i++) {
|
||||
puts.append(i == 0 ? "" : ",").append("{\"Key\":\"k").append(i).append("\",\"Value\":\"v\"}");
|
||||
}
|
||||
dataPlane().header("If-Match", store.dataEtag()).contentType("application/json")
|
||||
.body("{\"Puts\":[" + puts + "]}")
|
||||
.when().post(storePath(store) + "/keys")
|
||||
.then().statusCode(400).header("X-Amzn-Errortype", equalTo("ValidationException"));
|
||||
|
||||
dataPlane().header("If-Match", store.dataEtag()).contentType("application/json")
|
||||
.body("{\"Puts\":[{\"Key\":\"a\",\"Value\":\"1\"},{\"Key\":\"b\"}]}")
|
||||
.when().post(storePath(store) + "/keys")
|
||||
.then().statusCode(400).header("X-Amzn-Errortype", equalTo("ValidationException"));
|
||||
|
||||
dataPlane().when().get(storePath(store))
|
||||
.then().statusCode(200).body("ItemCount", equalTo(0)).header("ETag", equalTo(store.dataEtag()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void controlPlaneAndDataPlaneEtagsAreIndependent() {
|
||||
Store store = createStore(uniqueName(), "etags");
|
||||
|
||||
putKey(store, store.dataEtag(), "a", "1").then().statusCode(200);
|
||||
Response updated = given().contentType(XML).header("If-Match", store.etag())
|
||||
.body("<UpdateKeyValueStoreRequest xmlns=\"%s\"><Comment>changed</Comment></UpdateKeyValueStoreRequest>"
|
||||
.formatted(NS))
|
||||
.when().put(CLOUDFRONT + "key-value-store/" + store.name());
|
||||
updated.then().statusCode(200);
|
||||
|
||||
Response written = dataPlane().when().get(storePath(store));
|
||||
putKey(store, written.header("ETag"), "b", "2").then().statusCode(200).body("ItemCount", equalTo(2));
|
||||
given().header("If-Match", updated.header("ETag"))
|
||||
.when().delete(CLOUDFRONT + "key-value-store/" + store.name())
|
||||
.then().statusCode(204);
|
||||
}
|
||||
|
||||
@Test
|
||||
void createWithAnImportSourceIsRejectedInsteadOfCreatingAnEmptyStore() {
|
||||
String name = uniqueName();
|
||||
given().contentType(XML)
|
||||
.body(("<CreateKeyValueStoreRequest xmlns=\"%s\"><Name>%s</Name><ImportSource><SourceType>S3</SourceType>"
|
||||
+ "<SourceARN>arn:aws:s3:::bucket/keys.json</SourceARN></ImportSource></CreateKeyValueStoreRequest>")
|
||||
.formatted(NS, name))
|
||||
.when().post(CLOUDFRONT + "key-value-store")
|
||||
.then().statusCode(400).body(hasXPath("//*[local-name()='Code']", equalTo("InvalidArgument")));
|
||||
given().when().get(CLOUDFRONT + "key-value-store/" + name).then().statusCode(404);
|
||||
}
|
||||
|
||||
@Test
|
||||
void deletingAStoreDropsItsTags() {
|
||||
String name = uniqueName();
|
||||
Response created = given().contentType(XML)
|
||||
.body(("<CreateKeyValueStoreRequest xmlns=\"%s\"><Name>%s</Name></CreateKeyValueStoreRequest>")
|
||||
.formatted(NS, name))
|
||||
.when().post(CLOUDFRONT + "key-value-store");
|
||||
created.then().statusCode(201);
|
||||
String arn = XmlParser.extractFirst(created.asString(), "ARN", null);
|
||||
given().contentType(XML).queryParam("Operation", "Tag").queryParam("Resource", arn)
|
||||
.body("<Tags xmlns=\"%s\"><Items><Tag><Key>team</Key><Value>a</Value></Tag></Items></Tags>".formatted(NS))
|
||||
.when().post(CLOUDFRONT + "tagging").then().statusCode(204);
|
||||
|
||||
given().header("If-Match", created.header("ETag"))
|
||||
.when().delete(CLOUDFRONT + "key-value-store/" + name).then().statusCode(204);
|
||||
|
||||
given().queryParam("Resource", arn).when().get(CLOUDFRONT + "tagging")
|
||||
.then().statusCode(200).body(not(containsString("team")));
|
||||
}
|
||||
@Test
|
||||
void malformedKeyWritesAreValidationErrorsAndChangeNothing() {
|
||||
Store store = createStore(uniqueName(), "shapes");
|
||||
Response seeded = putKey(store, store.dataEtag(), "a", "1");
|
||||
seeded.then().statusCode(200);
|
||||
String etag = seeded.header("ETag");
|
||||
|
||||
String[] bodies = {"{\"Value\":{}}", "{\"Value\":5}"};
|
||||
for (String body : bodies) {
|
||||
dataPlane().header("If-Match", etag).contentType("application/json").body(body)
|
||||
.when().put(storePath(store) + "/keys/a")
|
||||
.then().statusCode(400).header("X-Amzn-Errortype", equalTo("ValidationException"));
|
||||
}
|
||||
String[] batches = {"{\"Puts\":[{\"Key\":\"a\",\"Value\":5}]}", "{\"Puts\":[{\"Key\":7,\"Value\":\"v\"}]}",
|
||||
"{\"Deletes\":\"a\"}", "{\"Puts\":{\"Key\":\"a\",\"Value\":\"v\"}}", "[]"};
|
||||
for (String body : batches) {
|
||||
dataPlane().header("If-Match", etag).contentType("application/json").body(body)
|
||||
.when().post(storePath(store) + "/keys")
|
||||
.then().statusCode(400).header("X-Amzn-Errortype", equalTo("ValidationException"));
|
||||
}
|
||||
|
||||
dataPlane().when().get(storePath(store) + "/keys/a").then().statusCode(200).body("Value", equalTo("1"));
|
||||
dataPlane().when().get(storePath(store)).then().statusCode(200).header("ETag", equalTo(etag));
|
||||
}
|
||||
|
||||
@Test
|
||||
void listKeyValueStoresHonoursTheStatusFilter() {
|
||||
Store store = createStore(uniqueName(), "status");
|
||||
|
||||
given().queryParam("Status", "READY").when().get(CLOUDFRONT + "key-value-store")
|
||||
.then().statusCode(200).body(containsString(store.name()));
|
||||
given().queryParam("Status", "PENDING").when().get(CLOUDFRONT + "key-value-store")
|
||||
.then().statusCode(200).body(not(containsString(store.name())));
|
||||
}
|
||||
@Test
|
||||
void aMalformedMaxResultsIsAValidationError() {
|
||||
Store store = createStore(uniqueName(), "page");
|
||||
|
||||
dataPlane().queryParam("MaxResults", "abc").when().get(storePath(store) + "/keys")
|
||||
.then().statusCode(400).header("X-Amzn-Errortype", equalTo("ValidationException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void anImportSourceWithoutASourceArnIsRejectedToo() {
|
||||
String name = uniqueName();
|
||||
given().contentType(XML)
|
||||
.body(("<CreateKeyValueStoreRequest xmlns=\"%s\"><Name>%s</Name><ImportSource><SourceType>S3"
|
||||
+ "</SourceType></ImportSource></CreateKeyValueStoreRequest>").formatted(NS, name))
|
||||
.when().post(CLOUDFRONT + "key-value-store")
|
||||
.then().statusCode(400).body(hasXPath("//*[local-name()='Code']", equalTo("InvalidArgument")));
|
||||
given().when().get(CLOUDFRONT + "key-value-store/" + name).then().statusCode(404);
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateKeyValueStoreWithoutACommentIsRejected() {
|
||||
Store store = createStore(uniqueName(), "kept");
|
||||
|
||||
given().contentType(XML).header("If-Match", store.etag())
|
||||
.body("<UpdateKeyValueStoreRequest xmlns=\"%s\"></UpdateKeyValueStoreRequest>".formatted(NS))
|
||||
.when().put(CLOUDFRONT + "key-value-store/" + store.name())
|
||||
.then().statusCode(400);
|
||||
given().when().get(CLOUDFRONT + "key-value-store/" + store.name())
|
||||
.then().statusCode(200).body(hasXPath("//*[local-name()='Comment']", equalTo("kept")));
|
||||
}
|
||||
@Test
|
||||
void updateKeysAppliesPutsAndDeletesAtOnce() {
|
||||
Store store = createStore(uniqueName(), "batch");
|
||||
Response seeded = dataPlane().header("If-Match", store.dataEtag()).contentType("application/json")
|
||||
.body("{\"Puts\":[{\"Key\":\"a\",\"Value\":\"1\"},{\"Key\":\"b\",\"Value\":\"2\"}]}")
|
||||
.when().post(storePath(store) + "/keys");
|
||||
seeded.then().statusCode(200).body("ItemCount", equalTo(2));
|
||||
|
||||
dataPlane().header("If-Match", seeded.header("ETag")).contentType("application/json")
|
||||
.body("{\"Puts\":[{\"Key\":\"c\",\"Value\":\"3\"}],\"Deletes\":[{\"Key\":\"a\"}]}")
|
||||
.when().post(storePath(store) + "/keys")
|
||||
.then().statusCode(200).body("ItemCount", equalTo(2));
|
||||
|
||||
dataPlane().when().get(storePath(store) + "/keys")
|
||||
.then().statusCode(200)
|
||||
.body("Items.Key", contains("b", "c"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void listKeysPagesInKeyOrder() {
|
||||
Store store = createStore(uniqueName(), "paging");
|
||||
Response seeded = dataPlane().header("If-Match", store.dataEtag()).contentType("application/json")
|
||||
.body("{\"Puts\":[{\"Key\":\"c\",\"Value\":\"3\"},{\"Key\":\"a\",\"Value\":\"1\"},"
|
||||
+ "{\"Key\":\"b\",\"Value\":\"2\"}]}")
|
||||
.when().post(storePath(store) + "/keys");
|
||||
seeded.then().statusCode(200);
|
||||
|
||||
Response first = dataPlane().queryParam("MaxResults", 2).when().get(storePath(store) + "/keys");
|
||||
first.then().statusCode(200).body("Items", hasSize(2)).body("Items.Key", contains("a", "b"));
|
||||
String token = first.jsonPath().getString("NextToken");
|
||||
assertNotNull(token);
|
||||
|
||||
dataPlane().queryParam("MaxResults", 2).queryParam("NextToken", token)
|
||||
.when().get(storePath(store) + "/keys")
|
||||
.then().statusCode(200)
|
||||
.body("Items.Key", contains("c"))
|
||||
.body("NextToken", nullValue());
|
||||
|
||||
dataPlane().queryParam("MaxResults", 51).when().get(storePath(store) + "/keys")
|
||||
.then().statusCode(400).header("X-Amzn-Errortype", equalTo("ValidationException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void keyAndValueSizeLimitsAreValidationErrors() {
|
||||
Store store = createStore(uniqueName(), "limits");
|
||||
|
||||
putKey(store, store.dataEtag(), "k".repeat(513), "v").then().statusCode(400)
|
||||
.header("X-Amzn-Errortype", equalTo("ValidationException"));
|
||||
putKey(store, store.dataEtag(), "k", "v".repeat(1025)).then().statusCode(400)
|
||||
.header("X-Amzn-Errortype", equalTo("ValidationException"));
|
||||
putKey(store, store.dataEtag(), "k".repeat(512), "v".repeat(1024)).then().statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
void anUnknownStoreArnIsResourceNotFound() {
|
||||
String arn = "arn:aws:cloudfront::000000000000:key-value-store/00000000-0000-0000-0000-000000000000";
|
||||
|
||||
dataPlane().when().get(DATA_PLANE + encoded(arn))
|
||||
.then().statusCode(404).header("X-Amzn-Errortype", equalTo("ResourceNotFoundException"));
|
||||
}
|
||||
|
||||
// ── Functions ─────────────────────────────────────────────────────────────
|
||||
|
||||
@Test
|
||||
void aFunctionCanBeAssociatedWithAStoreAndTheStoreIsProtectedWhileInUse() {
|
||||
Store store = createStore(uniqueName(), "in use");
|
||||
String functionName = "fn-" + UUID.randomUUID().toString().substring(0, 8);
|
||||
|
||||
Response function = given().contentType(XML).body(createFunction(functionName, "cloudfront-js-2.0", store.arn()))
|
||||
.when().post(CLOUDFRONT + "function");
|
||||
function.then().statusCode(201);
|
||||
assertEquals(store.arn(), XmlParser.extractFirst(function.asString(), "KeyValueStoreARN", null));
|
||||
|
||||
given().when().get(CLOUDFRONT + "function/" + functionName + "/describe")
|
||||
.then().statusCode(200)
|
||||
.body(hasXPath("//*[local-name()='KeyValueStoreAssociation']/*[local-name()='KeyValueStoreARN']",
|
||||
equalTo(store.arn())));
|
||||
given().when().get(CLOUDFRONT + "function")
|
||||
.then().statusCode(200)
|
||||
.body(hasXPath("//*[local-name()='KeyValueStoreARN'][text()='" + store.arn() + "']"));
|
||||
|
||||
given().header("If-Match", store.etag())
|
||||
.when().delete(CLOUDFRONT + "key-value-store/" + store.name())
|
||||
.then().statusCode(409)
|
||||
.body(hasXPath("//*[local-name()='Code']", equalTo("CannotDeleteEntityWhileInUse")));
|
||||
|
||||
given().header("If-Match", function.header("ETag"))
|
||||
.when().delete(CLOUDFRONT + "function/" + functionName)
|
||||
.then().statusCode(204);
|
||||
given().header("If-Match", store.etag())
|
||||
.when().delete(CLOUDFRONT + "key-value-store/" + store.name())
|
||||
.then().statusCode(204);
|
||||
}
|
||||
|
||||
@Test
|
||||
void aFunctionCannotUseAnUnknownStoreOrTheFirstRuntime() {
|
||||
Store store = createStore(uniqueName(), "runtime");
|
||||
String unknownArn = "arn:aws:cloudfront::000000000000:key-value-store/00000000-0000-0000-0000-000000000000";
|
||||
|
||||
given().contentType(XML)
|
||||
.body(createFunction("fn-" + UUID.randomUUID().toString().substring(0, 8), "cloudfront-js-2.0", unknownArn))
|
||||
.when().post(CLOUDFRONT + "function")
|
||||
.then().statusCode(404).body(hasXPath("//*[local-name()='Code']", equalTo("EntityNotFound")));
|
||||
given().contentType(XML)
|
||||
.body(createFunction("fn-" + UUID.randomUUID().toString().substring(0, 8), "cloudfront-js-1.0", store.arn()))
|
||||
.when().post(CLOUDFRONT + "function")
|
||||
.then().statusCode(400).body(hasXPath("//*[local-name()='Code']", equalTo("InvalidArgument")));
|
||||
}
|
||||
}
|
||||
+344
@@ -0,0 +1,344 @@
|
||||
package io.floci.aws.services.cloudfront;
|
||||
|
||||
import io.floci.aws.core.common.AwsException;
|
||||
import io.floci.aws.core.common.RegionResolver;
|
||||
import io.floci.aws.core.storage.AccountAwareStorageBackend;
|
||||
import io.floci.aws.core.storage.StorageFactory;
|
||||
import io.floci.aws.services.cloudfront.model.KeyValueStore;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
class CloudFrontKeyValueStoreServiceTest {
|
||||
|
||||
private static final String ACCOUNT = "000000000000";
|
||||
|
||||
private CloudFrontKeyValueStoreService newService() {
|
||||
StorageFactory storageFactory = Mockito.mock(StorageFactory.class);
|
||||
when(storageFactory.create(Mockito.anyString(), Mockito.anyString(), Mockito.any()))
|
||||
.thenAnswer(invocation -> AccountAwareStorageBackend.inMemory(ACCOUNT));
|
||||
return new CloudFrontKeyValueStoreService(storageFactory, new RegionResolver("us-east-1", ACCOUNT));
|
||||
}
|
||||
|
||||
private static void assertError(String code, int status, Runnable action) {
|
||||
AwsException e = assertThrows(AwsException.class, action::run);
|
||||
assertEquals(code, e.getErrorCode());
|
||||
assertEquals(status, e.getHttpStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createStoresAReadyStoreWithAnArnAndAnEtag() {
|
||||
CloudFrontKeyValueStoreService service = newService();
|
||||
|
||||
KeyValueStore created = service.create("tenants", "tenant to version");
|
||||
|
||||
assertEquals("tenants", created.getName());
|
||||
assertEquals("READY", created.getStatus());
|
||||
assertEquals("tenant to version", created.getComment());
|
||||
assertEquals("arn:aws:cloudfront::" + ACCOUNT + ":key-value-store/" + created.getId(), created.getArn());
|
||||
assertTrue(created.getItems().isEmpty());
|
||||
assertEquals(created.getArn(), service.findByArn(created.getArn()).orElseThrow().getArn());
|
||||
assertEquals(created.getEtag(), service.describe("tenants").getEtag());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createRejectsAnInvalidNameADuplicateAndAnOverlongComment() {
|
||||
CloudFrontKeyValueStoreService service = newService();
|
||||
service.create("tenants", null);
|
||||
|
||||
assertError("EntityAlreadyExists", 409, () -> service.create("tenants", null));
|
||||
assertError("InvalidArgument", 400, () -> service.create("bad name!", null));
|
||||
assertError("InvalidArgument", 400, () -> service.create("", null));
|
||||
assertError("InvalidArgument", 400, () -> service.create("a".repeat(65), null));
|
||||
assertError("InvalidArgument", 400, () -> service.create("commented", "c".repeat(129)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeOfAnUnknownStoreIsEntityNotFound() {
|
||||
assertError("EntityNotFound", 404, () -> newService().describe("missing"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateNeedsTheCurrentEtagAndRotatesIt() {
|
||||
CloudFrontKeyValueStoreService service = newService();
|
||||
KeyValueStore created = service.create("tenants", "one");
|
||||
String firstEtag = created.getEtag();
|
||||
|
||||
assertError("InvalidIfMatchVersion", 400, () -> service.update("tenants", "stale", "two"));
|
||||
assertError("InvalidIfMatchVersion", 400, () -> service.update("tenants", null, "two"));
|
||||
|
||||
KeyValueStore updated = service.update("tenants", firstEtag, "two");
|
||||
|
||||
assertEquals("two", updated.getComment());
|
||||
assertNotEquals(firstEtag, updated.getEtag());
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteNeedsTheCurrentEtag() {
|
||||
CloudFrontKeyValueStoreService service = newService();
|
||||
KeyValueStore created = service.create("tenants", null);
|
||||
|
||||
assertError("InvalidIfMatchVersion", 400, () -> service.delete("tenants", "stale"));
|
||||
service.delete("tenants", created.getEtag());
|
||||
|
||||
assertError("EntityNotFound", 404, () -> service.describe("tenants"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void listIsOrderedByNameAndPagesWithAMarker() {
|
||||
CloudFrontKeyValueStoreService service = newService();
|
||||
service.create("gamma", null);
|
||||
service.create("alpha", null);
|
||||
service.create("beta", null);
|
||||
|
||||
List<KeyValueStore> firstPage = service.list(null, 2, null);
|
||||
List<KeyValueStore> secondPage = service.list("beta", 2, null);
|
||||
|
||||
assertEquals(List.of("alpha", "beta"), firstPage.stream().map(KeyValueStore::getName).toList());
|
||||
assertEquals(List.of("gamma"), secondPage.stream().map(KeyValueStore::getName).toList());
|
||||
}
|
||||
|
||||
@Test
|
||||
void putKeyThenGetKeyRoundTripsAndCountsBytes() {
|
||||
CloudFrontKeyValueStoreService service = newService();
|
||||
KeyValueStore created = service.create("tenants", null);
|
||||
|
||||
KeyValueStore written = service.putKey(created.getArn(), created.getDataEtag(), "demo.example.com", "3-5-19-1234");
|
||||
|
||||
assertEquals("3-5-19-1234", service.getKey(created.getArn(), "demo.example.com").value());
|
||||
assertEquals(1, CloudFrontKeyValueStoreService.itemCount(written));
|
||||
assertEquals("demo.example.com".length() + "3-5-19-1234".length(),
|
||||
CloudFrontKeyValueStoreService.totalSizeInBytes(written));
|
||||
assertNotEquals(created.getDataEtag(), written.getDataEtag());
|
||||
}
|
||||
|
||||
@Test
|
||||
void sizeIsCountedInUtf8Bytes() {
|
||||
CloudFrontKeyValueStoreService service = newService();
|
||||
KeyValueStore created = service.create("tenants", null);
|
||||
|
||||
KeyValueStore written = service.putKey(created.getArn(), created.getDataEtag(), "k", "é");
|
||||
|
||||
assertEquals(1 + 2, CloudFrontKeyValueStoreService.totalSizeInBytes(written));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aDataPlaneWriteWithAStaleOrMissingEtagIsRejected() {
|
||||
CloudFrontKeyValueStoreService service = newService();
|
||||
KeyValueStore created = service.create("tenants", null);
|
||||
String arn = created.getArn();
|
||||
service.putKey(arn, created.getDataEtag(), "a", "1");
|
||||
|
||||
assertError("ValidationException", 400, () -> service.putKey(arn, created.getDataEtag(), "b", "2"));
|
||||
assertError("ValidationException", 400, () -> service.putKey(arn, null, "b", "2"));
|
||||
assertNull(service.describeByArn(arn).getItems().get("b"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void theControlPlaneAndDataPlaneKeepIndependentEtags() {
|
||||
CloudFrontKeyValueStoreService service = newService();
|
||||
KeyValueStore created = service.create("tenants", "one");
|
||||
|
||||
KeyValueStore updated = service.update("tenants", created.getEtag(), "two");
|
||||
assertNotEquals(created.getEtag(), updated.getEtag());
|
||||
assertEquals(created.getDataEtag(), updated.getDataEtag());
|
||||
KeyValueStore written = service.putKey(created.getArn(), created.getDataEtag(), "a", "1");
|
||||
assertEquals(updated.getEtag(), written.getEtag());
|
||||
assertNotEquals(created.getDataEtag(), written.getDataEtag());
|
||||
|
||||
service.delete("tenants", updated.getEtag());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createUsesTheRequestAccountInTheArn() {
|
||||
StorageFactory storageFactory = Mockito.mock(StorageFactory.class);
|
||||
when(storageFactory.create(Mockito.anyString(), Mockito.anyString(), Mockito.any()))
|
||||
.thenAnswer(invocation -> AccountAwareStorageBackend.inMemory(ACCOUNT));
|
||||
RegionResolver resolver = Mockito.spy(new RegionResolver("us-east-1", ACCOUNT));
|
||||
when(resolver.getAccountId()).thenReturn("111122223333");
|
||||
CloudFrontKeyValueStoreService service = new CloudFrontKeyValueStoreService(storageFactory, resolver);
|
||||
|
||||
KeyValueStore created = service.create("tenants", null);
|
||||
|
||||
assertTrue(created.getArn().startsWith("arn:aws:cloudfront::111122223333:key-value-store/"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createRejectsPunctuationAndStopsAtTwoHundredStores() {
|
||||
CloudFrontKeyValueStoreService service = newService();
|
||||
assertError("InvalidArgument", 400, () -> service.create("a?b", null));
|
||||
assertError("InvalidArgument", 400, () -> service.create("a\\b", null));
|
||||
assertError("InvalidArgument", 400, () -> service.create("a:b", null));
|
||||
|
||||
for (int i = 0; i < CloudFrontKeyValueStoreService.MAX_STORES; i++) {
|
||||
service.create("store-" + i, null);
|
||||
}
|
||||
|
||||
assertError("EntityLimitExceeded", 400, () -> service.create("one-too-many", null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void anUnknownStoreArnIsResourceNotFoundOnTheDataPlane() {
|
||||
CloudFrontKeyValueStoreService service = newService();
|
||||
String arn = "arn:aws:cloudfront::" + ACCOUNT + ":key-value-store/00000000-0000-0000-0000-000000000000";
|
||||
|
||||
assertError("ResourceNotFoundException", 404, () -> service.describeByArn(arn));
|
||||
assertError("ResourceNotFoundException", 404, () -> service.getKey(arn, "a"));
|
||||
assertError("ResourceNotFoundException", 404, () -> service.putKey(arn, "etag", "a", "1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aMissingKeyIsResourceNotFound() {
|
||||
CloudFrontKeyValueStoreService service = newService();
|
||||
KeyValueStore created = service.create("tenants", null);
|
||||
|
||||
assertError("ResourceNotFoundException", 404, () -> service.getKey(created.getArn(), "missing"));
|
||||
assertError("ResourceNotFoundException", 404,
|
||||
() -> service.deleteKey(created.getArn(), created.getDataEtag(), "missing"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void keyAndValueLimitsAreEnforcedInBytes() {
|
||||
CloudFrontKeyValueStoreService service = newService();
|
||||
KeyValueStore created = service.create("tenants", null);
|
||||
String arn = created.getArn();
|
||||
String etag = created.getDataEtag();
|
||||
|
||||
assertError("ValidationException", 400, () -> service.putKey(arn, etag, "k".repeat(513), "v"));
|
||||
assertError("ValidationException", 400, () -> service.putKey(arn, etag, "k", "v".repeat(1025)));
|
||||
assertError("ValidationException", 400, () -> service.putKey(arn, etag, "", "v"));
|
||||
|
||||
KeyValueStore atTheLimit = service.putKey(arn, etag, "k".repeat(512), "v".repeat(1024));
|
||||
assertEquals(1, CloudFrontKeyValueStoreService.itemCount(atTheLimit));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aStoreCannotGrowPastFiveMebibytes() {
|
||||
CloudFrontKeyValueStoreService service = newService();
|
||||
KeyValueStore created = service.create("tenants", null);
|
||||
Map<String, String> puts = new LinkedHashMap<>();
|
||||
for (int i = 0; i < 5200; i++) {
|
||||
puts.put("key-%05d".formatted(i), "v".repeat(1024));
|
||||
}
|
||||
|
||||
assertError("ServiceQuotaExceededException", 402,
|
||||
() -> service.updateKeys(created.getArn(), created.getDataEtag(), puts, List.of()));
|
||||
assertTrue(service.describeByArn(created.getArn()).getItems().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void aBatchIsAtomicWhenOneEntryIsInvalid() {
|
||||
CloudFrontKeyValueStoreService service = newService();
|
||||
KeyValueStore created = service.create("tenants", null);
|
||||
Map<String, String> puts = new LinkedHashMap<>();
|
||||
puts.put("good", "1");
|
||||
puts.put("bad", "v".repeat(1025));
|
||||
|
||||
assertError("ValidationException", 400,
|
||||
() -> service.updateKeys(created.getArn(), created.getDataEtag(), puts, List.of()));
|
||||
|
||||
KeyValueStore unchanged = service.describeByArn(created.getArn());
|
||||
assertTrue(unchanged.getItems().isEmpty());
|
||||
assertEquals(created.getDataEtag(), unchanged.getDataEtag());
|
||||
}
|
||||
|
||||
@Test
|
||||
void aBatchAppliesPutsAndDeletesTogetherAndSkipsDeletesOfAbsentKeys() {
|
||||
CloudFrontKeyValueStoreService service = newService();
|
||||
KeyValueStore created = service.create("tenants", null);
|
||||
KeyValueStore first = service.updateKeys(created.getArn(), created.getDataEtag(),
|
||||
Map.of("a", "1", "b", "2"), List.of());
|
||||
|
||||
KeyValueStore second = service.updateKeys(created.getArn(), first.getDataEtag(),
|
||||
Map.of("c", "3"), List.of("a", "never-existed"));
|
||||
|
||||
assertEquals(List.of("b", "c"), new ArrayList<>(new TreeMap<>(second.getItems()).keySet()));
|
||||
assertNotEquals(first.getDataEtag(), second.getDataEtag());
|
||||
}
|
||||
|
||||
@Test
|
||||
void listKeysIsSortedAndPagesWithAToken() {
|
||||
CloudFrontKeyValueStoreService service = newService();
|
||||
KeyValueStore created = service.create("tenants", null);
|
||||
Map<String, String> puts = new LinkedHashMap<>();
|
||||
for (String key : List.of("echo", "alpha", "delta", "bravo", "charlie")) {
|
||||
puts.put(key, key.toUpperCase());
|
||||
}
|
||||
service.updateKeys(created.getArn(), created.getDataEtag(), puts, List.of());
|
||||
|
||||
CloudFrontKeyValueStoreService.KeyPage first = service.listKeys(created.getArn(), null, 2);
|
||||
CloudFrontKeyValueStoreService.KeyPage second = service.listKeys(created.getArn(), first.nextToken(), 2);
|
||||
CloudFrontKeyValueStoreService.KeyPage third = service.listKeys(created.getArn(), second.nextToken(), 2);
|
||||
|
||||
assertEquals(List.of("alpha", "bravo"), first.items().stream().map(Map.Entry::getKey).toList());
|
||||
assertEquals(List.of("charlie", "delta"), second.items().stream().map(Map.Entry::getKey).toList());
|
||||
assertEquals(List.of("echo"), third.items().stream().map(Map.Entry::getKey).toList());
|
||||
assertNull(third.nextToken());
|
||||
}
|
||||
|
||||
@Test
|
||||
void listKeysValidatesMaxResultsAndTheToken() {
|
||||
CloudFrontKeyValueStoreService service = newService();
|
||||
KeyValueStore created = service.create("tenants", null);
|
||||
|
||||
assertError("ValidationException", 400, () -> service.listKeys(created.getArn(), null, 0));
|
||||
assertError("ValidationException", 400, () -> service.listKeys(created.getArn(), null, 51));
|
||||
assertError("ValidationException", 400, () -> service.listKeys(created.getArn(), "!!not base64!!", 10));
|
||||
assertEquals(10, CloudFrontKeyValueStoreService.DEFAULT_LIST_KEYS);
|
||||
}
|
||||
|
||||
@Test
|
||||
void listResumesAfterAMarkerStoreThatWasDeleted() {
|
||||
CloudFrontKeyValueStoreService service = newService();
|
||||
service.create("a", null);
|
||||
KeyValueStore b = service.create("b", null);
|
||||
service.create("c", null);
|
||||
service.delete("b", b.getEtag());
|
||||
|
||||
List<KeyValueStore> page = service.list("b", 10, null);
|
||||
|
||||
assertEquals(List.of("c"), page.stream().map(KeyValueStore::getName).toList());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateWithoutACommentIsRejectedAndKeepsTheStore() {
|
||||
CloudFrontKeyValueStoreService service = newService();
|
||||
KeyValueStore created = service.create("tenants", "keep me");
|
||||
|
||||
assertError("InvalidArgument", 400, () -> service.update("tenants", created.getEtag(), null));
|
||||
|
||||
KeyValueStore unchanged = service.describe("tenants");
|
||||
assertEquals("keep me", unchanged.getComment());
|
||||
assertEquals(created.getEtag(), unchanged.getEtag());
|
||||
}
|
||||
|
||||
@Test
|
||||
void findResolvesAStoreNameToItsStoredArn() {
|
||||
CloudFrontKeyValueStoreService service = newService();
|
||||
KeyValueStore created = service.create("tenants", null);
|
||||
|
||||
assertEquals(created.getArn(), service.find("key-value-store", List.of("tenants"), "us-east-1").orElseThrow());
|
||||
assertTrue(service.find("key-value-store", List.of("missing"), "us-east-1").isEmpty());
|
||||
assertTrue(service.find("distribution", List.of("tenants"), "us-east-1").isEmpty());
|
||||
}
|
||||
@Test
|
||||
void listFiltersByStatus() {
|
||||
CloudFrontKeyValueStoreService service = newService();
|
||||
service.create("a", null);
|
||||
service.create("b", null);
|
||||
|
||||
assertEquals(2, service.list(null, 10, "READY").size());
|
||||
assertTrue(service.list(null, 10, "PENDING").isEmpty());
|
||||
}}
|
||||
@@ -1,11 +1,13 @@
|
||||
package io.floci.aws.services.iam;
|
||||
|
||||
import io.floci.aws.core.common.XmlParser;
|
||||
import io.floci.aws.testing.EnforcementFixtures;
|
||||
import io.floci.aws.testing.IamEnforcementProfile;
|
||||
import io.floci.aws.testing.PartitionCleanup;
|
||||
import io.quarkus.test.common.http.TestHTTPResource;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.quarkus.test.junit.TestProfile;
|
||||
import io.restassured.response.Response;
|
||||
import io.restassured.response.ValidatableResponse;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -16,6 +18,7 @@ import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import static io.floci.aws.testing.EnforcementFixtures.auth;
|
||||
import static io.restassured.RestAssured.given;
|
||||
@@ -71,6 +74,49 @@ class IamRestRouteEnforcementIntegrationTest {
|
||||
.get("/2018-10-31/layers").then().statusCode(404);
|
||||
}
|
||||
|
||||
@Test
|
||||
void cloudFrontKeyValueStoreDataPlaneRoutesAreCheckedByOperation() {
|
||||
String user = user("route-kvs");
|
||||
String arn = "arn:aws:cloudfront::" + ACCOUNT + ":key-value-store/" + UUID.randomUUID();
|
||||
String path = "/key-value-stores/" + URLEncoder.encode(arn, StandardCharsets.UTF_8);
|
||||
|
||||
policy(user, allow("cloudfront-keyvaluestore:ListKeys", "*"));
|
||||
refused(as(user, "cloudfront-keyvaluestore").urlEncodingEnabled(false).get(path).then(),
|
||||
"cloudfront-keyvaluestore:DescribeKeyValueStore");
|
||||
refused(as(user, "cloudfront-keyvaluestore").urlEncodingEnabled(false).header("If-Match", "etag")
|
||||
.body("{\"Value\":\"v\"}").put(path + "/keys/k").then(), "cloudfront-keyvaluestore:PutKey");
|
||||
|
||||
policy(user, allow("cloudfront-keyvaluestore:DescribeKeyValueStore", arn));
|
||||
// Allowed on that store, the request reaches the data plane, which has no such store.
|
||||
as(user, "cloudfront-keyvaluestore").urlEncodingEnabled(false).get(path).then().statusCode(404);
|
||||
}
|
||||
@Test
|
||||
void cloudFrontKeyValueStoreControlPlaneIsCheckedAgainstTheStoresReturnedArn() {
|
||||
String user = user("route-kvs-control");
|
||||
String name = "kvs-" + suffix();
|
||||
String namespace = "http://cloudfront.amazonaws.com/doc/2020-05-31/";
|
||||
Response created = given().header("Authorization", auth(ADMIN, "cloudfront"))
|
||||
.contentType("application/xml")
|
||||
.body("<CreateKeyValueStoreRequest xmlns=\"" + namespace + "\"><Name>" + name
|
||||
+ "</Name></CreateKeyValueStoreRequest>")
|
||||
.post("/2020-05-31/key-value-store");
|
||||
created.then().statusCode(201);
|
||||
String arn = XmlParser.extractFirst(created.asString(), "ARN", null);
|
||||
String etag = created.header("ETag");
|
||||
|
||||
policy(user, allow("cloudfront:*", "*") + "," +
|
||||
"{\"Effect\":\"Deny\",\"Action\":\"cloudfront:DeleteKeyValueStore\",\"Resource\":\"" + arn + "\"}");
|
||||
refused(as(user, "cloudfront").header("If-Match", etag).delete("/2020-05-31/key-value-store/" + name).then(),
|
||||
"cloudfront:DeleteKeyValueStore");
|
||||
as(user, "cloudfront").get("/2020-05-31/key-value-store/" + name).then().statusCode(200);
|
||||
|
||||
policy(user, allow("cloudfront:DescribeKeyValueStore", "arn:aws:cloudfront::" + ACCOUNT
|
||||
+ ":key-value-store/not-this-one"));
|
||||
refused(as(user, "cloudfront").get("/2020-05-31/key-value-store/" + name).then(),
|
||||
"cloudfront:DescribeKeyValueStore");
|
||||
policy(user, allow("cloudfront:DescribeKeyValueStore", arn));
|
||||
as(user, "cloudfront").get("/2020-05-31/key-value-store/" + name).then().statusCode(200);
|
||||
}
|
||||
@Test
|
||||
void aScheduleRequestSignedForAnotherServiceIsStillCheckedAsScheduler() {
|
||||
// Checked by the route it reached, not by the credential scope it was signed with: an S3
|
||||
|
||||
Reference in new issue
Block a user