mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(logs): add vended log delivery sources, destinations and deliveries (#7411)
This commit is contained in:
1 parent
8c252ef0de
commit
3308ea2f1c
27 files changed
+1709
-42
No files matched your search
+12
-3
@@ -14,6 +14,7 @@ import org.junit.jupiter.api.TestFactory;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -42,11 +43,19 @@ class RequestResourceMembersTest {
|
||||
RequestResourceMembers.Table table = RequestResourceMembers.table();
|
||||
assertTrue(table.namespaces().containsAll(List.of("cognito-idp", "ecr", "elasticloadbalancing", "states")));
|
||||
assertTrue(table.handBuilt().contains("lambda"));
|
||||
assertEquals(Set.of("dynamodb"), table.namespaces().stream().filter(table.handBuilt()::contains)
|
||||
assertEquals(Set.of("dynamodb", "logs"), table.namespaces().stream().filter(table.handBuilt()::contains)
|
||||
.collect(Collectors.toSet()));
|
||||
assertEquals(Set.of("dynamodb:ListTables"), table.operations().keySet().stream()
|
||||
Set<String> logsDelivery = Stream.of("PutDeliverySource", "GetDeliverySource", "DeleteDeliverySource",
|
||||
"DescribeDeliverySources", "PutDeliveryDestination", "GetDeliveryDestination",
|
||||
"DeleteDeliveryDestination", "DescribeDeliveryDestinations", "CreateDelivery", "GetDelivery",
|
||||
"UpdateDeliveryConfiguration", "DeleteDelivery", "DescribeDeliveries")
|
||||
.map(operation -> "logs:" + operation).collect(Collectors.toSet());
|
||||
Set<String> expected = new HashSet<>(logsDelivery);
|
||||
expected.add("dynamodb:ListTables");
|
||||
assertEquals(expected, table.operations().keySet().stream()
|
||||
.filter(operation -> table.handBuilt().contains(operation.substring(0, operation.indexOf(':'))))
|
||||
.collect(Collectors.toSet()), "only explicit corrections override hand-built operations");
|
||||
.collect(Collectors.toSet()),
|
||||
"only explicit corrections and the operations listed to read override hand-built operations");
|
||||
assertTrue(table.namespaces().stream().noneMatch(table.notCovered()::contains));
|
||||
assertTrue(table.otherNamespaces().stream().noneMatch(table.notCovered()::contains));
|
||||
table.operations().forEach((operation, resources) -> {
|
||||
|
||||
+205
@@ -0,0 +1,205 @@
|
||||
package io.github.hectorvent.floci.services.cloudwatch.logs;
|
||||
|
||||
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static io.github.hectorvent.floci.testing.LogsRequests.logs;
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.empty;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasItem;
|
||||
import static org.hamcrest.Matchers.matchesPattern;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
|
||||
/**
|
||||
* Vended-log delivery over the Logs JSON 1.1 API: an EventBridge bus as delivery source, a log
|
||||
* group as delivery destination, and the delivery that pairs them, as
|
||||
* {@code terraform-aws-modules/eventbridge}'s {@code log_delivery} creates them.
|
||||
*/
|
||||
@QuarkusTest
|
||||
class CloudWatchLogsDeliveryIntegrationTest {
|
||||
|
||||
private static final String PREFIX = "arn:aws:logs:us-east-1:000000000000:";
|
||||
|
||||
@BeforeAll
|
||||
static void configureRestAssured() {
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
}
|
||||
|
||||
@Test
|
||||
void anEventBusDeliversToALogGroup() {
|
||||
String suffix = UUID.randomUUID().toString().substring(0, 8);
|
||||
String bus = "arn:aws:events:us-east-1:000000000000:event-bus/orders-" + suffix;
|
||||
String logGroup = PREFIX + "log-group:/aws/events/orders-" + suffix;
|
||||
|
||||
logs("PutDeliverySource", """
|
||||
{"name": "orders-%s", "resourceArn": "%s", "logType": "ERROR_LOGS", "tags": {"team": "data"}}
|
||||
""".formatted(suffix, bus)).then().statusCode(200)
|
||||
.body("deliverySource.name", equalTo("orders-" + suffix))
|
||||
.body("deliverySource.arn", equalTo(PREFIX + "delivery-source:orders-" + suffix))
|
||||
.body("deliverySource.resourceArns", contains(bus))
|
||||
.body("deliverySource.service", equalTo("events"))
|
||||
.body("deliverySource.logType", equalTo("ERROR_LOGS"))
|
||||
.body("deliverySource.tags", nullValue());
|
||||
String destinationArn = logs("PutDeliveryDestination", """
|
||||
{"name": "orders-logs-%s", "outputFormat": "json",
|
||||
"deliveryDestinationConfiguration": {"destinationResourceArn": "%s"}}
|
||||
""".formatted(suffix, logGroup)).then().statusCode(200)
|
||||
.body("deliveryDestination.arn", equalTo(PREFIX + "delivery-destination:orders-logs-" + suffix))
|
||||
.body("deliveryDestination.deliveryDestinationType", equalTo("CWL"))
|
||||
.body("deliveryDestination.outputFormat", equalTo("json"))
|
||||
.body("deliveryDestination.deliveryDestinationConfiguration.destinationResourceArn",
|
||||
equalTo(logGroup))
|
||||
.extract().path("deliveryDestination.arn");
|
||||
|
||||
String id = logs("CreateDelivery", """
|
||||
{"deliverySourceName": "orders-%s", "deliveryDestinationArn": "%s", "tags": {"team": "data"}}
|
||||
""".formatted(suffix, destinationArn)).then().statusCode(200)
|
||||
.body("delivery.id", matchesPattern("[0-9A-Za-z]{16}"))
|
||||
.body("delivery.deliveryDestinationType", equalTo("CWL"))
|
||||
.extract().path("delivery.id");
|
||||
String deliveryArn = PREFIX + "delivery:" + id;
|
||||
|
||||
// GetDelivery reports the event bus template's record fields and the S3 suffix path.
|
||||
logs("GetDelivery", "{\"id\": \"" + id + "\"}").then().statusCode(200)
|
||||
.body("delivery.arn", equalTo(deliveryArn))
|
||||
.body("delivery.deliverySourceName", equalTo("orders-" + suffix))
|
||||
.body("delivery.deliveryDestinationArn", equalTo(destinationArn))
|
||||
.body("delivery.recordFields", contains("resource_arn", "message_timestamp_ms", "event_bus_name",
|
||||
"request_id", "event_id", "invocation_id", "message_type", "log_level", "details", "error"))
|
||||
.body("delivery.s3DeliveryConfiguration.suffixPath", equalTo("{region}/{yyyy}/{MM}/{dd}/{HH}/"))
|
||||
.body("delivery.s3DeliveryConfiguration.enableHiveCompatiblePath", equalTo(false))
|
||||
.body("delivery.fieldDelimiter", nullValue())
|
||||
.body("delivery.tags", nullValue());
|
||||
logs("DescribeDeliveries", "{}").then().statusCode(200)
|
||||
.body("deliveries.id", hasItem(id))
|
||||
.body("deliveries.find { it.id == '" + id + "' }.recordFields", nullValue());
|
||||
|
||||
logs("UpdateDeliveryConfiguration", "{\"id\": \"" + id + "\", \"recordFields\": [\"event_id\", \"error\"]}")
|
||||
.then().statusCode(200);
|
||||
logs("GetDelivery", "{\"id\": \"" + id + "\"}").then()
|
||||
.body("delivery.recordFields", contains("event_id", "error"));
|
||||
|
||||
logs("ListTagsForResource", "{\"resourceArn\": \"" + deliveryArn + "\"}").then().statusCode(200)
|
||||
.body("tags.team", equalTo("data"));
|
||||
logs("TagResource", "{\"resourceArn\": \"" + PREFIX + "delivery-source:orders-" + suffix
|
||||
+ "\", \"tags\": {\"env\": \"local\"}}").then().statusCode(200);
|
||||
logs("ListTagsForResource", "{\"resourceArn\": \"" + PREFIX + "delivery-source:orders-" + suffix + "\"}")
|
||||
.then().body("tags.team", equalTo("data")).body("tags.env", equalTo("local"));
|
||||
// The same name in another partition is not the caller's source.
|
||||
logs("TagResource", "{\"resourceArn\": \"" + PREFIX.replace("arn:aws:", "arn:aws-cn:")
|
||||
+ "delivery-source:orders-" + suffix + "\", \"tags\": {\"env\": \"foreign\"}}").then().statusCode(400);
|
||||
logs("ListTagsForResource", "{\"resourceArn\": \"" + PREFIX + "delivery-source:orders-" + suffix + "\"}")
|
||||
.then().body("tags.env", equalTo("local"));
|
||||
|
||||
// In use: neither end can go while the delivery pairs them, and a second delivery is refused.
|
||||
logs("CreateDelivery", """
|
||||
{"deliverySourceName": "orders-%s", "deliveryDestinationArn": "%s"}
|
||||
""".formatted(suffix, destinationArn)).then().statusCode(400)
|
||||
.body("__type", equalTo("ConflictException"));
|
||||
logs("DeleteDeliverySource", "{\"name\": \"orders-" + suffix + "\"}").then().statusCode(400)
|
||||
.body("__type", equalTo("ConflictException"));
|
||||
logs("DeleteDeliveryDestination", "{\"name\": \"orders-logs-" + suffix + "\"}").then().statusCode(400)
|
||||
.body("__type", equalTo("ConflictException"));
|
||||
|
||||
logs("DeleteDelivery", "{\"id\": \"" + id + "\"}").then().statusCode(200);
|
||||
logs("DeleteDeliverySource", "{\"name\": \"orders-" + suffix + "\"}").then().statusCode(200);
|
||||
logs("DeleteDeliveryDestination", "{\"name\": \"orders-logs-" + suffix + "\"}").then().statusCode(200);
|
||||
logs("DescribeDeliverySources", "{}").then().statusCode(200)
|
||||
.body("deliverySources.name", not(hasItem("orders-" + suffix)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeCallsNarrowToTheNamedSourcesDestinationsAndDeliveries() {
|
||||
String suffix = UUID.randomUUID().toString().substring(0, 8);
|
||||
String[] ids = new String[2];
|
||||
for (int i = 0; i < 2; i++) {
|
||||
String bus = "arn:aws:events:us-east-1:000000000000:event-bus/filter-" + i + "-" + suffix;
|
||||
logs("PutDeliverySource", """
|
||||
{"name": "filter-%d-%s", "resourceArn": "%s", "logType": "ERROR_LOGS"}
|
||||
""".formatted(i, suffix, bus)).then().statusCode(200);
|
||||
String destination = logs("PutDeliveryDestination", """
|
||||
{"name": "filter-%d-%s", "deliveryDestinationConfiguration":
|
||||
{"destinationResourceArn": "%slog-group:/aws/events/filter-%d-%s"}}
|
||||
""".formatted(i, suffix, PREFIX, i, suffix)).then().statusCode(200)
|
||||
.extract().path("deliveryDestination.arn");
|
||||
ids[i] = logs("CreateDelivery", """
|
||||
{"deliverySourceName": "filter-%d-%s", "deliveryDestinationArn": "%s"}
|
||||
""".formatted(i, suffix, destination)).then().statusCode(200).extract().path("delivery.id");
|
||||
}
|
||||
|
||||
logs("DescribeDeliverySources", "{\"resourceArns\": [\"arn:aws:events:us-east-1:000000000000:event-bus/filter-1-"
|
||||
+ suffix + "\"]}").then().statusCode(200)
|
||||
.body("deliverySources.name", contains("filter-1-" + suffix));
|
||||
logs("DescribeDeliveryDestinations", "{\"names\": [\"filter-0-" + suffix + "\", \"missing-" + suffix + "\"]}")
|
||||
.then().statusCode(200)
|
||||
.body("deliveryDestinations.name", contains("filter-0-" + suffix));
|
||||
logs("DescribeDeliveries", "{\"deliverySourceNames\": [\"filter-1-" + suffix + "\"]}").then().statusCode(200)
|
||||
.body("deliveries.id", contains(ids[1]));
|
||||
logs("DescribeDeliveries", "{\"deliverySourceNames\": [\"missing-" + suffix + "\"]}").then().statusCode(200)
|
||||
.body("deliveries", empty());
|
||||
|
||||
for (int i = 0; i < 2; i++) {
|
||||
logs("DeleteDelivery", "{\"id\": \"" + ids[i] + "\"}").then().statusCode(200);
|
||||
logs("DeleteDeliverySource", "{\"name\": \"filter-" + i + "-" + suffix + "\"}").then().statusCode(200);
|
||||
logs("DeleteDeliveryDestination", "{\"name\": \"filter-" + i + "-" + suffix + "\"}").then().statusCode(200);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void unknownResourcesAndInvalidRequestsAreRefusedWithAwsMessages() {
|
||||
refused("GetDeliverySource", "{\"name\": \"no-such-source\"}", "ResourceNotFoundException",
|
||||
"Requested Delivery Source does not exist in this account.");
|
||||
refused("GetDeliveryDestination", "{\"name\": \"no-such-destination\"}", "ResourceNotFoundException",
|
||||
"Requested Delivery Destination does not exist in this account.");
|
||||
refused("GetDelivery", "{\"id\": \"AAAAAAAAAAAAAAAA\"}", "ResourceNotFoundException",
|
||||
"Requested Delivery does not exist in this account.");
|
||||
refused("DeleteDelivery", "{\"id\": \"AAAAAAAAAAAAAAAA\"}", "ResourceNotFoundException",
|
||||
"Requested Delivery does not exist in this account.");
|
||||
refused("ListTagsForResource", "{\"resourceArn\": \"" + PREFIX + "delivery:AAAAAAAAAAAAAAAA\"}",
|
||||
"ResourceNotFoundException", "Requested Delivery does not exist in this account.");
|
||||
refused("DescribeDeliverySources", "{\"limit\": 51}", "ValidationException",
|
||||
"1 validation error detected: Value at 'limit' failed to satisfy constraint: Member must have value "
|
||||
+ "less than or equal to 50");
|
||||
refused("DescribeDeliverySources", "{\"nextToken\": \"bogus\"}", "ValidationException",
|
||||
"Invalid Next Token.");
|
||||
|
||||
logs("PutDeliveryDestination", """
|
||||
{"name": "bad-destination", "deliveryDestinationConfiguration":
|
||||
{"destinationResourceArn": "arn:aws:sqs:us-east-1:000000000000:queue"}}
|
||||
""").then().statusCode(400).body("__type", equalTo("ValidationException"));
|
||||
logs("PutDeliveryDestination", "{\"name\": \"traces\", \"deliveryDestinationType\": \"XRAY\"}")
|
||||
.then().statusCode(200)
|
||||
.body("deliveryDestination.deliveryDestinationType", equalTo("XRAY"))
|
||||
.body("deliveryDestination.deliveryDestinationConfiguration", nullValue());
|
||||
logs("DeleteDeliveryDestination", "{\"name\": \"traces\"}").then().statusCode(200);
|
||||
refused("PutDeliverySource", "{\"name\": \"bad name\", \"resourceArn\": \"x\", \"logType\": \"ERROR_LOGS\"}",
|
||||
"ValidationException", "1 validation error detected: Value at 'name' failed to satisfy constraint: "
|
||||
+ "Member must satisfy regular expression pattern: [\\w-]*");
|
||||
refused("PutDeliverySource", "{\"name\": \"source\", \"logType\": \"ERROR_LOGS\"}", "ValidationException",
|
||||
"1 validation error detected: Value at 'resourceArn' failed to satisfy constraint: "
|
||||
+ "Member must not be null");
|
||||
refused("GetDelivery", "{\"id\": \"a-b\"}", "ValidationException",
|
||||
"1 validation error detected: Value at 'id' failed to satisfy constraint: "
|
||||
+ "Member must satisfy regular expression pattern: ^[0-9A-Za-z]+$");
|
||||
refused("DescribeDeliveries", "{\"deliverySourceNames\": [\"bad name\"]}", "ValidationException",
|
||||
"1 validation error detected: Value at 'deliverySourceNames' failed to satisfy constraint: "
|
||||
+ "Member must satisfy constraint: [Member must have length less than or equal to 60, "
|
||||
+ "Member must have length greater than or equal to 1, "
|
||||
+ "Member must satisfy regular expression pattern: [\\w-]*]");
|
||||
logs("CreateDelivery", "{\"deliverySourceName\": \"no-such-source\", \"deliveryDestinationArn\": \""
|
||||
+ PREFIX + "delivery-destination:no-such-destination\"}").then().statusCode(400)
|
||||
.body("__type", equalTo("ResourceNotFoundException"))
|
||||
.body("message", notNullValue());
|
||||
}
|
||||
|
||||
private static void refused(String action, String body, String type, String message) {
|
||||
logs(action, body).then().statusCode(400).body("__type", equalTo(type)).body("message", equalTo(message));
|
||||
}
|
||||
}
|
||||
+1
-5
@@ -16,6 +16,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import static io.github.hectorvent.floci.testing.LogsRequests.logs;
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
@@ -148,9 +149,4 @@ class CloudWatchLogsGroupPaginationIntegrationTest {
|
||||
groups.add(group);
|
||||
}
|
||||
}
|
||||
|
||||
private Response logs(String action, Map<String, ?> body) {
|
||||
return given().contentType("application/x-amz-json-1.1")
|
||||
.header("X-Amz-Target", "Logs_20140328." + action).body(body).post("/");
|
||||
}
|
||||
}
|
||||
+1
-7
@@ -12,6 +12,7 @@ import java.time.Instant;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static io.github.hectorvent.floci.testing.LogsRequests.logs;
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.awaitility.Awaitility.await;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
@@ -30,8 +31,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
@QuarkusTest
|
||||
class CloudWatchLogsMetricFilterIntegrationTest {
|
||||
|
||||
private static final String LOGS_CONTENT_TYPE = "application/x-amz-json-1.1";
|
||||
private static final String LOGS_AUTH = "AWS4-HMAC-SHA256 Credential=AKID/20260908/us-east-1/logs/aws4_request";
|
||||
private static final String CW_CONTENT_TYPE = "application/x-amz-json-1.0";
|
||||
private static final String CW_AUTH = "AWS4-HMAC-SHA256 Credential=AKID/20260908/us-east-1/monitoring/aws4_request";
|
||||
|
||||
@@ -40,11 +39,6 @@ class CloudWatchLogsMetricFilterIntegrationTest {
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
}
|
||||
|
||||
private static Response logs(String action, String body) {
|
||||
return given().contentType(LOGS_CONTENT_TYPE).header("Authorization", LOGS_AUTH)
|
||||
.header("X-Amz-Target", "Logs_20140328." + action).body(body).post("/");
|
||||
}
|
||||
|
||||
private static Response cloudWatch(String action, String body) {
|
||||
return given().contentType(CW_CONTENT_TYPE).header("Authorization", CW_AUTH)
|
||||
.header("X-Amz-Target", "GraniteServiceVersion20100801." + action).body(body).post("/");
|
||||
|
||||
+11
-14
@@ -17,6 +17,7 @@ import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import static io.github.hectorvent.floci.testing.LogsRequests.logs;
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.awaitility.Awaitility.await;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
@@ -32,7 +33,8 @@ class CloudWatchLogsMetricFilterRetryIntegrationTest {
|
||||
|
||||
@InjectSpy CloudWatchMetricsService metrics;
|
||||
@Inject CloudWatchLogsMetricFilterService publications;
|
||||
private static final String AUTH = "AWS4-HMAC-SHA256 Credential=AKID/20260916/eu-west-1/logs/aws4_request";
|
||||
private static final String REGION = "eu-west-1";
|
||||
private static final String AUTH = "AWS4-HMAC-SHA256 Credential=AKID/20260916/" + REGION + "/monitoring/aws4_request";
|
||||
private static final long TIME = 1_700_000_040_000L;
|
||||
|
||||
@BeforeAll
|
||||
@@ -60,7 +62,7 @@ class CloudWatchLogsMetricFilterRetryIntegrationTest {
|
||||
.body("Datapoints[0].Sum", equalTo(7.0f)).body("Datapoints[0].SampleCount", equalTo(1.0f));
|
||||
publications.retryPending();
|
||||
statistics(group).then().body("Datapoints[0].SampleCount", equalTo(1.0f));
|
||||
logs("DeleteLogGroup", "{\"logGroupName\":\"" + group + "\"}").then().statusCode(200);
|
||||
logs(REGION, "DeleteLogGroup", "{\"logGroupName\":\"" + group + "\"}").then().statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -80,33 +82,28 @@ class CloudWatchLogsMetricFilterRetryIntegrationTest {
|
||||
ingest(group);
|
||||
await().atMost(Duration.ofSeconds(10)).untilAsserted(() -> statistics(group).then().statusCode(200)
|
||||
.body("Datapoints[0].Sum", equalTo(7.0f)).body("Datapoints[0].SampleCount", equalTo(1.0f)));
|
||||
logs("DeleteLogGroup", "{\"logGroupName\":\"" + group + "\"}").then().statusCode(200);
|
||||
logs(REGION, "DeleteLogGroup", "{\"logGroupName\":\"" + group + "\"}").then().statusCode(200);
|
||||
}
|
||||
|
||||
private static void create(String group) {
|
||||
logs("CreateLogGroup", "{\"logGroupName\":\"" + group + "\"}").then().statusCode(200);
|
||||
logs("CreateLogStream", "{\"logGroupName\":\"" + group + "\",\"logStreamName\":\"s\"}").then().statusCode(200);
|
||||
logs("PutMetricFilter", """
|
||||
logs(REGION, "CreateLogGroup", "{\"logGroupName\":\"" + group + "\"}").then().statusCode(200);
|
||||
logs(REGION, "CreateLogStream", "{\"logGroupName\":\"" + group + "\",\"logStreamName\":\"s\"}").then().statusCode(200);
|
||||
logs(REGION, "PutMetricFilter", """
|
||||
{"logGroupName":"%s","filterName":"retry","filterPattern":"ERROR",
|
||||
"metricTransformations":[{"metricName":"Value","metricNamespace":"%s","metricValue":"3","defaultValue":7}]}
|
||||
""".formatted(group, group)).then().statusCode(200);
|
||||
}
|
||||
|
||||
private static void ingest(String group) {
|
||||
logs("PutLogEvents", """
|
||||
logs(REGION, "PutLogEvents", """
|
||||
{"logGroupName":"%s","logStreamName":"s","logEvents":[{"timestamp":%d,"message":"INFO"}]}
|
||||
""".formatted(group, TIME)).then().statusCode(200);
|
||||
logs("GetLogEvents", "{\"logGroupName\":\"" + group + "\",\"logStreamName\":\"s\"}")
|
||||
logs(REGION, "GetLogEvents", "{\"logGroupName\":\"" + group + "\",\"logStreamName\":\"s\"}")
|
||||
.then().statusCode(200).body("events", hasSize(1));
|
||||
}
|
||||
|
||||
private static Response logs(String action, String body) {
|
||||
return given().contentType("application/x-amz-json-1.1").header("Authorization", AUTH)
|
||||
.header("X-Amz-Target", "Logs_20140328." + action).body(body).post("/");
|
||||
}
|
||||
|
||||
private static Response statistics(String namespace) {
|
||||
return given().contentType("application/x-amz-json-1.0").header("Authorization", AUTH.replace("/logs/", "/monitoring/"))
|
||||
return given().contentType("application/x-amz-json-1.0").header("Authorization", AUTH)
|
||||
.header("X-Amz-Target", "GraniteServiceVersion20100801.GetMetricStatistics").body("""
|
||||
{"Namespace":"%s","MetricName":"Value","Period":60,"StartTime":%d,"EndTime":%d,
|
||||
"Statistics":["Sum","SampleCount"]}
|
||||
|
||||
@@ -785,6 +785,37 @@ class ResourceArnBuilderTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void deliveryActionsAreAuthorizedOnTheSourceDestinationOrDeliveryTheyName() {
|
||||
String prefix = "arn:aws:logs:us-east-1:" + ACCOUNT + ":";
|
||||
for (String action : List.of("logs:PutDeliverySource", "logs:GetDeliverySource", "logs:DeleteDeliverySource")) {
|
||||
setJsonBody("{\"name\":\"bus-source\"}");
|
||||
assertEquals(List.of(prefix + "delivery-source:bus-source"),
|
||||
builder.buildLogResources(action, ctx, "us-east-1", ACCOUNT, "aws"));
|
||||
}
|
||||
for (String action : List.of("logs:PutDeliveryDestination", "logs:GetDeliveryDestination",
|
||||
"logs:DeleteDeliveryDestination")) {
|
||||
setJsonBody("{\"name\":\"bus-logs\"}");
|
||||
assertEquals(List.of(prefix + "delivery-destination:bus-logs"),
|
||||
builder.buildLogResources(action, ctx, "us-east-1", ACCOUNT, "aws"));
|
||||
}
|
||||
for (String action : List.of("logs:GetDelivery", "logs:DeleteDelivery", "logs:UpdateDeliveryConfiguration")) {
|
||||
setJsonBody("{\"id\":\"AbCdEfGh12345678\"}");
|
||||
assertEquals(List.of(prefix + "delivery:AbCdEfGh12345678"),
|
||||
builder.buildLogResources(action, ctx, "us-east-1", ACCOUNT, "aws"));
|
||||
}
|
||||
setJsonBody("{\"deliverySourceName\":\"bus-source\",\"deliveryDestinationArn\":\""
|
||||
+ prefix + "delivery-destination:bus-logs\"}");
|
||||
assertEquals(List.of(prefix + "delivery-destination:bus-logs", prefix + "delivery:*",
|
||||
prefix + "delivery-source:bus-source"),
|
||||
builder.buildLogResources("logs:CreateDelivery", ctx, "us-east-1", ACCOUNT, "aws"));
|
||||
for (String action : List.of("logs:DescribeDeliverySources", "logs:DescribeDeliveryDestinations",
|
||||
"logs:DescribeDeliveries")) {
|
||||
setJsonBody("{}");
|
||||
assertEquals(List.of("*"), builder.buildLogResources(action, ctx, "us-east-1", ACCOUNT, "aws"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void excludedLogsActionsKeepWildcardResources() {
|
||||
for (String action : List.of("logs:PutLogEvents")) {
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package io.github.hectorvent.floci.testing;
|
||||
|
||||
import io.restassured.response.Response;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
|
||||
/** Sends CloudWatch Logs JSON 1.1 requests, signed for {@code us-east-1} unless a Region is given. */
|
||||
public final class LogsRequests {
|
||||
private LogsRequests() {}
|
||||
|
||||
public static Response logs(String action, String body) {
|
||||
return logs("us-east-1", action, body);
|
||||
}
|
||||
|
||||
public static Response logs(String action, Map<String, ?> body) {
|
||||
return request("us-east-1", action).body(body).post("/");
|
||||
}
|
||||
|
||||
public static Response logs(String region, String action, String body) {
|
||||
return request(region, action).body(body).post("/");
|
||||
}
|
||||
|
||||
private static RequestSpecification request(String region, String action) {
|
||||
return given().contentType("application/x-amz-json-1.1")
|
||||
.header("Authorization", "AWS4-HMAC-SHA256 Credential=AKID/20261103/" + region + "/logs/aws4_request")
|
||||
.header("X-Amz-Target", "Logs_20140328." + action);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user