mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(logs): support log group deletion protection (#2256)
* fix(logs): accept log group deletion protection lifecycle * feat(logs): support log group deletion protection
This commit is contained in:
1 parent
6ca7d44af0
commit
4215006fe2
7 files changed
+278
-3
No files matched your search
+97
@@ -16,6 +16,7 @@ import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@@ -98,6 +99,102 @@ class CloudWatchLogsHandlerTest {
|
||||
assertEquals(GROUP, ((JsonNode) response.getEntity()).path("logGroupIdentifier").asText());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createLogGroupWithDeletionProtectionIsReturnedByDescribeLogGroups() {
|
||||
String protectedGroup = GROUP + "-created-protected";
|
||||
ObjectNode create = MAPPER.createObjectNode();
|
||||
create.put("logGroupName", protectedGroup);
|
||||
create.put("deletionProtectionEnabled", true);
|
||||
|
||||
handler.handle("CreateLogGroup", create, REGION);
|
||||
|
||||
ObjectNode describe = MAPPER.createObjectNode();
|
||||
describe.put("logGroupNamePrefix", protectedGroup);
|
||||
JsonNode group = ((JsonNode) handler.handle("DescribeLogGroups", describe, REGION).getEntity())
|
||||
.path("logGroups").get(0);
|
||||
assertEquals(protectedGroup, group.path("logGroupName").asText());
|
||||
assertTrue(group.path("deletionProtectionEnabled").asBoolean());
|
||||
}
|
||||
|
||||
@Test
|
||||
void putLogGroupDeletionProtectionPersistsByName() {
|
||||
ObjectNode request = MAPPER.createObjectNode();
|
||||
request.put("logGroupIdentifier", GROUP);
|
||||
request.put("deletionProtectionEnabled", true);
|
||||
|
||||
Response response = handler.handle("PutLogGroupDeletionProtection", request, REGION);
|
||||
|
||||
assertEquals(200, response.getStatus());
|
||||
assertTrue(service.describeLogGroups(GROUP, REGION).getFirst().isDeletionProtectionEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
void putLogGroupDeletionProtectionAcceptsArnIdentifier() {
|
||||
ObjectNode request = MAPPER.createObjectNode();
|
||||
request.put("logGroupIdentifier", GROUP_ARN);
|
||||
request.put("deletionProtectionEnabled", true);
|
||||
|
||||
handler.handle("PutLogGroupDeletionProtection", request, REGION);
|
||||
|
||||
assertTrue(service.describeLogGroups(GROUP, REGION).getFirst().isDeletionProtectionEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
void putLogGroupDeletionProtectionRequiresIdentifier() {
|
||||
ObjectNode request = MAPPER.createObjectNode();
|
||||
request.put("deletionProtectionEnabled", true);
|
||||
|
||||
AwsException error = assertThrows(AwsException.class,
|
||||
() -> handler.handle("PutLogGroupDeletionProtection", request, REGION));
|
||||
|
||||
assertEquals("InvalidParameterException", error.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void putLogGroupDeletionProtectionRequiresBoolean() {
|
||||
ObjectNode request = MAPPER.createObjectNode();
|
||||
request.put("logGroupIdentifier", GROUP);
|
||||
|
||||
AwsException error = assertThrows(AwsException.class,
|
||||
() -> handler.handle("PutLogGroupDeletionProtection", request, REGION));
|
||||
|
||||
assertEquals("InvalidParameterException", error.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void putLogGroupDeletionProtectionRequiresExistingGroup() {
|
||||
ObjectNode request = MAPPER.createObjectNode();
|
||||
request.put("logGroupIdentifier", "/missing");
|
||||
request.put("deletionProtectionEnabled", true);
|
||||
|
||||
AwsException error = assertThrows(AwsException.class,
|
||||
() -> handler.handle("PutLogGroupDeletionProtection", request, REGION));
|
||||
|
||||
assertEquals("ResourceNotFoundException", error.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void protectedLogGroupCannotBeDeletedUntilProtectionIsDisabled() {
|
||||
ObjectNode protection = MAPPER.createObjectNode();
|
||||
protection.put("logGroupIdentifier", GROUP);
|
||||
protection.put("deletionProtectionEnabled", true);
|
||||
handler.handle("PutLogGroupDeletionProtection", protection, REGION);
|
||||
|
||||
ObjectNode deletion = MAPPER.createObjectNode();
|
||||
deletion.put("logGroupName", GROUP);
|
||||
AwsException error = assertThrows(AwsException.class,
|
||||
() -> handler.handle("DeleteLogGroup", deletion, REGION));
|
||||
assertEquals("ValidationException", error.getErrorCode());
|
||||
assertThat(error.getMessage(), containsString("Disable deletion protection"));
|
||||
|
||||
protection.put("deletionProtectionEnabled", false);
|
||||
handler.handle("PutLogGroupDeletionProtection", protection, REGION);
|
||||
Response response = handler.handle("DeleteLogGroup", deletion, REGION);
|
||||
|
||||
assertEquals(200, response.getStatus());
|
||||
assertFalse(service.logGroupExists(GROUP, REGION));
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeLogStreamsByLogGroupIdentifierArnWithWildcardSuffix() {
|
||||
ObjectNode request = MAPPER.createObjectNode();
|
||||
|
||||
+33
-1
@@ -43,6 +43,15 @@ class CloudWatchLogsServiceTest {
|
||||
List<LogGroup> groups = service.describeLogGroups(null, REGION);
|
||||
assertEquals(1, groups.size());
|
||||
assertEquals("/app/logs", groups.getFirst().getLogGroupName());
|
||||
assertFalse(groups.getFirst().isDeletionProtectionEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createLogGroupWithDeletionProtectionEnabled() {
|
||||
service.createLogGroup("/app/protected", null, null, true, REGION);
|
||||
|
||||
LogGroup group = service.describeLogGroups("/app/protected", REGION).getFirst();
|
||||
assertTrue(group.isDeletionProtectionEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -72,6 +81,29 @@ class CloudWatchLogsServiceTest {
|
||||
service.deleteLogGroup("/missing", REGION));
|
||||
}
|
||||
|
||||
@Test
|
||||
void protectedLogGroupMustBeDisabledBeforeDeletion() {
|
||||
service.createLogGroup("/app/protected", null, null, true, REGION);
|
||||
|
||||
AwsException error = assertThrows(AwsException.class,
|
||||
() -> service.deleteLogGroup("/app/protected", REGION));
|
||||
assertEquals("ValidationException", error.getErrorCode());
|
||||
assertTrue(service.logGroupExists("/app/protected", REGION));
|
||||
|
||||
service.putLogGroupDeletionProtection("/app/protected", false, REGION);
|
||||
service.deleteLogGroup("/app/protected", REGION);
|
||||
|
||||
assertFalse(service.logGroupExists("/app/protected", REGION));
|
||||
}
|
||||
|
||||
@Test
|
||||
void putLogGroupDeletionProtectionRequiresExistingGroup() {
|
||||
AwsException error = assertThrows(AwsException.class,
|
||||
() -> service.putLogGroupDeletionProtection("/missing", true, REGION));
|
||||
|
||||
assertEquals("ResourceNotFoundException", error.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeLogGroupsWithPrefix() {
|
||||
service.createLogGroup("/app/alpha", null, null, REGION);
|
||||
@@ -503,4 +535,4 @@ class CloudWatchLogsServiceTest {
|
||||
assertEquals(0, atStart.events().size());
|
||||
assertEquals("b/0", atStart.nextBackwardToken(), "token must echo back to signal start of stream");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user