mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(iam): read the managed-policy family's constraints from the model (#6580)
The declared constraints on IAM's managed-policy operations are read from the pinned model rather than from a hand-written check, through the vendored data tools/aws/regen_iam_shapes.py generates and a Query walk of it. Twelve operations go first: GetPolicy, DeletePolicy, the four policy-version operations, and the six attach and detach pairs. The vendored file carries that wave rather than all 180 operations, as the ECR and Resource Groups files carry theirs, and grows a wave at a time. The machinery was already here for the JSON protocols. request_shapes build_constraints vendors required members, lengths, patterns and enums; RequestConstraintCheck walks a JSON body against them; SmithyValidationErrors already writes the awsQuery wording. What was missing is the walk a Query request needs, which is why QueryConstraintCheck sits beside RequestConstraintCheck rather than inside it: a JSON body arrives as a tree, where a Query request arrives as flat parameters named after the members that carry them, and the violations are collected into one "N validation errors detected" message in the model's member order instead of the first one being thrown. A test sends two broken members in the opposite order to the model's and gets the model's order back, so the ordering is the model's rather than the wire's. What changes for a caller is the status, in the direction #6402 settled for this package: a PolicyArn under arnType's 20 characters, a VersionId outside policyVersionIdType's pattern or an absent required member used to reach the store and answer NoSuchEntity 404, where AWS's validation layer runs ahead of the operation and answers ValidationError 400. AttachRolePolicy's RoleName is the parity case for every value but one: IamService.validateRoleName already answered it from the same bounds and the same pattern, and for a name outside its pattern the message is unchanged by the model taking it over, which a test pins. An empty name is that one value, and the one place the wording moves rather than the status. validateRoleName stops at the first constraint an empty name breaks and reports the minimum alone, where the model also reports the pattern it breaks, so these twelve operations answer two violations where they answered one. That is the reading #6402 merged for a value breaking two of its constraints, and it makes validateRoleName the drift rather than the reference. The operations still on the hand-written check keep the single violation until a later wave takes them over, which a test holds still on CreateRole so that the wave which does has to settle the wording first. Two answers are the package's own rather than new. A member breaking two constraints is reported twice, which is what #6402 merged for a ServiceSpecificCredentialId that breaks both its length and its pattern, so an empty PolicyDocument reports its minimum and its pattern. The offending value stays quoted, as SmithyValidationErrors and validateRoleName already quote it; whether current IAM quotes it at all is an open question, and reading the constraints in one place is what would make that one helper to change rather than every message in the package. Scalars only so far. An operation whose input shape carries a list or a map is refused when the vendored file loads rather than passed over with its constraints unread, since reading one means reading Name.member.N and Name.entry.N.key and naming each index as the request spelled it. A boolean is declared and holds no constraint to be read against, so a SetAsDefault that is neither true nor false still reaches the operation, which reads anything but true as false. A test pins that rather than changing it, since what AWS answers for a malformed boolean is unrecorded here.
This commit is contained in:
1 parent
4b33002784
commit
bb48983b9c
11 files changed
+1019
No files matched your search
@@ -0,0 +1,196 @@
|
||||
package io.github.hectorvent.floci.core.common;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import jakarta.ws.rs.core.MultivaluedHashMap;
|
||||
import jakarta.ws.rs.core.MultivaluedMap;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class QueryConstraintCheckTest {
|
||||
|
||||
private static final ObjectMapper MAPPER = new ObjectMapper();
|
||||
|
||||
private static final String MODEL = """
|
||||
{
|
||||
"operations": {"Put": "PutRequest", "Take": "TakeRequest"},
|
||||
"shapes": {
|
||||
"PutRequest": {"type": "structure", "required": ["Name", "Arn"], "members": {
|
||||
"Name": "nameType", "Arn": "arnType", "Status": "statusType",
|
||||
"Age": "ageType", "Default": "booleanType"}},
|
||||
"TakeRequest": {"type": "structure", "members": {"Name": "nameType"}},
|
||||
"nameType": {"type": "string", "min": 1, "max": 8, "pattern": "[\\\\w+=,.@-]+"},
|
||||
"arnType": {"type": "string", "min": 20, "max": 2048},
|
||||
"statusType": {"type": "string", "enum": ["Active", "Inactive"]},
|
||||
"ageType": {"type": "integer", "min": 1, "max": 30},
|
||||
"booleanType": {"type": "boolean"}
|
||||
}
|
||||
}
|
||||
""";
|
||||
|
||||
private static QueryConstraintCheck check() throws Exception {
|
||||
return QueryConstraintCheck.of(MAPPER.readTree(MODEL));
|
||||
}
|
||||
|
||||
private static MultivaluedMap<String, String> params(String... pairs) {
|
||||
MultivaluedMap<String, String> params = new MultivaluedHashMap<>();
|
||||
for (int pair = 0; pair < pairs.length; pair += 2) {
|
||||
params.putSingle(pairs[pair], pairs[pair + 1]);
|
||||
}
|
||||
return params;
|
||||
}
|
||||
|
||||
/** Every required member the request leaves out, in the order the model lists the members. */
|
||||
@Test
|
||||
void theRequiredMembersAreReportedTogetherInTheModelsOrder() throws Exception {
|
||||
List<String> violations = check().violations("Put", params());
|
||||
|
||||
assertEquals(List.of(
|
||||
"Value null at 'name' failed to satisfy constraint: Member must not be null",
|
||||
"Value null at 'arn' failed to satisfy constraint: Member must not be null"),
|
||||
violations);
|
||||
}
|
||||
|
||||
/**
|
||||
* A member sent empty is a member the request carries, so what it breaks are its own
|
||||
* constraints, where one that never arrived is the member reported as null. An empty value
|
||||
* breaks both the minimum length and a pattern that asks for a character, and both are
|
||||
* reported, as #6402 settled for an id breaking two constraints.
|
||||
*/
|
||||
@Test
|
||||
void aMemberSentEmptyBreaksItsConstraintsRatherThanReadingAsAbsent() throws Exception {
|
||||
List<String> violations = check().violations("Take", params("Name", ""));
|
||||
|
||||
assertEquals(List.of(
|
||||
"Value '' at 'name' failed to satisfy constraint: "
|
||||
+ "Member must have length greater than or equal to 1",
|
||||
"Value '' at 'name' failed to satisfy constraint: "
|
||||
+ "Member must satisfy regular expression pattern: [\\w+=,.@-]+"),
|
||||
violations);
|
||||
assertEquals(List.of(), check().violations("Take", params()), "Name is optional here");
|
||||
}
|
||||
|
||||
/** Length, pattern and enum, each reported by the member that breaks it. */
|
||||
@Test
|
||||
void aStringIsHeldToItsLengthItsPatternAndItsEnum() throws Exception {
|
||||
assertEquals(List.of("Value 'abcdefghi' at 'name' failed to satisfy constraint: "
|
||||
+ "Member must have length less than or equal to 8"),
|
||||
check().violations("Take", params("Name", "abcdefghi")),
|
||||
"nine word characters break the length and nothing else");
|
||||
|
||||
assertEquals(List.of("Value 'two w' at 'name' failed to satisfy constraint: "
|
||||
+ "Member must satisfy regular expression pattern: [\\w+=,.@-]+"),
|
||||
check().violations("Take", params("Name", "two w")),
|
||||
"a space inside the length breaks the pattern and nothing else");
|
||||
|
||||
assertEquals(List.of(
|
||||
"Value 'two words' at 'name' failed to satisfy constraint: "
|
||||
+ "Member must have length less than or equal to 8",
|
||||
"Value 'two words' at 'name' failed to satisfy constraint: "
|
||||
+ "Member must satisfy regular expression pattern: [\\w+=,.@-]+"),
|
||||
check().violations("Take", params("Name", "two words")),
|
||||
"a value breaking both is reported twice");
|
||||
|
||||
assertEquals(List.of("Value 'Pending' at 'status' failed to satisfy constraint: "
|
||||
+ "Member must satisfy enum value set: [Active, Inactive]"),
|
||||
check().violations("Put", params("Name", "ok", "Arn", "a".repeat(20),
|
||||
"Status", "Pending")));
|
||||
}
|
||||
|
||||
/** A number is held to its range, and one that is no number at all is left to the operation. */
|
||||
@Test
|
||||
void aNumberIsHeldToItsRangeAndANonNumberIsLeftToTheOperation() throws Exception {
|
||||
MultivaluedMap<String, String> tooOld = params("Name", "ok", "Arn", "a".repeat(20), "Age", "31");
|
||||
assertEquals(List.of("Value '31' at 'age' failed to satisfy constraint: "
|
||||
+ "Member must have value less than or equal to 30"),
|
||||
check().violations("Put", tooOld));
|
||||
|
||||
MultivaluedMap<String, String> words = params("Name", "ok", "Arn", "a".repeat(20), "Age", "soon");
|
||||
assertEquals(List.of(), check().violations("Put", words));
|
||||
}
|
||||
|
||||
/** A boolean declares nothing a request can break, so nothing is checked for one. */
|
||||
@Test
|
||||
void aBooleanIsNotChecked() throws Exception {
|
||||
assertEquals(List.of(), check().violations("Put",
|
||||
params("Name", "ok", "Arn", "a".repeat(20), "Default", "yes")));
|
||||
}
|
||||
|
||||
/** The file carries one wave of operations, so an operation outside it passes untouched. */
|
||||
@Test
|
||||
void anOperationTheFileDoesNotCarryPasses() throws Exception {
|
||||
assertEquals(List.of(), check().violations("Delete", params("Name", "two words")));
|
||||
}
|
||||
|
||||
/** The protocol's code and the Smithy count, from the same violations. */
|
||||
@Test
|
||||
void checkThrowsTheQueryProtocolsValidationError() throws Exception {
|
||||
AwsException thrown = assertThrows(AwsException.class,
|
||||
() -> check().check("Put", params("Name", "two w")));
|
||||
|
||||
assertEquals("ValidationError", thrown.getErrorCode());
|
||||
assertEquals(400, thrown.getHttpStatus());
|
||||
assertEquals("2 validation errors detected: Value 'two w' at 'name' failed to satisfy"
|
||||
+ " constraint: Member must satisfy regular expression pattern: [\\w+=,.@-]+;"
|
||||
+ " Value null at 'arn' failed to satisfy constraint: Member must not be null",
|
||||
thrown.getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* A list or a map is read from numbered parameters rather than from one, so an operation
|
||||
* carrying either is refused when the file loads rather than passed over without its
|
||||
* constraints.
|
||||
*/
|
||||
@Test
|
||||
void anOperationCarryingAListIsRefusedWhenTheFileLoads() throws Exception {
|
||||
JsonNode model = MAPPER.readTree("""
|
||||
{
|
||||
"operations": {"Tag": "TagRequest"},
|
||||
"shapes": {
|
||||
"TagRequest": {"type": "structure", "members": {"Tags": "tagList"}},
|
||||
"tagList": {"type": "list", "member": "nameType", "max": 50},
|
||||
"nameType": {"type": "string", "min": 1}
|
||||
}
|
||||
}
|
||||
""");
|
||||
|
||||
IllegalStateException thrown =
|
||||
assertThrows(IllegalStateException.class, () -> QueryConstraintCheck.of(model));
|
||||
|
||||
assertTrue(thrown.getMessage().contains("Tag's Tags is a list"), thrown.getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* The vendored IAM file itself, read the way the handler reads it. Loading it is the check on
|
||||
* it: every operation's members have to be scalars and every pattern has to be one Java's
|
||||
* engine compiles, and a wave that breaks either would otherwise surface as a failure on the
|
||||
* first IAM request rather than here. Naming the twelve operations keeps the wave's own
|
||||
* contract, so an operation renamed or dropped in the model is a failure with a name on it.
|
||||
*/
|
||||
@Test
|
||||
void theVendoredIamFileLoadsAndCarriesTheOperationsThisWaveClaims() {
|
||||
QueryConstraintCheck iam =
|
||||
QueryConstraintCheck.load("aws/iam-request-shapes.json", "IAM request shapes");
|
||||
|
||||
List<String> wave = List.of("AttachGroupPolicy", "AttachRolePolicy", "AttachUserPolicy",
|
||||
"DetachGroupPolicy", "DetachRolePolicy", "DetachUserPolicy", "GetPolicy",
|
||||
"DeletePolicy", "CreatePolicyVersion", "GetPolicyVersion", "DeletePolicyVersion",
|
||||
"SetDefaultPolicyVersion");
|
||||
for (String operation : wave) {
|
||||
assertTrue(iam.violations(operation, params()).stream()
|
||||
.allMatch(violation -> violation.contains("must not be null")),
|
||||
operation + " reported something other than its absent required members");
|
||||
assertTrue(iam.violations(operation, params()).size() >= 1,
|
||||
operation + " resolved to no required members, so its shape did not resolve");
|
||||
}
|
||||
|
||||
assertEquals(List.of("Value 'v1' at 'policyArn' failed to satisfy constraint: Member must"
|
||||
+ " have length greater than or equal to 20"),
|
||||
iam.violations("GetPolicy", params("PolicyArn", "v1")));
|
||||
}
|
||||
}
|
||||
+233
@@ -0,0 +1,233 @@
|
||||
package io.github.hectorvent.floci.services.iam;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
|
||||
/**
|
||||
* The declared constraints the managed-policy family is now read against, from the model rather
|
||||
* than from a hand-written check. What they change is the status: a value that breaks a declared
|
||||
* constraint used to reach the store and answer {@code NoSuchEntity}, where AWS's validation layer
|
||||
* runs ahead of the operation and answers {@code ValidationError}, which is the ordering #6402
|
||||
* settled for this package.
|
||||
*
|
||||
* <p>{@code AttachRolePolicy}'s {@code RoleName} is the parity case rather than a change:
|
||||
* {@code IamService.validateRoleName} already answered it in this form, from the same bounds and
|
||||
* the same pattern, and the message is unchanged by the model taking it over.
|
||||
*/
|
||||
@QuarkusTest
|
||||
class IamRequestConstraintsIntegrationTest {
|
||||
|
||||
private static final String IAM_AUTH =
|
||||
"AWS4-HMAC-SHA256 Credential=test/20261025/us-east-1/iam/aws4_request";
|
||||
|
||||
/** 20 characters, the shortest value `arnType` accepts, and no policy that exists. */
|
||||
private static final String SHORTEST_ARN = "arn:aws:iam::1:p/abc";
|
||||
|
||||
private static final String TRUST_POLICY =
|
||||
"{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\","
|
||||
+ "\"Principal\":{\"Service\":\"lambda.amazonaws.com\"},\"Action\":\"sts:AssumeRole\"}]}";
|
||||
|
||||
private static final String CODE = "ErrorResponse.Error.Code";
|
||||
private static final String MESSAGE = "ErrorResponse.Error.Message";
|
||||
|
||||
private static RequestSpecification iam(String action) {
|
||||
return given().header("Authorization", IAM_AUTH).formParam("Action", action);
|
||||
}
|
||||
|
||||
/** `arnType` is 20 to 2048, so a shorter ARN is the 400 rather than the lookup's 404. */
|
||||
@Test
|
||||
void anArnUnderItsMinimumIsRefusedAheadOfTheLookup() {
|
||||
iam("GetPolicy")
|
||||
.formParam("PolicyArn", "arn:aws:iam::1:p/ab")
|
||||
.when().post("/").then().statusCode(400)
|
||||
.body(CODE, equalTo("ValidationError"))
|
||||
.body(MESSAGE, equalTo("1 validation error detected: Value 'arn:aws:iam::1:p/ab' at"
|
||||
+ " 'policyArn' failed to satisfy constraint: Member must have length greater"
|
||||
+ " than or equal to 20"))
|
||||
.body(not(containsString("NoSuchEntity")));
|
||||
|
||||
// The same ARN one character longer clears the constraint and reaches the lookup.
|
||||
iam("GetPolicy")
|
||||
.formParam("PolicyArn", SHORTEST_ARN)
|
||||
.when().post("/").then().statusCode(404)
|
||||
.body(CODE, equalTo("NoSuchEntity"));
|
||||
}
|
||||
|
||||
/** A required member the request leaves out is the validation layer's answer, not the store's. */
|
||||
@Test
|
||||
void aRequiredMemberLeftOutIsReportedAsNull() {
|
||||
iam("DeletePolicy").when().post("/").then().statusCode(400)
|
||||
.body(CODE, equalTo("ValidationError"))
|
||||
.body(MESSAGE, equalTo("1 validation error detected: Value null at 'policyArn' failed"
|
||||
+ " to satisfy constraint: Member must not be null"));
|
||||
}
|
||||
|
||||
/** `policyVersionIdType` publishes a pattern and no length, so a bare number breaks it. */
|
||||
@Test
|
||||
void aVersionIdOutsideItsPatternIsRefused() {
|
||||
iam("GetPolicyVersion")
|
||||
.formParam("PolicyArn", SHORTEST_ARN)
|
||||
.formParam("VersionId", "1")
|
||||
.when().post("/").then().statusCode(400)
|
||||
.body(MESSAGE, equalTo("1 validation error detected: Value '1' at 'versionId' failed to"
|
||||
+ " satisfy constraint: Member must satisfy regular expression pattern:"
|
||||
+ " v[1-9][0-9]*(\\.[A-Za-z0-9-]*)?"));
|
||||
|
||||
iam("DeletePolicyVersion")
|
||||
.formParam("PolicyArn", SHORTEST_ARN)
|
||||
.formParam("VersionId", "v1")
|
||||
.when().post("/").then().statusCode(404)
|
||||
.body(CODE, equalTo("NoSuchEntity"));
|
||||
}
|
||||
|
||||
/**
|
||||
* A document sent empty is a member that is present, so what it breaks are its own
|
||||
* constraints: the minimum length of 1 and a pattern that asks for a character, reported as
|
||||
* two violations the way #6402 reports an id that breaks both of its.
|
||||
*/
|
||||
@Test
|
||||
void anEmptyPolicyDocumentBreaksItsLengthAndItsPattern() {
|
||||
iam("CreatePolicyVersion")
|
||||
.formParam("PolicyArn", SHORTEST_ARN)
|
||||
.formParam("PolicyDocument", "")
|
||||
.when().post("/").then().statusCode(400)
|
||||
.body(MESSAGE, containsString("2 validation errors detected: Value '' at"
|
||||
+ " 'policyDocument' failed to satisfy constraint: Member must have length"
|
||||
+ " greater than or equal to 1"))
|
||||
.body(MESSAGE, containsString("Value '' at 'policyDocument' failed to satisfy"
|
||||
+ " constraint: Member must satisfy regular expression pattern:"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Both broken members are reported in one message, in the order the model lists them rather
|
||||
* than the order the request sent them. The second half is what makes that an assertion: the
|
||||
* request puts `PolicyArn` first and the answer still leads with `userName`, which the model
|
||||
* lists first. Whether AWS orders them that way is GEN-2's capture to confirm; what is pinned
|
||||
* here is that the order comes from the model and not from the wire.
|
||||
*/
|
||||
@Test
|
||||
void twoBrokenMembersAreReportedTogetherInTheModelsOrder() {
|
||||
String expected = "2 validation errors detected: Value '" + "a".repeat(65) + "' at"
|
||||
+ " 'userName' failed to satisfy constraint: Member must have length less than"
|
||||
+ " or equal to 64; Value 'short' at 'policyArn' failed to satisfy constraint:"
|
||||
+ " Member must have length greater than or equal to 20";
|
||||
|
||||
iam("AttachUserPolicy")
|
||||
.formParam("UserName", "a".repeat(65))
|
||||
.formParam("PolicyArn", "short")
|
||||
.when().post("/").then().statusCode(400)
|
||||
.body(MESSAGE, equalTo(expected));
|
||||
|
||||
iam("AttachUserPolicy")
|
||||
.formParam("PolicyArn", "short")
|
||||
.formParam("UserName", "a".repeat(65))
|
||||
.when().post("/").then().statusCode(400)
|
||||
.body(MESSAGE, equalTo(expected));
|
||||
}
|
||||
|
||||
/**
|
||||
* The parity case: the message for a role name outside its pattern is the one
|
||||
* {@code validateRoleName} already answered, from the same bounds, so what changed is where it
|
||||
* is read rather than what it says.
|
||||
*/
|
||||
@Test
|
||||
void aRoleNameOutsideItsPatternKeepsTheMessageTheServiceAlreadyAnswered() {
|
||||
iam("AttachRolePolicy")
|
||||
.formParam("RoleName", "two words")
|
||||
.formParam("PolicyArn", SHORTEST_ARN)
|
||||
.when().post("/").then().statusCode(400)
|
||||
.body(CODE, equalTo("ValidationError"))
|
||||
.body(MESSAGE, equalTo("1 validation error detected: Value 'two words' at 'roleName'"
|
||||
+ " failed to satisfy constraint: Member must satisfy regular expression"
|
||||
+ " pattern: [\\w+=,.@-]+"));
|
||||
}
|
||||
|
||||
/**
|
||||
* An empty name is the one input where reading the model changes what this service answers
|
||||
* rather than only when it answers. {@code validateRoleName} stops at the first constraint an
|
||||
* empty value breaks, so it reports the minimum length alone; the model reports the pattern it
|
||||
* also breaks, which is how #6402 reports an id breaking two of its own, and how
|
||||
* {@code GetMFADevice} already answers an empty {@code UserName}. The operations still on the
|
||||
* hand-written check keep the single violation until a later wave takes them over, and
|
||||
* {@code CreateRole} below is what holds that boundary still.
|
||||
*
|
||||
* <p>The order of the two is this package's, matching {@code GetMFADevice}, rather than a
|
||||
* claim about AWS: the captured messages in the Identity Center guide show length before
|
||||
* pattern in one and pattern before length in another, so an exact order is stricter than any
|
||||
* source states.
|
||||
*/
|
||||
@Test
|
||||
void anEmptyRoleNameBreaksTwoConstraintsWhereTheHandWrittenCheckStopsAtOne() {
|
||||
iam("AttachRolePolicy")
|
||||
.formParam("RoleName", "")
|
||||
.formParam("PolicyArn", SHORTEST_ARN)
|
||||
.when().post("/").then().statusCode(400)
|
||||
.body(CODE, equalTo("ValidationError"))
|
||||
.body(MESSAGE, equalTo("2 validation errors detected: Value '' at 'roleName' failed to"
|
||||
+ " satisfy constraint: Member must have length greater than or equal to 1;"
|
||||
+ " Value '' at 'roleName' failed to satisfy constraint: Member must satisfy"
|
||||
+ " regular expression pattern: [\\w+=,.@-]+"));
|
||||
|
||||
// The same empty name on an operation this wave leaves alone, reported the older way.
|
||||
iam("CreateRole")
|
||||
.formParam("RoleName", "")
|
||||
.formParam("AssumeRolePolicyDocument", TRUST_POLICY)
|
||||
.when().post("/").then().statusCode(400)
|
||||
.body(MESSAGE, equalTo("1 validation error detected: Value '' at 'roleName' failed to"
|
||||
+ " satisfy constraint: Member must have length greater than or equal to 1"));
|
||||
}
|
||||
|
||||
/**
|
||||
* A name of one space is a character long, so it clears the minimum and breaks only the
|
||||
* pattern. It is worth pinning because this package elsewhere reads a blank required member as
|
||||
* absent, and the model does not: the request carries it, so it is a value.
|
||||
*/
|
||||
@Test
|
||||
void aBlankRoleNameBreaksOnlyItsPatternRatherThanReadingAsAbsent() {
|
||||
iam("DetachRolePolicy")
|
||||
.formParam("RoleName", " ")
|
||||
.formParam("PolicyArn", SHORTEST_ARN)
|
||||
.when().post("/").then().statusCode(400)
|
||||
.body(MESSAGE, equalTo("1 validation error detected: Value ' ' at 'roleName' failed to"
|
||||
+ " satisfy constraint: Member must satisfy regular expression pattern:"
|
||||
+ " [\\w+=,.@-]+"));
|
||||
}
|
||||
|
||||
/** The other end of `arnType`: 2048 characters are accepted and 2049 are not. */
|
||||
@Test
|
||||
void anArnAtItsMaximumIsAcceptedAndOneCharacterLongerIsNot() {
|
||||
iam("GetPolicy")
|
||||
.formParam("PolicyArn", "arn:aws:iam::1:p/" + "a".repeat(2031))
|
||||
.when().post("/").then().statusCode(404)
|
||||
.body(CODE, equalTo("NoSuchEntity"));
|
||||
|
||||
iam("GetPolicy")
|
||||
.formParam("PolicyArn", "arn:aws:iam::1:p/" + "a".repeat(2032))
|
||||
.when().post("/").then().statusCode(400)
|
||||
.body(CODE, equalTo("ValidationError"))
|
||||
.body(MESSAGE, containsString("at 'policyArn' failed to satisfy constraint: Member must"
|
||||
+ " have length less than or equal to 2048"))
|
||||
.body(not(containsString("NoSuchEntity")));
|
||||
}
|
||||
|
||||
/**
|
||||
* A boolean is declared and not checked: the model names no constraint for one, so a value
|
||||
* that is neither true nor false reaches the operation, which reads anything but "true" as
|
||||
* false. Pinned rather than fixed, since what AWS answers for one is unrecorded here.
|
||||
*/
|
||||
@Test
|
||||
void aBooleanOutsideTrueAndFalseIsLeftToTheOperation() {
|
||||
iam("CreatePolicyVersion")
|
||||
.formParam("PolicyArn", SHORTEST_ARN)
|
||||
.formParam("PolicyDocument", "{}")
|
||||
.formParam("SetAsDefault", "maybe")
|
||||
.when().post("/").then().statusCode(404)
|
||||
.body(CODE, equalTo("NoSuchEntity"));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user