Skip to content

Commit 16b6528

Browse files
committed
chore: add integration tests for AWS KMS keyrings
1 parent f7801c7 commit 16b6528

File tree

6 files changed

+89
-0
lines changed

6 files changed

+89
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
"""Dummy stub to make linters work better."""
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
"""Integration tests for ``aws_encryption_sdk.key_provider.kms``."""
4+
from test.integration.integration_test_utils import setup_kms_master_key_provider_with_botocore_session
5+
6+
import pytest
7+
from botocore.exceptions import BotoCoreError
8+
9+
from aws_encryption_sdk.key_providers.kms import KMSMasterKeyProvider
10+
11+
pytestmark = [pytest.mark.integ]
12+
13+
14+
def test_remove_bad_client():
15+
test = KMSMasterKeyProvider()
16+
fake_region = "us-fakey-12"
17+
test.add_regional_client(fake_region)
18+
19+
with pytest.raises(BotoCoreError):
20+
test._regional_clients[fake_region].list_keys()
21+
22+
assert fake_region not in test._regional_clients
23+
24+
25+
def test_regional_client_does_not_modify_botocore_session(caplog):
26+
mkp = setup_kms_master_key_provider_with_botocore_session()
27+
fake_region = "us-fakey-12"
28+
29+
assert mkp.config.botocore_session.get_config_variable("region") != fake_region
30+
mkp.add_regional_client(fake_region)
31+
assert mkp.config.botocore_session.get_config_variable("region") != fake_region

test/integration/keyrings/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
"""Dummy stub to make linters work better."""
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
"""Dummy stub to make linters work better."""
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
"""Integration tests for ``aws_encryption_sdk.keyrings.aws_kms.client_cache``."""
4+
import pytest
5+
from botocore.exceptions import BotoCoreError
6+
from botocore.session import Session
7+
8+
from aws_encryption_sdk.keyrings.aws_kms.client_cache import ClientCache
9+
10+
pytestmark = [pytest.mark.integ]
11+
12+
13+
def test_client_cache_removes_bad_client():
14+
cache = ClientCache()
15+
fake_region = "us-fake-1"
16+
17+
initial_client = cache.client(fake_region, "kms")
18+
19+
assert fake_region in cache._cache
20+
21+
with pytest.raises(BotoCoreError):
22+
initial_client.encrypt(KeyId="foo", Plaintext=b"bar")
23+
24+
assert fake_region not in cache._cache
25+
26+
27+
def test_regional_client_does_not_modify_botocore_session():
28+
cache = ClientCache(botocore_session=Session())
29+
fake_region = "us-fake-1"
30+
31+
assert cache._botocore_session.get_config_variable("region") != fake_region
32+
cache.client(fake_region, "kms")
33+
assert cache._botocore_session.get_config_variable("region") != fake_region
34+
35+
36+
def test_client_cache_remove_bad_client_when_already_removed():
37+
cache = ClientCache()
38+
fake_region = "us-fake-1"
39+
40+
initial_client = cache.client(fake_region, "kms")
41+
42+
assert fake_region in cache._cache
43+
del cache._cache[fake_region]
44+
45+
with pytest.raises(BotoCoreError):
46+
initial_client.encrypt(KeyId="foo", Plaintext=b"bar")
47+
48+
assert fake_region not in cache._cache

test/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ mock
22
pytest>=3.3.1
33
pytest-cov
44
pytest-mock
5+
moto>=1.3.14

0 commit comments

Comments
 (0)