diff --git a/Makefile b/Makefile index 0c50e76591..8fac930ec3 100644 --- a/Makefile +++ b/Makefile @@ -25,6 +25,8 @@ # by tools/aws/regen_ecs_shapes.py. # src/main/resources/aws/ecr-request-shapes.json, the ECR request constraints, is generated # from botocore's ECR model by tools/aws/regen_ecr_shapes.py. +# src/main/resources/aws/iam-request-shapes.json, the IAM request constraints of the operations +# read from the model, is generated from botocore's IAM model by tools/aws/regen_iam_shapes.py. # src/main/resources/aws/emr-serverless-shapes.json, the shapes the Step Functions emr-serverless # integrations recase against, is generated from botocore's EMR Serverless model by # tools/aws/regen_emr_serverless_shapes.py. @@ -230,6 +232,7 @@ aws-data-sync: ## Regenerate src/main/resources/aws/*.json and the IAM managed-p $(PYTHON) tools/aws/regen_redshift_serverless_shapes.py $(PYTHON) tools/aws/regen_resource_groups_shapes.py $(PYTHON) tools/aws/regen_ecr_shapes.py + $(PYTHON) tools/aws/regen_iam_shapes.py $(PYTHON) tools/aws/regen_apigateway_types.py $(PYTHON) tools/aws/regen_sesv2_shapes.py $(PYTHON) tools/aws/regen_apigateway_shapes.py @@ -258,6 +261,12 @@ aws-data-check: ## CI gate: the vendored AWS data must match a fresh generation echo " Run 'make aws-data-sync' and commit the result."; \ exit 1; \ } + @$(PYTHON) tools/aws/regen_iam_shapes.py --check || { \ + echo ""; \ + echo "error: src/main/resources/aws/iam-request-shapes.json is out of date."; \ + echo " Run 'make aws-data-sync' and commit the result."; \ + exit 1; \ + } @$(PYTHON) tools/aws/regen_redshift_serverless_shapes.py --check || { \ echo ""; \ echo "error: src/main/resources/aws/redshift-serverless-request-shapes.json is out of date."; \ diff --git a/docs/services/iam.md b/docs/services/iam.md index d4b5805c66..5f394be0a5 100644 --- a/docs/services/iam.md +++ b/docs/services/iam.md @@ -154,6 +154,23 @@ outside 1 to 1000. `PathPrefix` and `Scope` filter before paging, and roles and policies are listed in name order so a `Marker` resumes where the previous page stopped. `ListPolicies` does not yet apply `OnlyAttached` or `PolicyUsageFilter`. +The declared constraints on the managed-policy family are read from the model rather than from a +hand-written check, `tools/aws/regen_iam_shapes.py` vendoring them for `GetPolicy`, `DeletePolicy`, +`CreatePolicyVersion`, `GetPolicyVersion`, `DeletePolicyVersion`, `SetDefaultPolicyVersion` and the +six attach and detach operations. A `PolicyArn` is held to `arnType`'s 20 to 2048 characters, a +`VersionId` to `policyVersionIdType`'s pattern, a `PolicyDocument` to its 1 to 131072 characters and +its pattern, and each principal name to its own bound, which for a role is the 1 to 64 characters of +`[\w+=,.@-]` this service already answered. The check runs ahead of the operation, so a value that +breaks a constraint is a 400 `ValidationError` where it used to reach the store and answer +`NoSuchEntity` 404, the ordering the rest of this package already follows. A member sent empty is a +member the request carries, so it breaks its own constraints rather than reading as absent, and a +member breaking two of them is reported twice, as a `ServiceSpecificCredentialId` breaking both of +its own already is. That is the one place the wording moves rather than only the status: a name sent +empty breaks its minimum and its pattern at once, so these operations report both, where the +hand-written check the rest of the service still uses stops at the first and reports the minimum +alone. A boolean member publishes no constraint to hold it to, so a `SetAsDefault` that is neither +`true` nor `false` reaches the operation, which reads anything but `true` as false. + ### Permission Boundaries | Action | Description | diff --git a/src/main/java/io/github/hectorvent/floci/core/common/QueryConstraintCheck.java b/src/main/java/io/github/hectorvent/floci/core/common/QueryConstraintCheck.java new file mode 100644 index 0000000000..d9837dac17 --- /dev/null +++ b/src/main/java/io/github/hectorvent/floci/core/common/QueryConstraintCheck.java @@ -0,0 +1,182 @@ +package io.github.hectorvent.floci.core.common; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import jakarta.ws.rs.core.MultivaluedMap; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.regex.Pattern; + +/** + * Checks an AWS Query request against the constraints a {@code tools/aws/regen_*_shapes.py} + * generator vendors from botocore through {@code request_shapes.build_constraints}: the members a + * structure requires, a string's length, pattern and enum, and a number's range. It reads the same + * vendored shape {@link RequestConstraintCheck} reads for the JSON protocols, and walks it + * differently because the requests differ: a JSON body arrives as a tree, where a Query request + * arrives as flat form parameters named after the members that carry them. + * + *
Every violation is collected rather than the first one thrown, which is what AWS's validation + * layer answers: "N validation errors detected" with the violations in the order the model lists + * the members, and a member that breaks two constraints reported twice. That is the reading #6402 + * merged for a `ServiceSpecificCredentialId` breaking both its length and its pattern, and + * `docs/services/iam.md` carries it. + * + *
The offending value is quoted, which is what {@link SmithyValidationErrors#lengthOutOfRange} + * and this package's `validateRoleName` already answer. Whether current IAM quotes it at all is + * what DRIFT-13 asks, and the point of reading the constraints here is that one capture would + * change one helper rather than every message in the package. + * + *
A member the request leaves out is absent, and only a required member is reported for one. A + * member present and empty is a value: the protocol carries it, so it breaks its minimum length + * rather than reading as absent. + * + *
Scalars only for now. An operation whose input shape carries a list or a map is refused when
+ * the file loads rather than passed over quietly, since reading one means reading
+ * {@code Name.member.N} and {@code Name.entry.N.key} and naming each index as the request spelled
+ * it.
+ */
+public final class QueryConstraintCheck {
+
+ private static final ObjectMapper MAPPER = new ObjectMapper();
+
+ /** The shape types a Query parameter can carry on its own, without an index or an entry. */
+ private static final Set The vendored file carries one wave of operations rather than all 180, and grows a wave at a
+ * time: the managed-policy family first, where no operation checks a declared constraint by hand,
+ * so the model adds the refusals AWS answers without rewording an answer already given.
+ * {@code AttachRolePolicy} and {@code DetachRolePolicy} are the exception and the parity case,
+ * {@code IamService.validateRoleName} already answering {@code roleName} in the same form.
+ */
+final class IamRequestShapes {
+
+ private static final QueryConstraintCheck CHECK =
+ QueryConstraintCheck.load("aws/iam-request-shapes.json", "IAM request shapes");
+
+ private IamRequestShapes() {
+ }
+
+ /** Throws {@code ValidationError} when the request breaks a constraint the model declares. */
+ static void check(String action, MultivaluedMap {@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.
+ *
+ * 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"));
+ }
+}
diff --git a/tools/aws/regen_iam_shapes.py b/tools/aws/regen_iam_shapes.py
new file mode 100644
index 0000000000..3908057f50
--- /dev/null
+++ b/tools/aws/regen_iam_shapes.py
@@ -0,0 +1,68 @@
+#!/usr/bin/env python3
+"""Vendor IAM request constraints from botocore's Apache-2.0 service model.
+
+`IamRequestShapes` checks the operations listed here against the vendored file through the shared
+`QueryConstraintCheck`: required members, lengths, patterns and enum values, as the model states
+them. The list grows an operation at a time, each one taken off the hand-written checks in the
+same change, so a wave is always reviewable against the messages it replaces.
+
+Run from anywhere in the repo:
+ python3 tools/aws/regen_iam_shapes.py # rewrite the vendored file in place
+ python3 tools/aws/regen_iam_shapes.py --check # exit 1 when the vendored file is stale
+"""
+from __future__ import annotations
+
+import argparse
+import json
+import sys
+from pathlib import Path
+
+from regen_partitions import resolve_botocore_data, strip_source
+from request_shapes import REPO_ROOT, build_constraints, load_model
+
+OUTPUT = REPO_ROOT / "src/main/resources/aws/iam-request-shapes.json"
+MODEL = Path("iam/2010-05-08")
+GENERATOR = "tools/aws/regen_iam_shapes.py"
+
+# The managed-policy family: every member a scalar, and no operation here checks a declared
+# constraint by hand today, so the vendored shapes add the refusals AWS answers without rewording
+# anything already answered. `AttachRolePolicy` and `DetachRolePolicy` are the exception and the
+# parity case: `IamService.validateRoleName` already answers `roleName` in Smithy's form.
+OPERATIONS = (
+ "AttachGroupPolicy", "AttachRolePolicy", "AttachUserPolicy",
+ "DetachGroupPolicy", "DetachRolePolicy", "DetachUserPolicy",
+ "GetPolicy", "DeletePolicy",
+ "CreatePolicyVersion", "GetPolicyVersion", "DeletePolicyVersion", "SetDefaultPolicyVersion",
+)
+
+
+def build(model: dict, provenance: str) -> dict:
+ return build_constraints(model, OPERATIONS, provenance, GENERATOR)
+
+
+def render(doc: dict) -> str:
+ return json.dumps(doc, indent=2) + "\n"
+
+
+def main(argv: list[str] | None = None) -> int:
+ parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
+ parser.add_argument("--check", action="store_true", help="exit 1 when the vendored file differs from a fresh generation")
+ parser.add_argument("--botocore-data", type=Path, help="botocore data directory")
+ parser.add_argument("--output", type=Path, default=OUTPUT, help=argparse.SUPPRESS)
+ args = parser.parse_args(argv)
+ data, provenance = resolve_botocore_data(args.botocore_data)
+ fresh = render(build(load_model(data, MODEL), provenance))
+ if args.check:
+ current = args.output.read_text(encoding="utf-8") if args.output.exists() else ""
+ if strip_source(current) != strip_source(fresh):
+ print(f"{args.output} is stale (generated from {provenance}).", file=sys.stderr)
+ return 1
+ return 0
+ args.output.write_text(fresh, encoding="utf-8")
+ shown = args.output.relative_to(REPO_ROOT) if args.output.is_relative_to(REPO_ROOT) else args.output
+ print(f"wrote {shown} from {provenance}")
+ return 0
+
+
+if __name__ == "__main__":
+ sys.exit(main())
diff --git a/tools/aws/test_regen_iam_shapes.py b/tools/aws/test_regen_iam_shapes.py
new file mode 100644
index 0000000000..79fe9d406a
--- /dev/null
+++ b/tools/aws/test_regen_iam_shapes.py
@@ -0,0 +1,88 @@
+"""Tests for regen_iam_shapes.
+
+Run with: pytest tools/aws -q (or: make aws-data-test)
+"""
+from __future__ import annotations
+
+import json
+
+import pytest
+
+import regen_iam_shapes as r
+
+
+MODEL = {
+ "operations": {
+ "GetPolicy": {"input": {"shape": "GetPolicyRequest"}, "output": {"shape": "GetPolicyResponse"}},
+ "ListPolicies": {"input": {"shape": "ListPoliciesRequest"}},
+ },
+ "shapes": {
+ "GetPolicyRequest": {"type": "structure", "required": ["PolicyArn"], "members": {
+ "PolicyArn": {"shape": "arnType"},
+ }},
+ "GetPolicyResponse": {"type": "structure", "members": {"Policy": {"shape": "arnType"}}},
+ "ListPoliciesRequest": {"type": "structure", "members": {"MaxItems": {"shape": "maxItemsType"}}},
+ "arnType": {"type": "string", "min": 20, "max": 2048},
+ "maxItemsType": {"type": "integer", "min": 1, "max": 1000},
+ },
+}
+
+
+def test_keeps_only_the_listed_operations_with_their_constraints(monkeypatch):
+ monkeypatch.setattr(r, "OPERATIONS", ("GetPolicy",))
+
+ doc = r.build(MODEL, "botocore test")
+
+ assert doc["_source"] == {"generator": "tools/aws/regen_iam_shapes.py", "botocore": "botocore test"}
+ assert doc["operations"] == {"GetPolicy": "GetPolicyRequest"}
+ assert "GetPolicyResponse" not in doc["shapes"]
+ assert "maxItemsType" not in doc["shapes"]
+ assert doc["shapes"]["GetPolicyRequest"] == {
+ "type": "structure", "required": ["PolicyArn"], "members": {"PolicyArn": "arnType"}}
+ assert doc["shapes"]["arnType"] == {"type": "string", "min": 20, "max": 2048}
+
+
+def test_a_misspelled_operation_is_refused_rather_than_skipped(monkeypatch):
+ monkeypatch.setattr(r, "OPERATIONS", ("GetPolciy",))
+
+ with pytest.raises(KeyError):
+ r.build(MODEL, "botocore test")
+
+
+def test_the_vendored_file_carries_every_listed_operation():
+ doc = json.loads(r.OUTPUT.read_text(encoding="utf-8"))
+
+ assert sorted(doc["operations"]) == sorted(r.OPERATIONS)
+ for operation, shape in doc["operations"].items():
+ assert shape in doc["shapes"], operation
+
+
+def test_check_ignores_provenance(tmp_path, monkeypatch):
+ monkeypatch.setattr(r, "OPERATIONS", ("GetPolicy",))
+ output = tmp_path / "shapes.json"
+ output.write_text(r.render(r.build(MODEL, "botocore 0.0.1 (local/aws/botocore)")), encoding="utf-8")
+ monkeypatch.setattr(r, "resolve_botocore_data", lambda explicit: (tmp_path, "--botocore-data /elsewhere"))
+ monkeypatch.setattr(r, "load_model", lambda data, model: MODEL)
+
+ assert r.main(["--check", "--output", str(output)]) == 0
+
+
+def test_check_reports_a_changed_constraint(tmp_path, monkeypatch):
+ monkeypatch.setattr(r, "OPERATIONS", ("GetPolicy",))
+ output = tmp_path / "shapes.json"
+ changed = {**MODEL, "shapes": {**MODEL["shapes"], "arnType": {"type": "string", "min": 1, "max": 2048}}}
+ output.write_text(r.render(r.build(changed, "botocore test")), encoding="utf-8")
+ monkeypatch.setattr(r, "resolve_botocore_data", lambda explicit: (tmp_path, "botocore test"))
+ monkeypatch.setattr(r, "load_model", lambda data, model: MODEL)
+
+ assert r.main(["--check", "--output", str(output)]) == 1
+
+
+def test_output_is_stable(monkeypatch):
+ monkeypatch.setattr(r, "OPERATIONS", ("GetPolicy", "ListPolicies"))
+
+ first = r.render(r.build(MODEL, "botocore test"))
+ second = r.render(r.build(MODEL, "botocore test"))
+
+ assert first == second
+ assert first.endswith("\n")