[iam] create_policy_version: Fix version id calculation

When creating a new IAM policy version with create_policy_version,
we cannot use the length of the versions list to calculate VersionId.
Keep track of the next version id to use as a non-decreasing counter.

Fixes #2157
This commit is contained in:
Santosh Ananthakrishnan 2019-04-16 19:29:48 +00:00
commit 4f1a1a9d1e
2 changed files with 19 additions and 3 deletions

View file

@ -303,8 +303,17 @@ def test_create_policy_versions():
PolicyDocument='{"some":"policy"}')
version = conn.create_policy_version(
PolicyArn="arn:aws:iam::123456789012:policy/TestCreatePolicyVersion",
PolicyDocument='{"some":"policy"}')
PolicyDocument='{"some":"policy"}',
SetAsDefault=True)
version.get('PolicyVersion').get('Document').should.equal({'some': 'policy'})
version.get('PolicyVersion').get('VersionId').should.equal("v2")
conn.delete_policy_version(
PolicyArn="arn:aws:iam::123456789012:policy/TestCreatePolicyVersion",
VersionId="v1")
version = conn.create_policy_version(
PolicyArn="arn:aws:iam::123456789012:policy/TestCreatePolicyVersion",
PolicyDocument='{"some":"policy"}')
version.get('PolicyVersion').get('VersionId').should.equal("v3")
@mock_iam