mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 14:10:49 -05:00
feat(firehose): add StartDeliveryStreamEncryption and StopDeliveryStreamEncryption (#2583)
* feat(firehose): add Start/StopDeliveryStreamEncryption Models DeliveryStreamEncryptionConfiguration on the stream description so the encryption state set by Start is visible to Describe and cleared by Stop. Limitations documented in docs/services/firehose.md. * fix(firehose): keep the key identity on StopDeliveryStreamEncryption and reject Start without an encryption input - Stopping customer-managed encryption now preserves KeyType and KeyARN with Status DISABLED, matching what DescribeDeliveryStream reports on real AWS. - Streams persisted before the encryption field existed deserialize to the AWS-shaped DISABLED default instead of null via a field-level initializer. - StartDeliveryStreamEncryption without DeliveryStreamEncryptionConfigurationInput is now rejected with InvalidArgumentException instead of silently defaulting. * fix(firehose): reject a KeyARN that is not a KMS key ARN StartDeliveryStreamEncryption stored DeliveryStreamEncryptionConfigurationInput's KeyARN verbatim, so a bare key id or an alias ARN was accepted and then reported back by DescribeDeliveryStream as the stream's encryption key. botocore pins AWSKMSKeyARNForSSE to arn:.*:kms:<region>:<12-digit account>:key/<id> with a 512-character cap; anything else is an InvalidArgumentException on real AWS. * fix(firehose): enforce the modeled input constraints on the pre-existing operations DeliveryStreamType is now checked against the modeled enum, and Tags, Records and TagKeys against their modeled list bounds (1-50, 1-500, 1-50), all answering InvalidArgumentException as the operations model. Previously all four were accepted verbatim. Included here because this PR already carries wire-shape hardening for the same handler; found by a model-grounded constraint sweep. * fix(firehose): treat StartDeliveryStreamEncryption input as optional DeliveryStreamEncryptionConfigurationInput is Required: No in the model; omitting it is the documented way to enable SSE with the service-owned key and defaults KeyType to AWS_OWNED_CMK. The prior null-input rejection regressed that path - inverted the pinning test to assert the 200/AWS_OWNED_CMK behavior.
This commit is contained in:
1 parent
20ecb89155
commit
4affa05cea
6 files changed
+458
-8
No files matched your search
@@ -12,6 +12,8 @@ Floci emulates Amazon Data Firehose for streaming data ingestion and delivery to
|
||||
| --- | --- |
|
||||
| `CreateDeliveryStream` | Creates a new delivery stream |
|
||||
| `UpdateDestination` | - |
|
||||
| `StartDeliveryStreamEncryption` | - |
|
||||
| `StopDeliveryStreamEncryption` | - |
|
||||
| `DescribeDeliveryStream` | Returns metadata about a stream |
|
||||
| `ListDeliveryStreams` | Lists all delivery streams |
|
||||
| `DeleteDeliveryStream` | Deletes a delivery stream |
|
||||
|
||||
+54
-8
@@ -53,12 +53,17 @@ public class FirehoseJsonHandler {
|
||||
}
|
||||
List<io.github.hectorvent.floci.services.firehose.model.DeliveryStreamDescription.Tag> tags = new ArrayList<>();
|
||||
if (request.has("Tags")) {
|
||||
requireListSize(request.get("Tags"), "Tags", 1, 50);
|
||||
for (JsonNode tNode : request.get("Tags")) {
|
||||
tags.add(mapper.treeToValue(tNode, io.github.hectorvent.floci.services.firehose.model.DeliveryStreamDescription.Tag.class));
|
||||
}
|
||||
}
|
||||
String deliveryStreamType = request.has("DeliveryStreamType")
|
||||
? request.get("DeliveryStreamType").asText() : null;
|
||||
if (deliveryStreamType != null && !DELIVERY_STREAM_TYPES.contains(deliveryStreamType)) {
|
||||
throw new AwsException("InvalidArgumentException",
|
||||
"DeliveryStreamType must be one of " + DELIVERY_STREAM_TYPES + ".", 400);
|
||||
}
|
||||
KinesisStreamSource source = request.has("KinesisStreamSourceConfiguration")
|
||||
? mapper.treeToValue(request.get("KinesisStreamSourceConfiguration"), KinesisStreamSource.class)
|
||||
: null;
|
||||
@@ -80,6 +85,31 @@ public class FirehoseJsonHandler {
|
||||
firehoseService.updateDestination(name, currentVersionId, destinationId, update);
|
||||
yield Response.ok(Map.of()).build();
|
||||
}
|
||||
case "StartDeliveryStreamEncryption" -> {
|
||||
String name = getDeliveryStreamName(request);
|
||||
JsonNode input = request.get("DeliveryStreamEncryptionConfigurationInput");
|
||||
// DeliveryStreamEncryptionConfigurationInput is optional (Required: No):
|
||||
// omitting it is the documented way to enable SSE with the service-owned
|
||||
// key (KeyType defaults to AWS_OWNED_CMK). KeyType is only required when
|
||||
// the input object itself is present.
|
||||
String keyType = null;
|
||||
String keyArn = null;
|
||||
if (input != null && !input.isNull()) {
|
||||
keyType = input.has("KeyType") && !input.get("KeyType").isNull()
|
||||
? input.get("KeyType").asText() : null;
|
||||
keyArn = input.has("KeyARN") && !input.get("KeyARN").isNull()
|
||||
? input.get("KeyARN").asText() : null;
|
||||
if (keyType == null || keyType.isBlank()) {
|
||||
throw new AwsException("InvalidArgumentException", "KeyType is required.", 400);
|
||||
}
|
||||
}
|
||||
firehoseService.startDeliveryStreamEncryption(name, keyType, keyArn);
|
||||
yield Response.ok(Map.of()).build();
|
||||
}
|
||||
case "StopDeliveryStreamEncryption" -> {
|
||||
firehoseService.stopDeliveryStreamEncryption(getDeliveryStreamName(request));
|
||||
yield Response.ok(Map.of()).build();
|
||||
}
|
||||
case "DescribeDeliveryStream" -> {
|
||||
String name = getDeliveryStreamName(request);
|
||||
var desc = firehoseService.describeDeliveryStream(name);
|
||||
@@ -104,6 +134,7 @@ public class FirehoseJsonHandler {
|
||||
case "PutRecordBatch" -> {
|
||||
String name = getDeliveryStreamName(request);
|
||||
List<Record> records = new ArrayList<>();
|
||||
requireListSize(request.get("Records"), "Records", 1, 500);
|
||||
for (JsonNode recordNode : request.get("Records")) {
|
||||
records.add(mapper.treeToValue(recordNode, Record.class));
|
||||
}
|
||||
@@ -116,10 +147,9 @@ public class FirehoseJsonHandler {
|
||||
case "TagDeliveryStream" -> {
|
||||
String name = getDeliveryStreamName(request);
|
||||
List<io.github.hectorvent.floci.services.firehose.model.DeliveryStreamDescription.Tag> tags = new ArrayList<>();
|
||||
if (request.has("Tags")) {
|
||||
for (JsonNode tNode : request.get("Tags")) {
|
||||
tags.add(mapper.treeToValue(tNode, io.github.hectorvent.floci.services.firehose.model.DeliveryStreamDescription.Tag.class));
|
||||
}
|
||||
requireListSize(request.get("Tags"), "Tags", 1, 50);
|
||||
for (JsonNode tNode : request.get("Tags")) {
|
||||
tags.add(mapper.treeToValue(tNode, io.github.hectorvent.floci.services.firehose.model.DeliveryStreamDescription.Tag.class));
|
||||
}
|
||||
firehoseService.tagDeliveryStream(name, tags);
|
||||
yield Response.ok(Map.of()).build();
|
||||
@@ -127,10 +157,9 @@ public class FirehoseJsonHandler {
|
||||
case "UntagDeliveryStream" -> {
|
||||
String name = getDeliveryStreamName(request);
|
||||
List<String> keys = new ArrayList<>();
|
||||
if (request.has("TagKeys")) {
|
||||
for (JsonNode kNode : request.get("TagKeys")) {
|
||||
keys.add(kNode.asText());
|
||||
}
|
||||
requireListSize(request.get("TagKeys"), "TagKeys", 1, 50);
|
||||
for (JsonNode kNode : request.get("TagKeys")) {
|
||||
keys.add(kNode.asText());
|
||||
}
|
||||
firehoseService.untagDeliveryStream(name, keys);
|
||||
yield Response.ok(Map.of()).build();
|
||||
@@ -164,4 +193,21 @@ public class FirehoseJsonHandler {
|
||||
default -> throw new AwsException("InvalidAction", "Action " + action + " is not supported", 400);
|
||||
};
|
||||
}
|
||||
|
||||
/** DeliveryStreamType values the 2015-08-04 model enumerates. */
|
||||
private static final java.util.Set<String> DELIVERY_STREAM_TYPES = java.util.Set.of(
|
||||
"DirectPut", "KinesisStreamAsSource", "MSKAsSource", "DatabaseAsSource");
|
||||
|
||||
/**
|
||||
* Enforces a modeled list min/max. A missing member on the tag operations is
|
||||
* treated as the modeled min-1 violation, matching real Firehose, which
|
||||
* requires the list on TagDeliveryStream/UntagDeliveryStream/PutRecordBatch.
|
||||
*/
|
||||
private static void requireListSize(JsonNode list, String member, int min, int max) {
|
||||
int size = list == null || list.isNull() || !list.isArray() ? 0 : list.size();
|
||||
if (size < min || size > max) {
|
||||
throw new AwsException("InvalidArgumentException",
|
||||
member + " must contain between " + min + " and " + max + " entries.", 400);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -48,6 +48,15 @@ public class FirehoseService implements ResourceProvider {
|
||||
private static final String DEFAULT_BUCKET = "floci-firehose-results";
|
||||
private static final int DEFAULT_BUFFERING_INTERVAL_SECONDS = 300;
|
||||
private static final int DEFAULT_BUFFERING_SIZE_MBS = 5;
|
||||
/**
|
||||
* botocore's {@code AWSKMSKeyARNForSSE} shape: a KMS <em>key</em> ARN, not an alias and
|
||||
* not a bare key id. Accepting anything else would let DescribeDeliveryStream report an
|
||||
* encryption key that could never exist, where real AWS rejects the call outright.
|
||||
*/
|
||||
private static final java.util.regex.Pattern SSE_KEY_ARN_PATTERN = java.util.regex.Pattern.compile(
|
||||
"arn:.*:kms:[a-zA-Z0-9\\-]+:\\d{12}:key/[a-zA-Z_0-9+=,.@\\-_/]+");
|
||||
private static final int SSE_KEY_ARN_MAX_LENGTH = 512;
|
||||
|
||||
// Per shard, per tick. GetRecords caps at 1000 anyway; a smaller page keeps one
|
||||
// busy source stream from monopolising the single flusher thread.
|
||||
private static final int SOURCE_POLL_LIMIT = 500;
|
||||
@@ -257,6 +266,45 @@ public class FirehoseService implements ResourceProvider {
|
||||
LOG.infov("Updated destination {0} of Firehose delivery stream {1}", destinationId, name);
|
||||
}
|
||||
|
||||
public void startDeliveryStreamEncryption(String name, String keyType, String keyArn) {
|
||||
DeliveryStreamDescription stream = describeDeliveryStream(name);
|
||||
String effectiveKeyType = keyType == null ? "AWS_OWNED_CMK" : keyType;
|
||||
if (!effectiveKeyType.equals("AWS_OWNED_CMK") && !effectiveKeyType.equals("CUSTOMER_MANAGED_CMK")) {
|
||||
throw new AwsException("InvalidArgumentException",
|
||||
"KeyType must be AWS_OWNED_CMK or CUSTOMER_MANAGED_CMK.", 400);
|
||||
}
|
||||
if (effectiveKeyType.equals("CUSTOMER_MANAGED_CMK") && (keyArn == null || keyArn.isBlank())) {
|
||||
throw new AwsException("InvalidArgumentException",
|
||||
"KeyARN is required for CUSTOMER_MANAGED_CMK.", 400);
|
||||
}
|
||||
if (keyArn != null && !keyArn.isBlank()
|
||||
&& (keyArn.length() > SSE_KEY_ARN_MAX_LENGTH || !SSE_KEY_ARN_PATTERN.matcher(keyArn).matches())) {
|
||||
throw new AwsException("InvalidArgumentException",
|
||||
"KeyARN is not a valid KMS key ARN: " + keyArn, 400);
|
||||
}
|
||||
stream.setDeliveryStreamEncryptionConfiguration(
|
||||
new DeliveryStreamDescription.DeliveryStreamEncryptionConfiguration(
|
||||
effectiveKeyType,
|
||||
effectiveKeyType.equals("CUSTOMER_MANAGED_CMK") ? keyArn : null,
|
||||
"ENABLED"));
|
||||
streamStore.put(name, stream);
|
||||
}
|
||||
|
||||
public void stopDeliveryStreamEncryption(String name) {
|
||||
DeliveryStreamDescription stream = describeDeliveryStream(name);
|
||||
DeliveryStreamDescription.DeliveryStreamEncryptionConfiguration current =
|
||||
stream.getDeliveryStreamEncryptionConfiguration();
|
||||
String keyType = current == null ? "AWS_OWNED_CMK" : current.getKeyType();
|
||||
// Keep the customer key identity on disable: real AWS still reports the KeyARN
|
||||
// of a stopped CUSTOMER_MANAGED_CMK stream, and dropping it here would make a
|
||||
// later DescribeDeliveryStream forget which key the stream was encrypted with.
|
||||
String keyArn = current == null ? null : current.getKeyArn();
|
||||
stream.setDeliveryStreamEncryptionConfiguration(
|
||||
new DeliveryStreamDescription.DeliveryStreamEncryptionConfiguration(
|
||||
keyType, keyArn, "DISABLED"));
|
||||
streamStore.put(name, stream);
|
||||
}
|
||||
|
||||
// A corrupt persisted version can only reach here when the caller echoed it
|
||||
// (the equality check above passed), so self-heal instead of failing with a 500
|
||||
// or blaming the client.
|
||||
|
||||
+45
@@ -40,6 +40,13 @@ public class DeliveryStreamDescription {
|
||||
@JsonProperty("Tags")
|
||||
private List<Tag> tags = new ArrayList<>();
|
||||
|
||||
// Field-level default so streams persisted before this field existed deserialize to
|
||||
// the AWS-shaped DISABLED configuration instead of null (Jackson only overwrites it
|
||||
// when the stored JSON actually carries the property).
|
||||
@JsonProperty("DeliveryStreamEncryptionConfiguration")
|
||||
private DeliveryStreamEncryptionConfiguration deliveryStreamEncryptionConfiguration =
|
||||
DeliveryStreamEncryptionConfiguration.disabled();
|
||||
|
||||
public DeliveryStreamDescription() {}
|
||||
public DeliveryStreamDescription(String name, String arn, S3Destination s3) {
|
||||
this(name, arn, s3, null);
|
||||
@@ -54,6 +61,7 @@ public class DeliveryStreamDescription {
|
||||
s3.applyDefaults();
|
||||
}
|
||||
this.destinations = List.of(new Destination(s3));
|
||||
this.deliveryStreamEncryptionConfiguration = DeliveryStreamEncryptionConfiguration.disabled();
|
||||
if (kinesisStreamSource != null) {
|
||||
this.source = new Source(kinesisStreamSource);
|
||||
}
|
||||
@@ -80,6 +88,12 @@ public class DeliveryStreamDescription {
|
||||
public void setLastUpdateTimestamp(Instant lastUpdateTimestamp) { this.lastUpdateTimestamp = lastUpdateTimestamp; }
|
||||
public List<Destination> getDestinations() { return destinations; }
|
||||
public void setDestinations(List<Destination> destinations) { this.destinations = destinations; }
|
||||
public DeliveryStreamEncryptionConfiguration getDeliveryStreamEncryptionConfiguration() {
|
||||
return deliveryStreamEncryptionConfiguration;
|
||||
}
|
||||
public void setDeliveryStreamEncryptionConfiguration(DeliveryStreamEncryptionConfiguration configuration) {
|
||||
this.deliveryStreamEncryptionConfiguration = configuration;
|
||||
}
|
||||
public Source getSource() { return source; }
|
||||
public void setSource(Source source) { this.source = source; }
|
||||
|
||||
@@ -365,4 +379,35 @@ public class DeliveryStreamDescription {
|
||||
public String getValue() { return value; }
|
||||
public void setValue(String value) { this.value = value; }
|
||||
}
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public static class DeliveryStreamEncryptionConfiguration {
|
||||
@JsonProperty("KeyType")
|
||||
private String keyType;
|
||||
@JsonProperty("KeyARN")
|
||||
private String keyArn;
|
||||
@JsonProperty("Status")
|
||||
private String status;
|
||||
|
||||
public DeliveryStreamEncryptionConfiguration() {}
|
||||
|
||||
public DeliveryStreamEncryptionConfiguration(String keyType, String keyArn, String status) {
|
||||
this.keyType = keyType;
|
||||
this.keyArn = keyArn;
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public static DeliveryStreamEncryptionConfiguration disabled() {
|
||||
return new DeliveryStreamEncryptionConfiguration("AWS_OWNED_CMK", null, "DISABLED");
|
||||
}
|
||||
|
||||
public String getKeyType() { return keyType; }
|
||||
public void setKeyType(String keyType) { this.keyType = keyType; }
|
||||
public String getKeyArn() { return keyArn; }
|
||||
public void setKeyArn(String keyArn) { this.keyArn = keyArn; }
|
||||
public String getStatus() { return status; }
|
||||
public void setStatus(String status) { this.status = status; }
|
||||
}
|
||||
}
|
||||
+102
@@ -0,0 +1,102 @@
|
||||
package io.github.hectorvent.floci.services.firehose;
|
||||
|
||||
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 static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
/**
|
||||
* Wire-level enforcement of the input constraints the 2015-08-04 model pins on
|
||||
* the pre-existing Firehose operations: the DeliveryStreamType enum, and the
|
||||
* list bounds on Tags (1-50), Records (1-500) and TagKeys (1-50). All of these
|
||||
* were previously accepted verbatim.
|
||||
*/
|
||||
@QuarkusTest
|
||||
class FirehoseInputConstraintConsumerTest {
|
||||
|
||||
private static final String CONTENT_TYPE = "application/x-amz-json-1.1";
|
||||
private static final String TARGET_PREFIX = "Firehose_20150804.";
|
||||
|
||||
@BeforeAll
|
||||
static void configureRestAssured() {
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
}
|
||||
|
||||
private static Response call(String action, String body) {
|
||||
return given()
|
||||
.contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + action)
|
||||
.body(body)
|
||||
.when()
|
||||
.post("/");
|
||||
}
|
||||
|
||||
private static void createStream(String name) {
|
||||
call("CreateDeliveryStream", "{\"DeliveryStreamName\":\"" + name + "\"}")
|
||||
.then().statusCode(200);
|
||||
}
|
||||
|
||||
private static String tagArray(int n) {
|
||||
StringBuilder sb = new StringBuilder("[");
|
||||
for (int i = 0; i < n; i++) {
|
||||
if (i > 0) {
|
||||
sb.append(',');
|
||||
}
|
||||
sb.append("{\"Key\":\"k").append(i).append("\",\"Value\":\"v\"}");
|
||||
}
|
||||
return sb.append(']').toString();
|
||||
}
|
||||
|
||||
@Test
|
||||
void createDeliveryStream_unknownType_returnsInvalidArgument() {
|
||||
call("CreateDeliveryStream", "{\"DeliveryStreamName\":\"ab-badtype\","
|
||||
+ "\"DeliveryStreamType\":\"CarrierPigeon\"}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidArgumentException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createDeliveryStream_tooManyTags_returnsInvalidArgument() {
|
||||
call("CreateDeliveryStream", "{\"DeliveryStreamName\":\"ab-manytags\","
|
||||
+ "\"Tags\":" + tagArray(51) + "}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidArgumentException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void putRecordBatch_emptyRecords_returnsInvalidArgument() {
|
||||
createStream("ab-batch-empty");
|
||||
call("PutRecordBatch", "{\"DeliveryStreamName\":\"ab-batch-empty\",\"Records\":[]}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidArgumentException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void tagDeliveryStream_emptyAndOversizedTags_returnInvalidArgument() {
|
||||
createStream("ab-tag-bounds");
|
||||
call("TagDeliveryStream", "{\"DeliveryStreamName\":\"ab-tag-bounds\",\"Tags\":[]}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidArgumentException"));
|
||||
call("TagDeliveryStream", "{\"DeliveryStreamName\":\"ab-tag-bounds\",\"Tags\":" + tagArray(51) + "}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidArgumentException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void untagDeliveryStream_emptyTagKeys_returnsInvalidArgument() {
|
||||
createStream("ab-untag-bounds");
|
||||
call("UntagDeliveryStream", "{\"DeliveryStreamName\":\"ab-untag-bounds\",\"TagKeys\":[]}")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidArgumentException"));
|
||||
}
|
||||
}
|
||||
+207
@@ -127,6 +127,213 @@ class FirehoseIntegrationTest {
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
void startAndStopDeliveryStreamEncryption() {
|
||||
String encryptionStream = "encryption-stream-" + System.currentTimeMillis();
|
||||
given()
|
||||
.contentType("application/x-amz-json-1.1")
|
||||
.header("X-Amz-Target", "Firehose_20150804.CreateDeliveryStream")
|
||||
.body("{ \"DeliveryStreamName\": \"" + encryptionStream + "\" }")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
String keyArn = "arn:aws:kms:us-east-1:123456789012:key/test-key";
|
||||
given()
|
||||
.contentType("application/x-amz-json-1.1")
|
||||
.header("X-Amz-Target", "Firehose_20150804.StartDeliveryStreamEncryption")
|
||||
.body("{ \"DeliveryStreamName\": \"" + encryptionStream
|
||||
+ "\", \"DeliveryStreamEncryptionConfigurationInput\": { \"KeyType\": \"CUSTOMER_MANAGED_CMK\", \"KeyARN\": \""
|
||||
+ keyArn + "\" } }")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.contentType("application/x-amz-json-1.1")
|
||||
.header("X-Amz-Target", "Firehose_20150804.DescribeDeliveryStream")
|
||||
.body("{ \"DeliveryStreamName\": \"" + encryptionStream + "\" }")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("DeliveryStreamDescription.DeliveryStreamEncryptionConfiguration.KeyType",
|
||||
equalTo("CUSTOMER_MANAGED_CMK"))
|
||||
.body("DeliveryStreamDescription.DeliveryStreamEncryptionConfiguration.KeyARN",
|
||||
equalTo(keyArn))
|
||||
.body("DeliveryStreamDescription.DeliveryStreamEncryptionConfiguration.Status",
|
||||
equalTo("ENABLED"));
|
||||
|
||||
given()
|
||||
.contentType("application/x-amz-json-1.1")
|
||||
.header("X-Amz-Target", "Firehose_20150804.StopDeliveryStreamEncryption")
|
||||
.body("{ \"DeliveryStreamName\": \"" + encryptionStream + "\" }")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.contentType("application/x-amz-json-1.1")
|
||||
.header("X-Amz-Target", "Firehose_20150804.DescribeDeliveryStream")
|
||||
.body("{ \"DeliveryStreamName\": \"" + encryptionStream + "\" }")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("DeliveryStreamDescription.DeliveryStreamEncryptionConfiguration.Status",
|
||||
equalTo("DISABLED"))
|
||||
// Disabling must not erase the key identity: real AWS keeps reporting the
|
||||
// stopped stream's KeyType and customer KeyARN.
|
||||
.body("DeliveryStreamDescription.DeliveryStreamEncryptionConfiguration.KeyType",
|
||||
equalTo("CUSTOMER_MANAGED_CMK"))
|
||||
.body("DeliveryStreamDescription.DeliveryStreamEncryptionConfiguration.KeyARN",
|
||||
equalTo("arn:aws:kms:us-east-1:123456789012:key/test-key"));
|
||||
|
||||
given()
|
||||
.contentType("application/x-amz-json-1.1")
|
||||
.header("X-Amz-Target", "Firehose_20150804.DeleteDeliveryStream")
|
||||
.body("{ \"DeliveryStreamName\": \"" + encryptionStream + "\" }")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(8)
|
||||
void startDeliveryStreamEncryptionWithoutInputDefaultsToAwsOwnedCmk() {
|
||||
// DeliveryStreamEncryptionConfigurationInput is optional (Required: No) - omitting
|
||||
// it is the documented way to enable SSE with the service-owned key, not an error.
|
||||
String encryptionStream = "encryption-noinput-" + System.currentTimeMillis();
|
||||
given()
|
||||
.contentType("application/x-amz-json-1.1")
|
||||
.header("X-Amz-Target", "Firehose_20150804.CreateDeliveryStream")
|
||||
.body("{ \"DeliveryStreamName\": \"" + encryptionStream + "\" }")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.contentType("application/x-amz-json-1.1")
|
||||
.header("X-Amz-Target", "Firehose_20150804.StartDeliveryStreamEncryption")
|
||||
.body("{ \"DeliveryStreamName\": \"" + encryptionStream + "\" }")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.contentType("application/x-amz-json-1.1")
|
||||
.header("X-Amz-Target", "Firehose_20150804.DescribeDeliveryStream")
|
||||
.body("{ \"DeliveryStreamName\": \"" + encryptionStream + "\" }")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("DeliveryStreamDescription.DeliveryStreamEncryptionConfiguration.Status",
|
||||
equalTo("ENABLED"))
|
||||
.body("DeliveryStreamDescription.DeliveryStreamEncryptionConfiguration.KeyType",
|
||||
equalTo("AWS_OWNED_CMK"));
|
||||
|
||||
given()
|
||||
.contentType("application/x-amz-json-1.1")
|
||||
.header("X-Amz-Target", "Firehose_20150804.DeleteDeliveryStream")
|
||||
.body("{ \"DeliveryStreamName\": \"" + encryptionStream + "\" }")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(7)
|
||||
void startDeliveryStreamEncryptionWithoutCustomerKeyReturnsInvalidArgument() {
|
||||
String encryptionStream = "encryption-validation-" + System.currentTimeMillis();
|
||||
given()
|
||||
.contentType("application/x-amz-json-1.1")
|
||||
.header("X-Amz-Target", "Firehose_20150804.CreateDeliveryStream")
|
||||
.body("{ \"DeliveryStreamName\": \"" + encryptionStream + "\" }")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.contentType("application/x-amz-json-1.1")
|
||||
.header("X-Amz-Target", "Firehose_20150804.StartDeliveryStreamEncryption")
|
||||
.body("{ \"DeliveryStreamName\": \"" + encryptionStream
|
||||
+ "\", \"DeliveryStreamEncryptionConfigurationInput\": { \"KeyType\": \"CUSTOMER_MANAGED_CMK\" } }")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidArgumentException"));
|
||||
|
||||
given()
|
||||
.contentType("application/x-amz-json-1.1")
|
||||
.header("X-Amz-Target", "Firehose_20150804.DeleteDeliveryStream")
|
||||
.body("{ \"DeliveryStreamName\": \"" + encryptionStream + "\" }")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(9)
|
||||
void startDeliveryStreamEncryptionWithMalformedKeyArnReturnsInvalidArgument() {
|
||||
String encryptionStream = "encryption-badarn-" + System.currentTimeMillis();
|
||||
given()
|
||||
.contentType("application/x-amz-json-1.1")
|
||||
.header("X-Amz-Target", "Firehose_20150804.CreateDeliveryStream")
|
||||
.body("{ \"DeliveryStreamName\": \"" + encryptionStream + "\" }")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
// botocore pins AWSKMSKeyARNForSSE to
|
||||
// arn:.*:kms:<region>:<12-digit account>:key/<id> — a bare key id is not a KeyARN,
|
||||
// and storing it would make DescribeDeliveryStream report a key that cannot exist.
|
||||
given()
|
||||
.contentType("application/x-amz-json-1.1")
|
||||
.header("X-Amz-Target", "Firehose_20150804.StartDeliveryStreamEncryption")
|
||||
.body("{ \"DeliveryStreamName\": \"" + encryptionStream
|
||||
+ "\", \"DeliveryStreamEncryptionConfigurationInput\": "
|
||||
+ "{ \"KeyType\": \"CUSTOMER_MANAGED_CMK\", \"KeyARN\": \"not-an-arn\" } }")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidArgumentException"));
|
||||
|
||||
// The rejected call must not have enabled encryption on the stream.
|
||||
given()
|
||||
.contentType("application/x-amz-json-1.1")
|
||||
.header("X-Amz-Target", "Firehose_20150804.DescribeDeliveryStream")
|
||||
.body("{ \"DeliveryStreamName\": \"" + encryptionStream + "\" }")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("DeliveryStreamDescription.DeliveryStreamEncryptionConfiguration.Status",
|
||||
equalTo("DISABLED"));
|
||||
|
||||
given()
|
||||
.contentType("application/x-amz-json-1.1")
|
||||
.header("X-Amz-Target", "Firehose_20150804.DeleteDeliveryStream")
|
||||
.body("{ \"DeliveryStreamName\": \"" + encryptionStream + "\" }")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(16)
|
||||
void describeDeliveryStreamReturnsKinesisSourceConfiguration() {
|
||||
|
||||
Reference in new issue
Block a user