Files
floci/tools/aws/test_fetch_iam_account_property_namespaces.py
T
Priamo Germosen 8440821793 fix(iam): read iam:AccountPropertyNamespaces from the keys PutAccountProperties sets (#9736)
The generated IAM condition key table had iam:AccountPropertyNamespaces in notRead on both actions the Service
Reference lists it on, so a policy keyed on it matched nothing: the IAM user guide's DenyRoleManagerEnablement
statement, ForAnyValue:StringEquals on RoleManager, let a caller enable role manager, and an Allow requiring the
namespace refused every call.

Neither botocore nor the Service Reference says where the value is; AWS's pages do. The IAM user guide's condition
key table: iam:AccountPropertyNamespaces "Specifies the account property namespaces being read or modified in the
request ... When you call PutAccountProperties or GetAccountProperties". The API reference on PutAccountProperties'
Properties: "Each key uses the format Namespace/PropertyName. The key must contain exactly one / separating the
namespace from the property name". tools/aws/fetch_iam_account_property_namespaces.py copies both sentences into
tools/aws/sources/iam-account-property-namespaces.json with what they name: the key, the operation, the parameter,
the format, its separator and the part that is the namespace. regen_iam_condition_keys.py takes that entry as it
stands, refusing it unless the Service Reference lists the pair and botocore models the parameter as a map of
strings, and writes it to a new fromMapKeys section, which the IAM context resolver reads from the request's map as
the operation's handler does. GetAccountProperties names no properties, so it stays in notRead.
2026-11-29 08:40:07 -04:00

77 lines
4.8 KiB
Python

#!/usr/bin/env python3
"""Tests for fetch_iam_account_property_namespaces.py, on pages in the IAM user guide's and API reference's markup."""
from __future__ import annotations
import pytest
import fetch_iam_account_property_namespaces as f
KEY = ('<dt><b><span class="term"><div id="ck_AccountPropertyNamespaces"></div>iam:AccountPropertyNamespaces</span>'
'</b></dt><dd><p>Works with <a href="#">string operators</a>.</p><p>Specifies the account property namespaces '
'being read or modified in the\n request. Account properties are organized into namespaces (for example,\n '
'<code class="code">RoleManager</code>). When you call <code class="code">PutAccountProperties</code> or\n '
'<code class="code">GetAccountProperties</code>, use this condition key to restrict which\n property namespaces '
'a principal can access.</p></dd>')
OTHER_KEY = ('<dt><b><span class="term">iam:AssociatedResourceArn</span></b></dt><dd><p>Works with ARN operators.</p>'
'</dd>')
PROPERTIES = ('<dt><span class="term">\n <b>Properties</b>\n </span></dt>\n'
'<dt><span class="term">Properties.entry.N.key (key)</span></dt>\n'
'<dd><p>A map of property key-value pairs to set. All keys must belong to the same\n namespace.</p>'
'<p>Each key uses the format <code class="code">Namespace/PropertyName</code>. The key must contain\n'
' exactly one <code class="code">/</code> separating the namespace from the property name, and cannot\n'
' start or end with <code class="code">/</code>.</p><p>Type: String to string map</p></dd>')
NAME = '<dt><span class="term">\n <b>RoleName</b>\n </span></dt>\n<dd><p>The name of the role.</p></dd>'
def keys_page(*entries: str) -> str:
listed = "".join(entries) if entries else OTHER_KEY + KEY
return f'<div id="main-col-body"><h1>IAM condition keys</h1><dl>{listed}</dl></div><div class="prev-next"></div>'
def operation_page(*parameters: str, operation: str = "PutAccountProperties") -> str:
listed = "".join(parameters) if parameters else NAME + PROPERTIES
return (f'<div id="main-col-body"><h1 class="topictitle" id="API_{operation}">{operation}</h1>'
f'<h2 id="API_{operation}_RequestParameters">Request Parameters</h2><dl>{listed}</dl>'
f'<h2 id="API_{operation}_Errors">Errors</h2></div><div class="prev-next"></div>')
def pages(keys: str | None = None, operation: str | None = None):
return lambda url: (keys or keys_page()) if url == f.KEYS_PAGE else (operation or operation_page())
def test_the_key_is_read_from_the_part_of_each_key_the_operations_parameter_names_the_namespace():
built = f.build(pages())
assert built["key"]["key"] == "iam:AccountPropertyNamespaces"
assert built["key"]["operations"] == ["GetAccountProperties", "PutAccountProperties"]
# A parameter whose keys hold no namespace, as RoleName, is not read.
assert built["keys"] == [{
"operation": "PutAccountProperties", "member": "Properties", "key": "iam:AccountPropertyNamespaces",
"format": "Namespace/PropertyName", "separator": "/", "part": "Namespace",
"row": "Each key uses the format Namespace/PropertyName. The key must contain exactly one / separating the "
"namespace from the property name, and cannot start or end with /."}]
def test_a_page_whose_layout_or_wording_changed_is_refused():
with pytest.raises(ValueError, match="what iam:AccountPropertyNamespaces is"):
f.build(pages(keys=keys_page(KEY.replace("being read or modified", "being changed"))))
with pytest.raises(ValueError, match="gives 0 request parameters"):
f.build(pages(operation=operation_page(NAME)))
with pytest.raises(ValueError, match="gives 0 request parameters"):
f.build(pages(operation=operation_page(PROPERTIES.replace("the namespace from", "the scope from"))))
with pytest.raises(ValueError, match="which operation it is for"):
f.build(pages(operation=operation_page().replace('class="topictitle"', 'class="title"')))
def test_an_operation_page_the_guide_does_not_name_for_the_key_is_refused():
with pytest.raises(ValueError, match="not to PutRolePolicy"):
f.build(pages(operation=operation_page(operation="PutRolePolicy")))
def test_the_file_is_stale_when_a_page_says_something_else():
vendored = f.build(pages())
assert not f.stale(vendored, pages())
assert f.stale(vendored, pages(operation=operation_page(PROPERTIES.replace("Namespace/PropertyName",
"Namespace:PropertyName")
.replace('<code class="code">/</code> separating',
'<code class="code">:</code> separating'))))