Files
floci/tools/aws/test_regen_query_services.py
T
Priamo Germosen 30d8d3ff5c fix(core): route a Query action by its service's botocore model (#5879)
A Query request without a usable credential scope is routed by its
Action and Version, and IAM enforcement authorizes it under the service
that routing picks. The names each service routed were kept by hand in
AwsQueryController and had drifted from what the services serve: 170
names Floci dispatches, across eight services, reached no service and
fell through to SQS. They answered UnsupportedOperation in SQS's
namespace and were authorized as SQS actions.

Each Query service's API versions and operations now come from its
botocore models: tools/aws/regen_query_services.py writes them, from the
pinned botocore, to aws/query-services.json, and make aws-data-check
fails when the file is stale. Every name a service defines reaches it,
implemented here or not. Floci keeps the list of services and their
order, Cognito's names, which no Query model holds, and ElastiCache's
ValidateIamAuthToken, which no model defines.

A name several services define goes to the first of them when the
request names no Version. Ten such names get a pinned owner instead,
the service that serves them here, where the order would pick an
earlier one that does not. The routing parity test checks every
dispatched action with and without a Version and no longer needs its
list of known gaps.
2026-10-17 10:17:18 -05:00

65 lines
2.7 KiB
Python

"""Tests for regen_query_services.
Run with: pytest tools/aws -q (or: make aws-data-test)
"""
from __future__ import annotations
import json
import regen_query_services as r
def model(api_version: str, *operations: str) -> dict:
return {"metadata": {"apiVersion": api_version}, "operations": {name: {} for name in operations}}
def test_a_service_gets_every_operation_and_version_of_its_models():
doc = r.build({
"rds": [model("2014-10-31", "CreateDBCluster", "DescribeEvents"),
model("2014-10-31", "CreateDBCluster", "CreateGlobalCluster")],
"elasticloadbalancing": [model("2015-12-01", "CreateLoadBalancer", "CreateTargetGroup"),
model("2012-06-01", "CreateLoadBalancer", "ConfigureHealthCheck")],
}, "botocore test")
assert doc["_source"] == {"generator": "tools/aws/regen_query_services.py", "botocore": "botocore test"}
assert doc["services"] == {
"elasticloadbalancing": {
"apiVersions": ["2012-06-01", "2015-12-01"],
"operations": ["ConfigureHealthCheck", "CreateLoadBalancer", "CreateTargetGroup"],
},
"rds": {
"apiVersions": ["2014-10-31"],
"operations": ["CreateDBCluster", "CreateGlobalCluster", "DescribeEvents"],
},
}
def test_the_latest_api_version_is_read(tmp_path):
for version in ("2014-09-01", "2016-11-15", "2015-10-01"):
(tmp_path / "ec2" / version).mkdir(parents=True)
assert r.latest_model_dir(tmp_path, "ec2").name == "2016-11-15"
def test_check_ignores_the_provenance_and_catches_a_changed_operation(tmp_path):
data = tmp_path / "data"
for name, models in r.SERVICES.items():
for index, botocore_model in enumerate(models):
directory = data / botocore_model / "2020-01-01"
directory.mkdir(parents=True, exist_ok=True)
(directory / "service-2.json").write_text(
json.dumps(model("2020-01-01", f"{name.title()}{index}")), encoding="utf-8")
output = tmp_path / "query-services.json"
assert r.main(["--botocore-data", str(data), "--output", str(output)]) == 0
assert r.main(["--check", "--botocore-data", str(data), "--output", str(output)]) == 0
stale = json.loads(output.read_text(encoding="utf-8"))
stale["_source"]["botocore"] = "another label"
output.write_text(json.dumps(stale), encoding="utf-8")
assert r.main(["--check", "--botocore-data", str(data), "--output", str(output)]) == 0
stale["services"]["sqs"]["operations"].append("Unlisted")
output.write_text(json.dumps(stale), encoding="utf-8")
assert r.main(["--check", "--botocore-data", str(data), "--output", str(output)]) == 1