Files
floci/tools/aws/test_fetch_route53_conditions.py
T
Priamo Germosen ee3970d6c9 fix(iam): read route53:VPCs from the vendored Route 53 developer guide (#9687)
Under enforcement a VPC association call scoped by route53:VPCs was refused for every VPC, as #8367 reports: the request condition key table never filled the key, so a condition on it never saw a value. Neither botocore nor the Service Reference says where a request carries the key or in what form.

Route 53's developer guide says both, in its table of condition keys: route53:VPCs "Represents a list of VPCs in the request of AssociateVPCWithHostedZone, DisassociateVPCFromHostedZone, ListHostedZonesByVPC, CreateHostedZone, CreateVPCAssociationAuthorization, and DeleteVPCAssociationAuthorization, in the format of "VPCId=<vpc-id>,VPCRegion=<region>". A vendored source, tools/aws/sources/route53-condition-keys.json, written by tools/aws/fetch_route53_conditions.py from that page, gives each key the table gives in a format of request members, with its operations and members, and the generator reads it for route53 (CONDITION_SOURCES) beside the record keys it already reads.

The table writes a key a format composes as that format with each member's place holding where the request carries it (VPCId={VPC.VPCId},VPCRegion={VPC.VPCRegion}), and a member of the query string as ? and its name (ListHostedZonesByVPC's ?vpcid and ?vpcregion), and the request condition reader fills the format from them, read from an XML body or the query string, when each member holds one value. A request naming no VPC, as a public CreateHostedZone does, carries none.

Route 53 reads the VPC only where its schema puts it, the VPC below the request's root, where IAM reads it, and refuses a second VPC, a second VPCId or VPCRegion, or a repeated vpcid or vpcregion query parameter with InvalidInput, as it already refuses a change batch naming an element twice. It used to take the first VPC anywhere in the body, so a request naming a denied VPC beside another carried no value for the Deny to match and still acted on the denied one.

Closes #8367.
2026-11-28 18:39:20 -04:00

48 lines
2.2 KiB
Python

#!/usr/bin/env python3
"""Tests for fetch_route53_conditions.py, on a page in the Route 53 developer guide's markup."""
from __future__ import annotations
import pytest
import fetch_route53_conditions as f
HEADER = "<tr><th>Route 53 Condition Key</th><th>API operations</th><th>Value type</th><th>Description</th></tr>"
def row(key: str, operations: str, description: str) -> str:
return (f"<tr><td><p>{key}</p></td><td><p>{operations}</p></td><td><p>Multi-valued</p></td>"
f"<td><p>{description}</p></td></tr>")
VPCS = row("route53:VPCs", "<p>AssociateVPCWithHostedZone</p><p>ListHostedZonesByVPC</p>",
'Represents a list of VPCs in the request of AssociateVPCWithHostedZone and ListHostedZonesByVPC, in the '
'format of "VPCId=&lt;vpc-id&gt;,VPCRegion=&lt;region&gt;')
ACTIONS = row("route53:ChangeResourceRecordSetsActions", "ChangeResourceRecordSets",
"Represents a list of actions in the request of ChangeResourceRecordSets.")
def page(rows: str = VPCS + ACTIONS) -> str:
return f'<div id="main-col-body"><table>{HEADER}{rows}</table></div><div class="prev-next"></div>'
def test_a_key_in_a_format_of_members_is_read_with_its_operations_and_members():
keys = {entry["key"]: entry for entry in f.build(lambda url: page())["keys"]}
assert keys["route53:VPCs"]["operations"] == ["AssociateVPCWithHostedZone", "ListHostedZonesByVPC"]
assert keys["route53:VPCs"]["format"] == "VPCId=<vpc-id>,VPCRegion=<region>"
assert keys["route53:VPCs"]["members"] == ["VPCId", "VPCRegion"]
# A row giving no format of members is not read here.
assert "route53:ChangeResourceRecordSetsActions" not in keys
def test_a_page_whose_layout_changed_is_refused():
with pytest.raises(ValueError, match="no table"):
f.build(lambda url: '<div id="main-col-body"><table><tr><th>Key</th></tr></table></div>')
with pytest.raises(ValueError, match="no key in a format"):
f.build(lambda url: page(ACTIONS))
def test_the_file_is_stale_when_the_page_says_something_else():
vendored = f.build(lambda url: page())
assert not f.stale(vendored, page())
assert f.stale(vendored, page(VPCS.replace("VPCRegion=", "Region=") + ACTIONS))