mirror of
https://github.com/floci-io/floci.git
synced 2026-11-26 15:21:05 -05:00
CreateTags and DeleteTags checked a vpce- ID in their Resources list on `*`, because the generated table learns each ID prefix from botocore's examples and botocore gives none for VPC endpoints. A grant on one endpoint was refused and a deny on it never applied. fetch_ec2_id_examples.py copies the identifier examples of the EC2 API reference's CreateVpcEndpoint page into tools/aws/sources/ec2-id-examples.json, and the generator matches their XML paths to botocore's output shapes, which gives VpcEndpointId the vpce- prefix. That prefix joins botocore's in the one prefix map and reads only the tagging calls' generic list, so DeleteVpcEndpoints keeps its typed reader. The source names its namespace and pages, and the shared source verifier checks it against the live page. The regenerated table also takes in what the Service Reference added on 2026-11-25: CloudWatch's omni-slo, experiment and lookup types, which its tag operations now act on, Elastic Load Balancing's proxy type and the amplifygen3 namespace. Co-authored-by: Andre Kurait <AndreKurait@gmail.com>
63 lines
2.5 KiB
Python
63 lines
2.5 KiB
Python
import html
|
|
import json
|
|
|
|
import pytest
|
|
|
|
import fetch_ec2_id_examples as f
|
|
|
|
|
|
def page(xml):
|
|
return '<pre class="programlisting"><code>' + html.escape(xml) + '</code></pre>'
|
|
|
|
|
|
RESPONSE = '''<CreateVpcEndpointResponse xmlns="https://example.test/ec2">
|
|
<vpcEndpoint><vpcEndpointId>vpce-abc12345</vpcEndpointId>
|
|
<networkInterfaceIdSet><item>eni-cd1a3319</item></networkInterfaceIdSet>
|
|
<serviceName>com.amazonaws.us-east-1.s3</serviceName></vpcEndpoint>
|
|
</CreateVpcEndpointResponse>'''
|
|
|
|
|
|
def test_copies_response_paths_and_values_without_assigning_resource_types():
|
|
assert f.read_examples("CreateVpcEndpoint", page(RESPONSE)) == [
|
|
{"path": ["vpcEndpoint", "vpcEndpointId"], "value": "vpce-abc12345"},
|
|
{"path": ["vpcEndpoint", "networkInterfaceIdSet", "item"], "value": "eni-cd1a3319"},
|
|
]
|
|
|
|
|
|
def test_ignores_request_blocks_and_other_operations():
|
|
other = page(RESPONSE.replace("CreateVpcEndpointResponse", "OtherResponse"))
|
|
assert f.read_examples("CreateVpcEndpoint", other + page("VpcEndpointId=vpce-ffffffff") + page(RESPONSE)) == \
|
|
f.read_examples("CreateVpcEndpoint", page(RESPONSE))
|
|
|
|
|
|
@pytest.mark.parametrize("source", ["", page("not XML"), page(RESPONSE.replace("vpce-abc12345", "none")
|
|
.replace("eni-cd1a3319", "none"))])
|
|
def test_missing_response_identifiers_fail_closed(source):
|
|
with pytest.raises(ValueError):
|
|
f.read_examples("CreateVpcEndpoint", source)
|
|
|
|
|
|
def test_malformed_response_is_not_silently_omitted():
|
|
with pytest.raises(ValueError, match="malformed XML"):
|
|
f.read_examples("CreateVpcEndpoint", page(RESPONSE.replace("</vpcEndpoint>", "")))
|
|
|
|
|
|
def test_verification_detects_changed_examples_and_ignores_retrieval_date(tmp_path, monkeypatch):
|
|
output = tmp_path / "examples.json"
|
|
monkeypatch.setattr(f, "OUTPUT", output)
|
|
fetch = lambda url: page(RESPONSE)
|
|
assert f.main([], fetch) == 0
|
|
source = json.loads(output.read_text())
|
|
source["_source"]["retrieved"] = "2000-01-01"
|
|
output.write_text(json.dumps(source))
|
|
assert f.main(["--verify"], fetch) == 0
|
|
assert f.main(["--verify"], lambda url: page(RESPONSE.replace("vpce-abc12345", "vpce-ffffffff"))) == 1
|
|
|
|
|
|
def test_source_declares_namespace_and_pages_for_shared_verification():
|
|
source = f.build({url: page(RESPONSE) for url in f.PAGES.values()})
|
|
assert source["namespace"] == "ec2"
|
|
assert source["_source"]["pages"] == list(f.PAGES.values())
|
|
source["namespace"] = "other"
|
|
assert f.stale(source, {url: page(RESPONSE) for url in f.PAGES.values()})
|