diff --git a/src/main/java/io/floci/aws/services/iam/IamRestRoutes.java b/src/main/java/io/floci/aws/services/iam/IamRestRoutes.java index 94818cf52ed..a0faca44d73 100644 --- a/src/main/java/io/floci/aws/services/iam/IamRestRoutes.java +++ b/src/main/java/io/floci/aws/services/iam/IamRestRoutes.java @@ -52,8 +52,7 @@ * it. * *

The file is generated by {@code tools/aws/regen_rest_routes.py}, which fails when one route names two - * operations of a credential scope read here. The scopes it lists as {@code handRouted} are not read: the - * registry's rules authorize them alone. A missing or malformed resource is a build defect, so loading fails with + * operations of a credential scope. A missing or malformed resource is a build defect, so loading fails with * {@link IllegalStateException} rather than leaving every route it holds unchecked. */ final class IamRestRoutes { @@ -293,12 +292,10 @@ boolean takesPath(String scope, String path, MultivaluedMap quer static IamRestRoutes parse(InputStream in) throws IOException { JsonNode document = MAPPER.readTree(in); - JsonNode handRouted = document == null ? null : document.path("handRouted"); JsonNode models = document == null ? null : document.path("models"); - if (handRouted == null || !handRouted.isObject() || !models.isObject() || models.isEmpty()) { - throw new IllegalStateException(RESOURCE_NAME + " carries no handRouted scopes or no models"); + if (models == null || !models.isObject() || models.isEmpty()) { + throw new IllegalStateException(RESOURCE_NAME + " carries no models"); } - Set skipped = Set.copyOf(handRouted.propertyStream().map(Map.Entry::getKey).toList()); Map>> routes = new HashMap<>(); Map denialStatuses = new HashMap<>(); Set documentedScopes = new HashSet<>(); @@ -321,9 +318,6 @@ static IamRestRoutes parse(InputStream in) throws IOException { + " conflicting access-denied HTTP statuses"); } } - if (skipped.contains(scope)) { - return; - } JsonNode documentation = model.getValue().path("documented"); if (!documentation.isMissingNode() && !documentation.isObject()) { throw new IllegalStateException(RESOURCE_NAME + " gives model " + model.getKey() diff --git a/src/main/resources/aws/rest-routes.json b/src/main/resources/aws/rest-routes.json index 6b3b3e14ef8..409cf4a5f49 100644 --- a/src/main/resources/aws/rest-routes.json +++ b/src/main/resources/aws/rest-routes.json @@ -1,7 +1,5 @@ { "_source": {"generator": "tools/aws/regen_rest_routes.py", "botocore": "botocore 1.43.118 (installed package)"}, - "handRouted": { - }, "models": { "accessanalyzer": { "credentialScope": "access-analyzer", diff --git a/src/test/java/io/floci/aws/services/iam/IamActionRegistryTest.java b/src/test/java/io/floci/aws/services/iam/IamActionRegistryTest.java index 51242a3f461..cc0715c78cf 100644 --- a/src/test/java/io/floci/aws/services/iam/IamActionRegistryTest.java +++ b/src/test/java/io/floci/aws/services/iam/IamActionRegistryTest.java @@ -53,8 +53,7 @@ class IamActionRegistryTest { @Test void aRouteNoRuleMapsIsCheckedAsItsOperationWhenFlociChecksItAsAwsDoes() throws IOException { IamRestRoutes routes = IamRestRoutes.parse(new ByteArrayInputStream(""" - {"handRouted": {}, - "models": { + {"models": { "opensearch": {"credentialScope": "es", "operations": { "ListDomainNames": {"method": "GET", "requestUri": "/unmapped/domain"}, "DescribeDomain": {"method": "GET", "requestUri": "/unmapped/domain/{DomainName}"} diff --git a/src/test/java/io/floci/aws/services/iam/IamRestRouteCoverageTest.java b/src/test/java/io/floci/aws/services/iam/IamRestRouteCoverageTest.java index 67dfedfc78d..213a6c04981 100644 --- a/src/test/java/io/floci/aws/services/iam/IamRestRouteCoverageTest.java +++ b/src/test/java/io/floci/aws/services/iam/IamRestRouteCoverageTest.java @@ -201,17 +201,9 @@ Stream everyRouteOfARoutedScopeIsItsOperationByTheVendoredRoutesAlo return tests.stream(); } - /** The models of every credential scope the vendored routes do not list as hand-routed. */ + /** The models of every credential scope the vendored routes read. */ private static List routedModels(JsonNode document) { - List models = new ArrayList<>(); - Iterator> all = document.path("models").fields(); - while (all.hasNext()) { - Map.Entry model = all.next(); - if (!document.path("handRouted").has(model.getValue().path("credentialScope").asText())) { - models.add(model.getKey()); - } - } - return models; + return document.path("models").propertyStream().map(Map.Entry::getKey).toList(); } /** Every model route of {@code operation} among the models Floci authorizes under {@code scope}. */ @@ -222,10 +214,8 @@ private static List routesOf(JsonNode models, String scope, String operat Map.Entry model = all.next(); JsonNode route = model.getValue().path("operations").path(operation); if (scope.equals(model.getValue().path("credentialScope").asText()) && !route.isMissingNode()) { - // A hand-routed scope's route lists all its request must carry; another's what tells it apart. - JsonNode carries = route.has("required") ? route.path("required") : route.path("requires"); routes.add(new Route(scope, model.getKey(), operation, route.path("method").asText(), - route.path("requestUri").asText(), carries)); + route.path("requestUri").asText(), route.path("requires"))); } } return routes; @@ -241,11 +231,9 @@ private static JsonNode load(String resource) throws IOException { } } - /** An operation's route: its method, and its request URI with each label filled in. */ /** - * A route of a model's operation, and what botocore requires its request to carry ({@code required} for a - * hand-routed scope's, {@code requires} where several operations share it), which the request built on it carries - * as an SDK sends it. + * A route of a model's operation, and what botocore requires its request to carry where several operations share + * it ({@code requires}), which the request built on it carries as an SDK sends it. */ private record Route(String scope, String model, String operation, String method, String requestUri, JsonNode requires) { diff --git a/src/test/java/io/floci/aws/services/iam/IamRestRoutesTest.java b/src/test/java/io/floci/aws/services/iam/IamRestRoutesTest.java index 4bf4c1a3452..e6fe1c230cb 100644 --- a/src/test/java/io/floci/aws/services/iam/IamRestRoutesTest.java +++ b/src/test/java/io/floci/aws/services/iam/IamRestRoutesTest.java @@ -25,8 +25,7 @@ class IamRestRoutesTest { private static final String ROUTES = """ - {"handRouted": {"hand": "the rules route it alone"}, - "models": { + {"models": { "svc": {"credentialScope": "svc", "operations": { "ListThings": {"method": "GET", "requestUri": "/things/"}, "GetThing": {"method": "GET", "requestUri": "/things/{ThingName}"}, @@ -40,9 +39,6 @@ class IamRestRoutesTest { "ListVersionsV2": {"method": "GET", "requestUri": "/versions?list-type=2"}, "ValidateThing": {"method": "GET", "requestUri": "/from.data/validation"}, "GetRoot": {"method": "GET", "requestUri": "/"} - }}, - "hand": {"credentialScope": "hand", "operations": { - "Ping": {"method": "GET", "requestUri": "/ping"} }} }}"""; @@ -143,7 +139,7 @@ void routeDataIsBundledWithTheApplicationRatherThanOnlyWithTests() throws Except void denialStatusComesFromTheModelAndFallsBackWhenMissing() { IamRestRoutes modelled = routes(ROUTES.replace("\"credentialScope\": \"svc\"", "\"credentialScope\": \"svc\", \"accessDeniedStatus\": 402")); assertEquals(402, modelled.accessDeniedStatus("svc", 403)); - assertEquals(403, modelled.accessDeniedStatus("hand", 403)); + assertEquals(403, modelled.accessDeniedStatus("other", 403)); assertEquals(400, modelled.accessDeniedStatus("unknown", 400)); assertEquals(403, modelled.accessDeniedStatus(null, 403)); } @@ -157,8 +153,13 @@ void invalidModelledDenialStatusesAreRejected(String status) { @Test void modelsSharingAScopeMustAgreeOnTheDenialStatus() { - String document = ROUTES.replace("\"credentialScope\": \"svc\"", "\"credentialScope\": \"svc\", \"accessDeniedStatus\": 401") - .replace("\"credentialScope\": \"hand\"", "\"credentialScope\": \"svc\", \"accessDeniedStatus\": 403"); + String document = """ + {"models": { + "one": {"credentialScope": "svc", "accessDeniedStatus": 401, + "operations": {"GetOne": {"method": "GET", "requestUri": "/one"}}}, + "two": {"credentialScope": "svc", "accessDeniedStatus": 403, + "operations": {"GetTwo": {"method": "GET", "requestUri": "/two"}}} + }}"""; assertThrows(IllegalStateException.class, () -> routes(document)); } @@ -219,7 +220,7 @@ void aQueryTheRouteNamesMustBeOnTheRequest() { @Test void operationsSharingARouteAreToldApartByWhatTheirRequestMustCarry() { IamRestRoutes table = routes(""" - {"handRouted": {}, "models": {"objects": {"credentialScope": "obj", "operations": { + {"models": {"objects": {"credentialScope": "obj", "operations": { "PutObject": {"method": "PUT", "requestUri": "/{Bucket}/{Key+}"}, "CopyObject": {"method": "PUT", "requestUri": "/{Bucket}/{Key+}", "requires": {"headers": ["x-amz-copy-source"]}}, @@ -248,7 +249,7 @@ void operationsSharingARouteAreToldApartByWhatTheirRequestMustCarry() { @Test void aDeprecatedOperationYieldsToTheCurrentOneOfItsRoute() { IamRestRoutes table = routes(""" - {"handRouted": {}, "models": {"objects": {"credentialScope": "obj", "operations": { + {"models": {"objects": {"credentialScope": "obj", "operations": { "GetBucketLifecycle": {"method": "GET", "requestUri": "/{Bucket}?lifecycle", "deprecated": true}, "GetBucketLifecycleConfiguration": {"method": "GET", "requestUri": "/{Bucket}?lifecycle"} }}}}"""); @@ -299,10 +300,9 @@ void aLiteralSegmentKeepsItsMatrixParameters() { } @Test - void aRequestOfAnotherMethodOrScopeOrOfAHandRoutedScopeMatchesNothing() { + void aRequestOfAnotherMethodOrScopeMatchesNothing() { assertEquals(Optional.empty(), routes.operation("svc", "DELETE", "/things/web", null)); assertEquals(Optional.empty(), routes.operation("other", "GET", "/things/web", null)); - assertEquals(Optional.empty(), routes.operation("hand", "GET", "/ping", null)); assertEquals(Optional.empty(), get("/nothing")); } @@ -349,7 +349,7 @@ void aRequestTwoOperationsRoutesTakeAlikeIsAmbiguous() { } @ParameterizedTest - @ValueSource(strings = {"", "{}", "{\"models\":[]}", "{\"handRouted\": {}, \"models\":{}}"}) + @ValueSource(strings = {"", "{}", "{\"models\":[]}", "{\"models\":{}}"}) void missingRouteDataFailsRatherThanProvidingAnEmptyAuthorizationTable(String document) { assertThrows(IllegalStateException.class, () -> routes(document)); } @@ -357,14 +357,13 @@ void missingRouteDataFailsRatherThanProvidingAnEmptyAuthorizationTable(String do @Test void aMalformedFileFailsToLoad() { for (String bad : List.of("{\"models\": {\"svc\": {\"credentialScope\": \"svc\", \"operations\": {}}}}", - "{\"handRouted\": {}, \"models\": {\"svc\": {\"credentialScope\": \"svc\", \"operations\": {}}}}", - "{\"handRouted\": {}, \"models\": {\"svc\": {\"operations\": {}}}}", - "{\"handRouted\": {}, \"models\": {\"svc\": {\"credentialScope\": \"svc\"}}}", - "{\"handRouted\": {}, \"models\": {\"svc\": {\"credentialScope\": \"svc\", \"operations\": " + "{\"models\": {\"svc\": {\"operations\": {}}}}", + "{\"models\": {\"svc\": {\"credentialScope\": \"svc\"}}}", + "{\"models\": {\"svc\": {\"credentialScope\": \"svc\", \"operations\": " + "{\"Op\": {\"requestUri\": \"/op\"}}}}}", - "{\"handRouted\": {}, \"models\": {\"svc\": {\"credentialScope\": \"svc\", \"operations\": " + "{\"models\": {\"svc\": {\"credentialScope\": \"svc\", \"operations\": " + "{\"Op\": {\"method\": \"INVALID\", \"requestUri\": \"/op\"}}}}}", - "{\"handRouted\": {}, \"models\": {\"svc\": {\"credentialScope\": \"svc\", \"operations\": " + "{\"models\": {\"svc\": {\"credentialScope\": \"svc\", \"operations\": " + "{\"Op\": {\"method\": \"GET\", \"requestUri\": \"op\"}}}}}")) { assertThrows(IllegalStateException.class, () -> routes(bad), bad); } diff --git a/tools/aws/regen_iam_authorized_actions.py b/tools/aws/regen_iam_authorized_actions.py index b0725153742..0c257d39624 100644 --- a/tools/aws/regen_iam_authorized_actions.py +++ b/tools/aws/regen_iam_authorized_actions.py @@ -66,15 +66,14 @@ `MEASURED_VERSIONED` give what the Service Authorization Reference's actions table does, quoted with its link. -The file also lists, for each credential scope whose REST routes `rest-routes.json` reads (the -scopes it leaves to the registry's rules, `handRouted`, aside), the actions of that namespace the -reference gives no resource type, from its `Actions`. A REST request no rule of `IamActionRegistry` -maps is checked as the operation whose route it matches only when that operation's action is one of -them. Floci checks a REST request on `*` until it reads the resources in its path, and AWS authorizes -such an action on `*` too, so the check is the one AWS makes. An action AWS authorizes on a resource -stays unchecked instead: checked on `*`, a grant scoped to its resource would be refused. These are -read from `Actions`, not `Operations`, because the reference lists the operations of one SDK client -per namespace: OpenSearch's are the `es` client's alone, none of the `opensearch` client's, whose +The file also lists, for each credential scope whose REST routes `rest-routes.json` reads, the actions +of that namespace the reference gives no resource type, from its `Actions`. A REST request no rule of +`IamActionRegistry` maps is checked as the operation whose route it matches only when that operation's +action is one of them. Floci checks a REST request on `*` until it reads the resources in its path, and +AWS authorizes such an action on `*` too, so the check is the one AWS makes. An action AWS authorizes on +a resource stays unchecked instead: checked on `*`, a grant scoped to its resource would be refused. +These are read from `Actions`, not `Operations`, because the reference lists the operations of one SDK +client per namespace: OpenSearch's are the `es` client's alone, none of the `opensearch` client's, whose operations are named after `es` actions all the same. It lists too, for those scopes, the operations a request on whose route is checked as the action its HTTP @@ -487,11 +486,8 @@ def _sdk_clients(namespace: str, operation: dict) -> set[str]: def routed_namespaces(routes: dict) -> list[str]: - """The credential scopes whose REST routes the vendored routes read: every model's but those the registry's - rules authorize alone.""" - hand_routed = routes.get("handRouted") or {} - return sorted({model["credentialScope"] for model in (routes.get("models") or {}).values() - if model["credentialScope"] not in hand_routed}) + """The credential scopes whose REST routes the vendored routes read: every model's.""" + return sorted({model["credentialScope"] for model in (routes.get("models") or {}).values()}) def actions_without_resource_types(documents: list[dict], namespaces: list[str]) -> dict[str, list[str]]: @@ -513,12 +509,9 @@ def actions_without_resource_types(documents: list[dict], namespaces: list[str]) def route_methods(routes: dict) -> dict[str, dict[str, list[str]]]: """Each routed scope's operations, with the HTTP methods of every route the vendored routes give them, an alternative's own method included.""" - routed = set(routed_namespaces(routes)) methods: dict[str, dict[str, set[str]]] = {} for model in (routes.get("models") or {}).values(): scope = model["credentialScope"] - if scope not in routed: - continue for operation, route in (model.get("operations") or {}).items(): found = methods.setdefault(scope, {}).setdefault(operation, set()) found.add(route["method"]) diff --git a/tools/aws/regen_rest_routes.py b/tools/aws/regen_rest_routes.py index b9a6b694f79..8ff14dd6067 100644 --- a/tools/aws/regen_rest_routes.py +++ b/tools/aws/regen_rest_routes.py @@ -9,21 +9,18 @@ `iam-authorized-actions.json` names for it, or as its own; `IamRestRouteCoverageTest` builds a request on each route and compares the action the registry gives with that one. -The credential scopes in `HAND_ROUTED`, none now, are authorized by the registry's rules alone, each for -its reason, and their routes are vendored for the coverage test only, each with the query parameters and -headers botocore requires its request to carry (`required`), which the registry's rules read. Operations -sharing a route are told apart by what botocore models their requests as carrying: the query parameters -and headers of the members their input requires (`requires`: S3's UploadPart, on `PUT /{Bucket}/{Key+}` -with PutObject, requires `partNumber` and `uploadId`, CopyObject the `x-amz-copy-source` header), and a -deprecated operation (`deprecated`) yields to a current one of the same route and conditions. An -operation whose every request botocore's endpoint rules send to another service's endpoint, signed for -it, is that service's (`signedElsewhere`: S3's ListDirectoryBuckets, signed `s3express`). Within any -scope, the operations of a route must leave every request one operation: no two current ones requiring -the same, and what any two require together required by one of them, the route requiring all a request -carries being its operation (`shared_routes`). The generation fails otherwise. Supported shared- -controller alternatives are generated beside the modeled URI, with member-location overrides for the -bare route, and its own method where that is not the operation's. These alternatives describe existing -Floci compatibility paths, not additional botocore operations. +Operations sharing a route are told apart by what botocore models their requests as carrying: the query +parameters and headers of the members their input requires (`requires`: S3's UploadPart, on +`PUT /{Bucket}/{Key+}` with PutObject, requires `partNumber` and `uploadId`, CopyObject the +`x-amz-copy-source` header), and a deprecated operation (`deprecated`) yields to a current one of the +same route and conditions. An operation whose every request botocore's endpoint rules send to another +service's endpoint, signed for it, is that service's (`signedElsewhere`: S3's ListDirectoryBuckets, +signed `s3express`). Within any scope, the operations of a route must leave every request one operation: +no two current ones requiring the same, and what any two require together required by one of them, the +route requiring all a request carries being its operation (`shared_routes`). The generation fails +otherwise. Supported shared-controller alternatives are generated beside the modeled URI, with +member-location overrides for the bare route, and its own method where that is not the operation's. +These alternatives describe existing Floci compatibility paths, not additional botocore operations. The models are botocore's `//service-2.json` (Apache-2.0, https://github.com/boto/botocore), the latest API version of each, located as @@ -61,9 +58,6 @@ REPO_ROOT = Path(__file__).resolve().parents[2] OUTPUT = REPO_ROOT / "src/main/resources/aws/rest-routes.json" -# Credential scopes the registry's rules authorize alone, and why. -HAND_ROUTED: dict[str, str] = {} - # botocore model -> the credential scope Floci authorizes its requests under. MODELS: dict[str, str] = { "accessanalyzer": "access-analyzer", @@ -386,7 +380,6 @@ def build(models: dict[str, dict], provenance: str, documented: dict[str, dict] raise SystemExit(f"error: {name} is both a botocore model and a documented endpoint") routes[name] = model routes = dict(sorted(routes.items())) - with_required(routes, models) with_conditions(routes, models) shared = shared_routes(routes) if shared: @@ -397,7 +390,6 @@ def build(models: dict[str, dict], provenance: str, documented: dict[str, dict] "generator": "tools/aws/regen_rest_routes.py", "botocore": provenance, }, - "handRouted": dict(sorted(HAND_ROUTED.items())), "models": routes, } @@ -414,19 +406,6 @@ def required_members(model: dict, operation: str) -> dict[str, list[str]]: return {**({"query": query} if query else {}), **({"headers": headers} if headers else {})} -def with_required(routes: dict[str, dict], models: dict[str, dict]) -> None: - """Each operation of a hand-routed scope given what its request must carry (`required`), for the coverage test to - build the request the registry's rules read; the routes of other scopes, which requests are matched on, need it only - where operations share them (`with_conditions`).""" - for name, model in routes.items(): - if model["credentialScope"] not in HAND_ROUTED or name not in models: - continue - for operation, route in model["operations"].items(): - required = required_members(models[name], operation) - if required: - route["required"] = required - - def with_conditions(routes: dict[str, dict], models: dict[str, dict]) -> None: """Each operation of a route that names several within its scope given what botocore models its request as carrying: the query parameters and headers of the members its input requires (`requires`), and whether botocore @@ -552,11 +531,7 @@ def load_models(data: Path) -> dict[str, dict]: def render(doc: dict) -> str: """The document with one operation to a line, so a model's routes read as a table.""" - lines = ["{", f' "_source": {json.dumps(doc["_source"])},', ' "handRouted": {'] - hand = list(doc["handRouted"].items()) - for position, (scope, reason) in enumerate(hand): - lines.append(f" {json.dumps(scope)}: {json.dumps(reason)}" + ("," if position < len(hand) - 1 else "")) - lines += [" },", ' "models": {'] + lines = ["{", f' "_source": {json.dumps(doc["_source"])},', ' "models": {'] models = list(doc["models"].items()) for index, (name, model) in enumerate(models): lines.append(f" {json.dumps(name)}: {{") diff --git a/tools/aws/test_regen_iam_authorized_actions.py b/tools/aws/test_regen_iam_authorized_actions.py index 30b3bab7f01..b00745be0a8 100644 --- a/tools/aws/test_regen_iam_authorized_actions.py +++ b/tools/aws/test_regen_iam_authorized_actions.py @@ -322,7 +322,7 @@ def test_generating_from_saved_files_writes_a_file_check_accepts(tmp_path): def no_routes(tmp_path) -> str: """A routes file reading no scope's routes.""" routes = tmp_path / "rest-routes.json" - routes.write_text(json.dumps({"handRouted": {}, "models": {}}), encoding="utf-8") + routes.write_text(json.dumps({"models": {}}), encoding="utf-8") return str(routes) @@ -367,12 +367,11 @@ def typed(namespace: str, actions: dict[str, list[str]]) -> dict: for name, kinds in actions.items()]} -ROUTES = {"handRouted": {"hand": "the rules route it alone"}, - "models": {"svc": {"credentialScope": "svc"}, "svc-v2": {"credentialScope": "svc"}, - "other": {"credentialScope": "other"}, "hand": {"credentialScope": "hand"}}} +ROUTES = {"models": {"svc": {"credentialScope": "svc"}, "svc-v2": {"credentialScope": "svc"}, + "other": {"credentialScope": "other"}}} -def test_the_routed_scopes_are_every_models_but_the_hand_routed_ones(): +def test_the_routed_scopes_are_every_models(): assert r.routed_namespaces(ROUTES) == ["other", "svc"] @@ -435,7 +434,7 @@ def by_method_service(operations: dict[str, list[str]], sdks: dict[str, list[str return document -METHOD_ROUTES = {"handRouted": {"hand": "the rules route it alone"}, "models": { +METHOD_ROUTES = {"models": { "api": {"credentialScope": "api", "operations": { "TagResource": {"method": "PUT", "requestUri": "/tags/{arn+}", "alternatives": [{"method": "POST", "requestUri": "/tags", "located": {"arn": "body"}}]}, @@ -444,8 +443,7 @@ def by_method_service(operations: dict[str, list[str]], sdks: dict[str, list[str "CreatePortal": {"method": "POST", "requestUri": "/portals"}}}, "api-v2": {"credentialScope": "api", "operations": { "TagResource": {"method": "POST", "requestUri": "/v2/tags/{arn+}"}, - "GetStage": {"method": "GET", "requestUri": "/v2/apis/{id}/stages/{name}"}}}, - "hand": {"credentialScope": "hand", "operations": {"GetThing": {"method": "GET", "requestUri": "/things"}}}}} + "GetStage": {"method": "GET", "requestUri": "/v2/apis/{id}/stages/{name}"}}}}} def test_the_route_methods_are_each_routed_operations_alternatives_included(): diff --git a/tools/aws/test_regen_rest_routes.py b/tools/aws/test_regen_rest_routes.py index 7834f2f2dba..fa187081391 100644 --- a/tools/aws/test_regen_rest_routes.py +++ b/tools/aws/test_regen_rest_routes.py @@ -85,12 +85,10 @@ def test_check_passes_on_a_fresh_generation_and_fails_on_a_stale_one(tmp_path, m assert r.main(data + ["--check"]) == 1 -def test_a_route_naming_two_operations_a_request_cannot_tell_apart_is_refused(monkeypatch): - monkeypatch.setattr(r, "HAND_ROUTED", {"s3": "the rules route it alone"}) +def test_a_route_naming_two_operations_a_request_cannot_tell_apart_is_refused(): with pytest.raises(SystemExit): r.build({"lambda": model("rest-json", "2015-03-31", GetByName=("GET", "/things/{Name}"), GetById=("GET", "/things/{Id}/"))}, "botocore test") - # A scope the rules route alone is checked too: its routes are what the coverage test builds requests on. with pytest.raises(SystemExit): r.build({"s3": model("rest-xml", "2006-03-01", PutObject=("PUT", "/{Bucket}/{Key+}"), UploadPart=("PUT", "/{Bucket}/{Key+}"))}, "botocore test") @@ -104,8 +102,7 @@ def test_a_route_naming_two_operations_a_request_cannot_tell_apart_is_refused(mo UploadPart=("PUT", "/{Bucket}/{Key+}")), "UploadPart", {"PartNumber": ("querystring", "partNumber"), "UploadId": ("querystring", "uploadId")}), }, "botocore test") - assert doc["handRouted"] == dict(sorted(r.HAND_ROUTED.items())) - assert set(doc["handRouted"]) == {"s3"} + assert "handRouted" not in doc # Only a route several operations share carries conditions; one operation in two models is one operation. assert "requires" not in doc["models"]["lambda"]["operations"]["ListTags"] assert "requires" not in doc["models"]["lambda"]["operations"]["GetThing"] @@ -191,15 +188,6 @@ def test_an_operation_signed_for_another_service_on_every_request_is_left_out_of r.build({"s3": s3}, "botocore test") -def test_the_hand_routed_scopes_are_rendered_with_their_reasons(monkeypatch): - monkeypatch.setattr(r, "HAND_ROUTED", {"s3": "the rules route it alone"}) - text = r.render(r.build({"s3": model("rest-xml", "2006-03-01", HeadBucket=("HEAD", "/{Bucket}"))}, - "botocore test")) - - assert json.loads(text)["handRouted"] == dict(sorted(r.HAND_ROUTED.items())) - assert text.splitlines()[2] == ' "handRouted": {' - - @pytest.mark.parametrize("status", [400, 401, 402, 403]) def test_denial_status_comes_from_the_declared_error_shape(status): service = model("rest-json", "2020-01-01", GetThing=("GET", "/things/{Name}")) @@ -456,17 +444,3 @@ def test_vendored_documented_routes_read_from_another_page_or_malformed_are_refu malformed["operations"]["GetCatalog"] = {"method": "FETCH", "requestUri": "/iceberg/v1/config"} with pytest.raises(SystemExit, match="malformed"): r.carried_documented(r.render(r.build({}, "test", {"glue-iceberg-rest": malformed}))) - - -def test_a_hand_routed_scopes_routes_list_all_their_requests_must_carry_for_the_coverage_test(monkeypatch): - monkeypatch.setattr(r, "HAND_ROUTED", {"s3": "the rules route it alone"}) - s3 = shaped(model("rest-xml", "2006-03-01", CompleteMultipartUpload=("POST", "/{Bucket}/{Key+}"), - PutObject=("PUT", "/{Bucket}/{Key+}")), - "CompleteMultipartUpload", {"UploadId": ("querystring", "uploadId")}) - lam = shaped(model("rest-json", "2015-03-31", GetThing=("GET", "/things/{Name}")), - "GetThing", {"Qualifier": ("querystring", "Qualifier")}) - doc = r.build({"s3": s3, "lambda": lam}, "botocore test") - assert doc["models"]["s3"]["operations"]["CompleteMultipartUpload"]["required"] == {"query": ["uploadId"]} - assert "required" not in doc["models"]["s3"]["operations"]["PutObject"] - # A routed scope's requests are matched on its routes, which carry only what tells shared ones apart. - assert "required" not in doc["models"]["lambda"]["operations"]["GetThing"]