mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(ssm): validate SettingValue and require an account list on ModifyDocumentPermission (#2635)
* fix(ssm): validate SettingValue and require an account list on ModifyDocumentPermission UpdateServiceSetting.SettingValue was read with plain asText(), so an absent or blank value silently stored an empty customized setting, and botocore's ServiceSettingValue max (4096) was never enforced. ModifyDocumentPermission accepted a request with neither AccountIdsToAdd nor AccountIdsToRemove and returned success having shared/unshared nothing, when botocore documents at least one of the two as required. * fix(ssm): review comments — whitespace SettingValue, non-list AccountIds, message format Greptile: isBlank() rejected a whitespace-only SettingValue even though botocore's ServiceSettingValue constraint is length-only (min 1); switched to isEmpty(). Copilot: a non-list AccountIdsToAdd/AccountIdsToRemove payload was silently treated as an empty list because forEach() on a scalar/object node yields no elements, so the new "neither list specified" guard could pass a malformed request. Reject a present-but-non-array field explicitly, and reworded that guard's message to match this file's "1 validation error detected:" prefix.
This commit is contained in:
1 parent
5400204563
commit
149ac635f2
2 files changed
+179
-2
No files matched your search
@@ -321,6 +321,71 @@ class SsmIntegrationTest {
|
||||
.body("__type", equalTo("ServiceSettingNotFound"));
|
||||
}
|
||||
|
||||
// ── SettingValue (botocore: ServiceSettingValue, required, min 1 / max 4096) ──
|
||||
|
||||
@Test
|
||||
void updateServiceSetting_missingSettingValueReturnsValidationException() {
|
||||
given()
|
||||
.header("X-Amz-Target", "AmazonSSM.UpdateServiceSetting")
|
||||
.contentType(SSM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{ "SettingId": "/ssm/documents/console/public-sharing-permission" }
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ValidationException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateServiceSetting_whitespaceOnlySettingValueIsStoredVerbatim() {
|
||||
given()
|
||||
.header("X-Amz-Target", "AmazonSSM.UpdateServiceSetting")
|
||||
.contentType(SSM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"SettingId": "/ssm/parameter-store/default-parameter-tier",
|
||||
"SettingValue": " "
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "AmazonSSM.GetServiceSetting")
|
||||
.contentType(SSM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{ "SettingId": "/ssm/parameter-store/default-parameter-tier" }
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ServiceSetting.SettingValue", equalTo(" "));
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateServiceSetting_settingValueOverMaxLengthReturnsValidationException() {
|
||||
String tooLong = "x".repeat(4097);
|
||||
given()
|
||||
.header("X-Amz-Target", "AmazonSSM.UpdateServiceSetting")
|
||||
.contentType(SSM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"SettingId": "/ssm/documents/console/public-sharing-permission",
|
||||
"SettingValue": "%s"
|
||||
}
|
||||
""".formatted(tooLong))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ValidationException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void serviceSettingOperations_missingSettingIdReturnsValidationException() {
|
||||
for (String target : new String[]{"GetServiceSetting", "UpdateServiceSetting", "ResetServiceSetting"}) {
|
||||
@@ -1055,6 +1120,40 @@ class SsmIntegrationTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void modifyDocumentPermission_nonListAccountIdsToAddReturnsValidationException() {
|
||||
createSharableDocument("Non-List-Account-Ids-Document");
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "AmazonSSM.ModifyDocumentPermission")
|
||||
.contentType(SSM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"Name": "Non-List-Account-Ids-Document",
|
||||
"PermissionType": "Share",
|
||||
"AccountIdsToAdd": "444444444444"
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ValidationException"));
|
||||
|
||||
// Nothing may have been shared — the scalar must not be silently treated as empty.
|
||||
given()
|
||||
.header("X-Amz-Target", "AmazonSSM.DescribeDocumentPermission")
|
||||
.contentType(SSM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{ "Name": "Non-List-Account-Ids-Document", "PermissionType": "Share" }
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("AccountIds", empty());
|
||||
}
|
||||
|
||||
// ── AccountIdsToAdd/Remove (botocore: list max 20, member (?i)all|[0-9]{12}) ──
|
||||
|
||||
@Test
|
||||
@@ -1138,6 +1237,43 @@ class SsmIntegrationTest {
|
||||
.body("__type", equalTo("ValidationException"));
|
||||
}
|
||||
|
||||
// ── ModifyDocumentPermission: at least one of AccountIdsToAdd/AccountIdsToRemove
|
||||
// required (botocore: documented on both members, not a JSON `required` or shape
|
||||
// constraint — "You must specify a value for this parameter or the
|
||||
// AccountIdsToRemove/AccountIdsToAdd parameter.") ──
|
||||
|
||||
@Test
|
||||
void modifyDocumentPermission_neitherAccountListSpecifiedReturnsValidationException() {
|
||||
createSharableDocument("No-Account-Lists-Document");
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "AmazonSSM.ModifyDocumentPermission")
|
||||
.contentType(SSM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"Name": "No-Account-Lists-Document",
|
||||
"PermissionType": "Share"
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ValidationException"));
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "AmazonSSM.DescribeDocumentPermission")
|
||||
.contentType(SSM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{ "Name": "No-Account-Lists-Document", "PermissionType": "Share" }
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("AccountIds", empty());
|
||||
}
|
||||
|
||||
private static void createSharableDocument(String name) {
|
||||
given()
|
||||
.header("X-Amz-Target", "AmazonSSM.CreateDocument")
|
||||
|
||||
Reference in new issue
Block a user