mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(iam): match status validation errors for credential updates (#7174)
This commit is contained in:
1 parent
a707cb3260
commit
a54ca5e0c9
10 files changed
+109
-50
No files matched your search
+8
-6
@@ -25,9 +25,8 @@ import static org.hamcrest.Matchers.equalTo;
|
||||
* implicitly based on the AWS access key ID used to sign the request", the sentence this operation
|
||||
* shares with DeleteAccessKey and ListAccessKeys.
|
||||
*
|
||||
* <p>The refusal is the rendering {@code IamService.requireStatusFromEnum} already answers for the
|
||||
* other three operations that take this shape, which names neither the offending value nor the
|
||||
* permitted set, as AWS's own recording of one of them does not.
|
||||
* <p>The four operations share {@code IamService.requireStatusFromEnum}; the latest AWS captures
|
||||
* distinguish an absent status from a present value outside the enum.
|
||||
*/
|
||||
@QuarkusTest
|
||||
class IamAccessKeyStatusIntegrationTest {
|
||||
@@ -61,19 +60,22 @@ class IamAccessKeyStatusIntegrationTest {
|
||||
.body("ErrorResponse.Error.Code", equalTo("ValidationError"))
|
||||
.body("ErrorResponse.Error.Message",
|
||||
equalTo("1 validation error detected: Value at 'status' failed to satisfy "
|
||||
+ "constraint: Member must satisfy enum value set"));
|
||||
+ "constraint: Member must satisfy enum value set: "
|
||||
+ "[Expired, Active, Inactive]"));
|
||||
|
||||
assertStatusStillActive(userName);
|
||||
}
|
||||
|
||||
@Test
|
||||
void anAbsentStatusIsAnsweredTheSameWay() {
|
||||
void anAbsentStatusNamesTheMissingMember() {
|
||||
String userName = user("absent-status");
|
||||
String accessKeyId = accessKeyFor(userName);
|
||||
|
||||
update(ACCOUNT, Map.of("UserName", userName, "AccessKeyId", accessKeyId)).statusCode(400)
|
||||
.body("ErrorResponse.Error.Code", equalTo("ValidationError"))
|
||||
.body("ErrorResponse.Error.Message", containsString("at 'status'"));
|
||||
.body("ErrorResponse.Error.Message",
|
||||
equalTo("1 validation error detected: Value at 'status' failed to satisfy "
|
||||
+ "constraint: Member must not be null"));
|
||||
|
||||
assertStatusStillActive(userName);
|
||||
}
|
||||
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
package io.github.hectorvent.floci.services.iam;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.response.ValidatableResponse;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.CsvSource;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
/** IAM's four statusType updates share the validation behavior captured for issue #6042. */
|
||||
@QuarkusTest
|
||||
class IamCredentialStatusValidationIntegrationTest {
|
||||
|
||||
private static final String MESSAGE = "ErrorResponse.Error.Message";
|
||||
private static final String PREFIX = "1 validation error detected: Value at 'status' failed "
|
||||
+ "to satisfy constraint: ";
|
||||
|
||||
@ParameterizedTest(name = "{0} without Status")
|
||||
@CsvSource({
|
||||
"UpdateAccessKey, AccessKeyId, AKIAIOSFODNN7EXAMPLE",
|
||||
"UpdateSigningCertificate, CertificateId, ABCDEFGHIJKLMNOPQRSTUVWX",
|
||||
"UpdateSSHPublicKey, SSHPublicKeyId, APKAEXAMPLEEXAMPLE12",
|
||||
"UpdateServiceSpecificCredential, ServiceSpecificCredentialId, ACCAEXAMPLEEXAMPLE12"
|
||||
})
|
||||
void omittedStatusIsReportedAsNull(String action, String idMember, String id) {
|
||||
update(action, idMember, id, null).statusCode(400)
|
||||
.body("ErrorResponse.Error.Code", equalTo("ValidationError"))
|
||||
.body(MESSAGE, equalTo(PREFIX + "Member must not be null"));
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "{0} with Status=Enabled")
|
||||
@CsvSource({
|
||||
"UpdateAccessKey, AccessKeyId, AKIAIOSFODNN7EXAMPLE",
|
||||
"UpdateSigningCertificate, CertificateId, ABCDEFGHIJKLMNOPQRSTUVWX",
|
||||
"UpdateSSHPublicKey, SSHPublicKeyId, APKAEXAMPLEEXAMPLE12",
|
||||
"UpdateServiceSpecificCredential, ServiceSpecificCredentialId, ACCAEXAMPLEEXAMPLE12"
|
||||
})
|
||||
void invalidStatusListsAllowedValues(String action, String idMember, String id) {
|
||||
update(action, idMember, id, "Enabled").statusCode(400)
|
||||
.body("ErrorResponse.Error.Code", equalTo("ValidationError"))
|
||||
.body(MESSAGE, equalTo(PREFIX
|
||||
+ "Member must satisfy enum value set: [Expired, Active, Inactive]"));
|
||||
}
|
||||
|
||||
private static ValidatableResponse update(String action, String idMember, String id,
|
||||
String status) {
|
||||
RequestSpecification request = given()
|
||||
.header("Authorization", "AWS4-HMAC-SHA256 Credential=000000000912/20261101/"
|
||||
+ "us-east-1/iam/aws4_request")
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", action)
|
||||
.formParam("Version", "2010-05-08")
|
||||
.formParam("UserName", "status-validation-missing-user")
|
||||
.formParam(idMember, id);
|
||||
if (status != null) {
|
||||
request.formParam("Status", status);
|
||||
}
|
||||
return request.when().post("/").then();
|
||||
}
|
||||
}
|
||||
@@ -2191,16 +2191,14 @@ class IamServiceTest {
|
||||
() -> iamService.updateAccessKey("alice", "AKIANOSUCHKEY00000", "Disabled"));
|
||||
|
||||
assertEquals("ValidationError", error.getErrorCode());
|
||||
// The rendering the three sibling operations already answer with, taken from a recording
|
||||
// of UpdateServiceSpecificCredential: AWS names neither the value nor the permitted set.
|
||||
// AWS lists the allowed values in its error message, even when the key is unknown.
|
||||
assertEquals("1 validation error detected: Value at 'status' failed to satisfy "
|
||||
+ "constraint: Member must satisfy enum value set", error.getMessage());
|
||||
+ "constraint: Member must satisfy enum value set: [Expired, Active, Inactive]",
|
||||
error.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void anAbsentAccessKeyStatusIsAnsweredLikeAnInvalidOne() {
|
||||
// The shared helper reads a null as a value outside the enum, which is how the other three
|
||||
// statusType operations answer one. Changing that would change all four, so it stays.
|
||||
void anAbsentAccessKeyStatusNamesTheMissingMember() {
|
||||
iamService.createUser("alice", "/");
|
||||
AccessKey key = iamService.createAccessKey("alice");
|
||||
|
||||
@@ -2209,7 +2207,7 @@ class IamServiceTest {
|
||||
|
||||
assertEquals("ValidationError", error.getErrorCode());
|
||||
assertEquals("1 validation error detected: Value at 'status' failed to satisfy "
|
||||
+ "constraint: Member must satisfy enum value set", error.getMessage());
|
||||
+ "constraint: Member must not be null", error.getMessage());
|
||||
// And the key is as it was: the status is read before the lookup, so nothing is written.
|
||||
assertEquals("Active", iamService.listAccessKeys("alice").getFirst().getStatus());
|
||||
}
|
||||
|
||||
+3
-4
@@ -587,10 +587,9 @@ class ServiceSpecificCredentialIntegrationTest {
|
||||
.when().post("/").then().statusCode(400)
|
||||
.body(containsString("ValidationError"))
|
||||
.body(containsString("1 validation error detected"))
|
||||
.body(containsString("Member must satisfy enum value set"))
|
||||
// AWS names neither the offending value nor the permitted set. The trailing colon
|
||||
// is the tell for the set, and "Deleted" for the value.
|
||||
.body(not(containsString("enum value set:")))
|
||||
.body(containsString("Member must satisfy enum value set: "
|
||||
+ "[Expired, Active, Inactive]"))
|
||||
// The error lists the set but does not echo the rejected value.
|
||||
.body(not(containsString("Deleted")));
|
||||
}
|
||||
|
||||
|
||||
+3
-4
@@ -140,11 +140,10 @@ class SigningCertificateIntegrationTest {
|
||||
.formParam("Status", "Revoked")
|
||||
.when().post("/").then().statusCode(400)
|
||||
.body(containsString("ValidationError"))
|
||||
// statusType is one shape across the three operations that take it, and AWS renders it
|
||||
// without the offending value or the permitted set.
|
||||
// The AWS capture lists the set but does not echo the offending value.
|
||||
.body(containsString("1 validation error detected"))
|
||||
.body(containsString("Member must satisfy enum value set"))
|
||||
.body(not(containsString("enum value set:")))
|
||||
.body(containsString("Member must satisfy enum value set: "
|
||||
+ "[Expired, Active, Inactive]"))
|
||||
.body(not(containsString("Revoked")));
|
||||
}
|
||||
|
||||
|
||||
+3
-5
@@ -218,9 +218,7 @@ class SshPublicKeyIntegrationTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* And nothing outside the enum. {@code statusType} is one shape across the three operations
|
||||
* that take it, so this is the same answer AWS gives on UpdateServiceSpecificCredential, where
|
||||
* it was recorded: the offending value and the permitted set are both absent.
|
||||
* And nothing outside the enum. AWS lists the permitted set without echoing the value.
|
||||
*/
|
||||
@Test
|
||||
void theStatusTakesNothingOutsideTheEnum() {
|
||||
@@ -235,8 +233,8 @@ class SshPublicKeyIntegrationTest {
|
||||
.when().post("/").then().statusCode(400)
|
||||
.body(containsString("ValidationError"))
|
||||
.body(containsString("1 validation error detected"))
|
||||
.body(containsString("Member must satisfy enum value set"))
|
||||
.body(not(containsString("enum value set:")))
|
||||
.body(containsString("Member must satisfy enum value set: "
|
||||
+ "[Expired, Active, Inactive]"))
|
||||
.body(not(containsString("Revoked")));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user