#!/usr/bin/env python3 """Tests for fetch_sts_source_identity.py, on a page in the IAM user guide's markup.""" from __future__ import annotations import pytest import fetch_sts_source_identity as f PERMISSIONS = ("
To specify a source identity, "
"principals (IAM users and roles) must have permissions to sts:SetSourceIdentity. As the "
"administrator, you can configure this.
When you assume a role with another role, called "
"role chaining, permissions for sts:SetSourceIdentity are required in both the "
"permissions policy of the principal who is assuming the role and in the role trust policy of the "
"target role. Otherwise, the assume role operation will fail.
Trust policies for all roles connected to an identity "
"provider (IdP) must have the sts:SetSourceIdentity permission.
The value that is set " "persists when a role is used to " "assume another role through the AWS CLI or AWS API, known as role chaining. The value that is set " "cannot be changed during the role session.
When an identity sets a source identity, the "
"sts:SourceIdentity key is present in the request. For subsequent actions taken during the "
"role session, the aws:SourceIdentity key is present in the request.
To pass source identity while assuming a role, use "
"the -–source-identity AWS CLI option or the SourceIdentity AWS API "
"parameter.
To set a SAML attribute for source identity, include "
"the Attribute element with the Name attribute set to "
"https://aws.amazon.com/SAML/Attributes/SourceIdentity. Use the AttributeValue "
"element.
Include source identity in the "
'https://aws.amazon.com/'
"source_identity namespace in the token when you submit the request.
Nothing to read here.
" CHAINED = ("Therefore, both the "
"aws:SourceIdentity and sts:SourceIdentity keys are present in the request "
"context.
sts:SetSourceIdentity",
"permissions for sts:SetOther"),
ASSUME_ROLE, CHAINED))
with pytest.raises(ValueError, match="a role an identity provider is connected to"):
f.build(lambda url: page(THINGS.replace("must have the sts:SetSourceIdentity permission",
"must have the sts:Other permission"),
PERMISSIONS, ASSUME_ROLE, CHAINED))
with pytest.raises(ValueError, match="other keys for a chained request"):
f.build(lambda url: page(THINGS, PERMISSIONS, ASSUME_ROLE,
CHAINED.replace("aws:SourceIdentity", "aws:Other")))
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(THINGS, PERMISSIONS, ASSUME_ROLE.replace("SourceIdentity", "Identity"),
CHAINED))