mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(redshift): accept s3table log destination and reject mutual snapshot restore params (#4340)
* fix(redshift): accept s3table log destination and reject mutual snapshot restore params Closes #4242 * fix(redshift): preserve S3-table logging configuration and report status Pass S3TableKmsKeyId and S3TableGranularity through EnableLogging, store them on Cluster, and serialize S3Tables in LoggingStatus responses. * fix(redshift): validate S3-table logging settings * fix(redshift): complete S3 table logging status
This commit is contained in:
1 parent
41d07f6e3b
commit
6bdf14210e
7 files changed
+343
-7
No files matched your search
+167
-1
@@ -5,6 +5,7 @@ import io.github.hectorvent.floci.services.redshift.container.RedshiftContainerM
|
||||
import io.quarkus.test.InjectMock;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.path.xml.XmlPath;
|
||||
import jakarta.inject.Inject;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -47,6 +48,9 @@ public class RedshiftOperationsTest {
|
||||
@InjectMock
|
||||
RedshiftContainerManager containerManager;
|
||||
|
||||
@Inject
|
||||
RedshiftService service;
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void parameterGroupLifecycle() {
|
||||
@@ -210,7 +214,154 @@ public class RedshiftOperationsTest {
|
||||
.statusCode(200)
|
||||
.body(not(containsString("redshift-copy")));
|
||||
|
||||
// 1e. Static discovery APIs
|
||||
// 1e. Logging: EnableLogging with s3table destination preserves its publishing status
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.formParam("Action", "EnableLogging")
|
||||
.formParam("ClusterIdentifier", "cluster-src")
|
||||
.formParam("LogDestinationType", "s3table")
|
||||
.formParam("S3TableGranularity", "cluster")
|
||||
.formParam("S3TableKmsKeyId", "test-kms-key")
|
||||
.formParam("LogExports.member.1", "sys_query_history")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.contentType("application/xml")
|
||||
.body(containsString("<LoggingEnabled>true</LoggingEnabled>"))
|
||||
.body(containsString("<LogDestinationType>s3table</LogDestinationType>"))
|
||||
.body(containsString("<S3Tables><S3Tables><member>sys_query_history</member></S3Tables>"))
|
||||
.body(containsString("<S3TableGranularity>cluster</S3TableGranularity>"))
|
||||
.body(containsString("<EnabledAll>false</EnabledAll>"));
|
||||
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.formParam("Action", "DescribeLoggingStatus")
|
||||
.formParam("ClusterIdentifier", "cluster-src")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.contentType("application/xml")
|
||||
.body(containsString("<LoggingEnabled>true</LoggingEnabled>"))
|
||||
.body(containsString("<LogDestinationType>s3table</LogDestinationType>"))
|
||||
.body(containsString("<S3Tables><S3Tables><member>sys_query_history</member></S3Tables>"))
|
||||
.body(containsString("<S3TableGranularity>cluster</S3TableGranularity>"))
|
||||
.body(containsString("<EnabledAll>false</EnabledAll>"))
|
||||
.body(not(containsString("<S3TableKmsKeyId>")));
|
||||
|
||||
assertEquals("test-kms-key", service.describeLoggingStatus("cluster-src").getLoggingS3TableKmsKeyId());
|
||||
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.formParam("Action", "EnableLogging")
|
||||
.formParam("ClusterIdentifier", "cluster-src")
|
||||
.formParam("LogDestinationType", "s3table")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<S3Tables><EnabledAll>true</EnabledAll></S3Tables>"))
|
||||
.body(not(containsString("<S3Tables></S3Tables>")))
|
||||
.body(not(containsString("<S3TableGranularity>")));
|
||||
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.formParam("Action", "DisableLogging")
|
||||
.formParam("ClusterIdentifier", "cluster-src")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.contentType("application/xml")
|
||||
.body(containsString("<LoggingEnabled>false</LoggingEnabled>"))
|
||||
.body(not(containsString("<S3Tables>")));
|
||||
|
||||
// 1e.1 S3-table settings are invalid for a non-table destination
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.formParam("Action", "EnableLogging")
|
||||
.formParam("ClusterIdentifier", "cluster-src")
|
||||
.formParam("LogDestinationType", "cloudwatch")
|
||||
.formParam("S3TableGranularity", "cluster")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.contentType("application/xml")
|
||||
.body(containsString("<Code>InvalidParameterCombination</Code>"));
|
||||
|
||||
// 1e.1.1 Only AWS-supported S3-table granularity values are accepted
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.formParam("Action", "EnableLogging")
|
||||
.formParam("ClusterIdentifier", "cluster-src")
|
||||
.formParam("LogDestinationType", "s3table")
|
||||
.formParam("S3TableGranularity", "daily")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.contentType("application/xml")
|
||||
.body(containsString("<Code>InvalidParameterValue</Code>"));
|
||||
|
||||
// 1e.2 Non-table logging status must omit the S3-table status block
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.formParam("Action", "EnableLogging")
|
||||
.formParam("ClusterIdentifier", "cluster-src")
|
||||
.formParam("LogDestinationType", "cloudwatch")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<LogDestinationType>cloudwatch</LogDestinationType>"))
|
||||
.body(not(containsString("<S3Tables>")));
|
||||
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.formParam("Action", "DisableLogging")
|
||||
.formParam("ClusterIdentifier", "cluster-src")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<LoggingEnabled>false</LoggingEnabled>"));
|
||||
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.formParam("Action", "DescribeLoggingStatus")
|
||||
.formParam("ClusterIdentifier", "cluster-src")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<LoggingEnabled>false</LoggingEnabled>"))
|
||||
.body(not(containsString("<S3Tables>")));
|
||||
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.formParam("Action", "DescribeLoggingStatus")
|
||||
.formParam("ClusterIdentifier", "cluster-src")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.contentType("application/xml")
|
||||
.body(containsString("<LoggingEnabled>false</LoggingEnabled>"))
|
||||
.body(not(containsString("<S3Tables>")));
|
||||
|
||||
// 1f. Static discovery APIs
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
@@ -274,6 +425,21 @@ public class RedshiftOperationsTest {
|
||||
.body(containsString("<ClusterIdentifier>cluster-src</ClusterIdentifier>"))
|
||||
.body(containsString("<ClusterStatus>deleting</ClusterStatus>"));
|
||||
|
||||
// 4b. RestoreFromClusterSnapshot rejects carrying both SnapshotIdentifier and SnapshotArn
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.formParam("Action", "RestoreFromClusterSnapshot")
|
||||
.formParam("ClusterIdentifier", "cluster-restored-invalid")
|
||||
.formParam("SnapshotIdentifier", "snap-test-1")
|
||||
.formParam("SnapshotArn", "arn:aws:redshift:us-east-1:000000000000:snapshot:cluster-src/snap-test-1")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.contentType("application/xml")
|
||||
.body(containsString("<Code>InvalidParameterCombination</Code>"));
|
||||
|
||||
// 5. RestoreFromClusterSnapshot
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
|
||||
+64
-1
@@ -345,6 +345,20 @@ class RedshiftQueryHandlerTest {
|
||||
verify(service, never()).restoreFromClusterSnapshot(any(), any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void restoreFromClusterSnapshotWithBothIdentifierAndArnIs400() {
|
||||
MultivaluedMap<String, String> params = new MultivaluedHashMap<>();
|
||||
params.putSingle("ClusterIdentifier", "restored-cluster");
|
||||
params.putSingle("SnapshotIdentifier", "snap-a");
|
||||
params.putSingle("SnapshotArn", "arn:aws:redshift:us-east-1:acc:snapshot:src/snap-b");
|
||||
|
||||
AwsException ex = assertThrows(AwsException.class,
|
||||
() -> handler.handle("RestoreFromClusterSnapshot", params, "auth"));
|
||||
assertEquals("InvalidParameterCombination", ex.getErrorCode());
|
||||
assertEquals(400, ex.getHttpStatus());
|
||||
verify(service, never()).restoreFromClusterSnapshot(any(), any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void clusterXmlCarriesDefaultParameterGroupAndMultiAZ() {
|
||||
MultivaluedMap<String, String> params = new MultivaluedHashMap<>();
|
||||
@@ -644,6 +658,24 @@ class RedshiftQueryHandlerTest {
|
||||
assertTrue(xml.contains("<S3KeyPrefix>logs/</S3KeyPrefix>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeS3TableLoggingStatusIncludesEnabledAllWithoutGranularity() {
|
||||
MultivaluedMap<String, String> params = new MultivaluedHashMap<>();
|
||||
params.putSingle("ClusterIdentifier", "test-cluster");
|
||||
|
||||
Cluster cluster = new Cluster();
|
||||
cluster.setClusterIdentifier("test-cluster");
|
||||
cluster.setLoggingEnabled(true);
|
||||
cluster.setLoggingDestinationType("s3table");
|
||||
when(service.describeLoggingStatus("test-cluster")).thenReturn(cluster);
|
||||
|
||||
Response response = handler.handle("DescribeLoggingStatus", params);
|
||||
|
||||
String xml = (String) response.getEntity();
|
||||
assertTrue(xml.contains("<S3Tables><EnabledAll>true</EnabledAll></S3Tables>"));
|
||||
assertFalse(xml.contains("<S3Tables></S3Tables>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeLoggingStatusRequiresClusterIdentifier() {
|
||||
MultivaluedMap<String, String> params = new MultivaluedHashMap<>();
|
||||
@@ -666,7 +698,7 @@ class RedshiftQueryHandlerTest {
|
||||
cluster.setLoggingEnabled(true);
|
||||
cluster.setLoggingBucketName("my-bucket");
|
||||
cluster.setLoggingS3KeyPrefix("logs/");
|
||||
when(service.enableLogging("test-cluster", "my-bucket", "logs/", null, List.of())).thenReturn(cluster);
|
||||
when(service.enableLogging("test-cluster", "my-bucket", "logs/", null, List.of(), null, null)).thenReturn(cluster);
|
||||
|
||||
Response response = handler.handle("EnableLogging", params);
|
||||
assertEquals(200, response.getStatus());
|
||||
@@ -675,6 +707,37 @@ class RedshiftQueryHandlerTest {
|
||||
assertTrue(xml.contains("<LoggingEnabled>true</LoggingEnabled>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void enableLoggingS3TableWithGranularityAndKmsKey() {
|
||||
MultivaluedMap<String, String> params = new MultivaluedHashMap<>();
|
||||
params.putSingle("ClusterIdentifier", "test-cluster");
|
||||
params.putSingle("LogDestinationType", "s3table");
|
||||
params.putSingle("S3TableKmsKeyId", "my-kms-key");
|
||||
params.putSingle("S3TableGranularity", "cluster");
|
||||
params.putSingle("LogExports.member.1", "sys_query_history");
|
||||
|
||||
Cluster cluster = new Cluster();
|
||||
cluster.setClusterIdentifier("test-cluster");
|
||||
cluster.setLoggingEnabled(true);
|
||||
cluster.setLoggingDestinationType("s3table");
|
||||
cluster.setLoggingS3TableKmsKeyId("my-kms-key");
|
||||
cluster.setLoggingS3TableGranularity("cluster");
|
||||
cluster.setLoggingExports(List.of("sys_query_history"));
|
||||
when(service.enableLogging("test-cluster", null, null, "s3table", List.of("sys_query_history"),
|
||||
"my-kms-key", "cluster"))
|
||||
.thenReturn(cluster);
|
||||
|
||||
Response response = handler.handle("EnableLogging", params);
|
||||
assertEquals(200, response.getStatus());
|
||||
String xml = (String) response.getEntity();
|
||||
assertTrue(xml.contains("<EnableLoggingResult>"));
|
||||
assertTrue(xml.contains("<LoggingEnabled>true</LoggingEnabled>"));
|
||||
assertTrue(xml.contains("<LogDestinationType>s3table</LogDestinationType>"));
|
||||
assertTrue(xml.contains("<S3Tables><S3Tables><member>sys_query_history</member></S3Tables>"));
|
||||
assertTrue(xml.contains("<EnabledAll>false</EnabledAll>"));
|
||||
assertTrue(xml.contains("<S3TableGranularity>cluster</S3TableGranularity>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void disableLogging() {
|
||||
MultivaluedMap<String, String> params = new MultivaluedHashMap<>();
|
||||
|
||||
@@ -929,6 +929,63 @@ class RedshiftServiceTest {
|
||||
assertEquals(List.of("connectionlog"), result.getLoggingExports());
|
||||
}
|
||||
|
||||
@Test
|
||||
void enableLoggingS3TableDoesNotRequireBucketName() {
|
||||
Cluster cluster = new Cluster();
|
||||
cluster.setClusterIdentifier("my-cluster");
|
||||
when(clusterBackend.get("my-cluster")).thenReturn(Optional.of(cluster));
|
||||
|
||||
Cluster result = service.enableLogging("my-cluster", null, null, "s3table", null, "my-kms-key", "account");
|
||||
assertTrue(result.isLoggingEnabled());
|
||||
assertEquals("s3table", result.getLoggingDestinationType());
|
||||
assertNull(result.getLoggingBucketName());
|
||||
assertEquals("my-kms-key", result.getLoggingS3TableKmsKeyId());
|
||||
assertEquals("account", result.getLoggingS3TableGranularity());
|
||||
}
|
||||
|
||||
@Test
|
||||
void enableLoggingRejectsInvalidS3TableGranularity() {
|
||||
Cluster cluster = new Cluster();
|
||||
cluster.setClusterIdentifier("my-cluster");
|
||||
when(clusterBackend.get("my-cluster")).thenReturn(Optional.of(cluster));
|
||||
|
||||
AwsException ex = assertThrows(AwsException.class,
|
||||
() -> service.enableLogging("my-cluster", null, null, "s3table", null, null, "daily"));
|
||||
|
||||
assertEquals("InvalidParameterValue", ex.getErrorCode());
|
||||
assertFalse(cluster.isLoggingEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
void enableLoggingRejectsS3TableSettingsForOtherDestinations() {
|
||||
Cluster cluster = new Cluster();
|
||||
cluster.setClusterIdentifier("my-cluster");
|
||||
when(clusterBackend.get("my-cluster")).thenReturn(Optional.of(cluster));
|
||||
|
||||
AwsException ex = assertThrows(AwsException.class,
|
||||
() -> service.enableLogging("my-cluster", null, null, "s3", null, null, "cluster"));
|
||||
|
||||
assertEquals("InvalidParameterCombination", ex.getErrorCode());
|
||||
assertFalse(cluster.isLoggingEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
void disableLoggingClearsS3TableFields() {
|
||||
Cluster cluster = new Cluster();
|
||||
cluster.setClusterIdentifier("my-cluster");
|
||||
cluster.setLoggingEnabled(true);
|
||||
cluster.setLoggingDestinationType("s3table");
|
||||
cluster.setLoggingS3TableKmsKeyId("my-kms-key");
|
||||
cluster.setLoggingS3TableGranularity("account");
|
||||
when(clusterBackend.get("my-cluster")).thenReturn(Optional.of(cluster));
|
||||
|
||||
Cluster result = service.disableLogging("my-cluster");
|
||||
assertFalse(result.isLoggingEnabled());
|
||||
assertNull(result.getLoggingDestinationType());
|
||||
assertNull(result.getLoggingS3TableKmsKeyId());
|
||||
assertNull(result.getLoggingS3TableGranularity());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createClusterAssignsDefaultParameterGroup() {
|
||||
when(clusterBackend.get(anyString())).thenReturn(Optional.empty());
|
||||
|
||||
Reference in new issue
Block a user