-
Notifications
You must be signed in to change notification settings - Fork 84
Description
I'm trying to write some code that consumes aws-encryption-sdk
, specifically KMSMasterKeyProvider
. Everything works fine but I would like to add tests with stubbed out KMS requests+responses (using botocore.stub.Stubber
'ed boto3 clients).
My test setup creates a botocore session with fake credentials, e.g.
@pytest.fixture
def botocore_session():
session = botocore.session.get_session()
session.set_credentials("invalid-access-key", "invalid-secret-key")
session.set_stream_logger('', 'DEBUG')
return session
and then passes that session down into the KMSMasterKeyProvider
constructor. However, I can't also pass in a boto3 KMS client object for it to use. It creates its own clients here
aws-encryption-sdk-python/src/aws_encryption_sdk/key_providers/kms.py
Lines 163 to 167 in 0f4dc6e
if region_name not in self._regional_clients: | |
session = boto3.session.Session(botocore_session=self.config.botocore_session) | |
client = session.client("kms", region_name=region_name, config=self._user_agent_adding_config) | |
self._register_client(client, region_name) | |
self._regional_clients[region_name] = client |
I could create a KMSMasterKeyProvider
object in my test setup, reach into its ._regional_clients
and add my stubbed KMS client, and inject that into my code. Is that the best approach for now? Is there some other approach to stubbing that I should try?