Skip to content

Can't effectively test code that uses aws-encryption-sdk with stubs #204

@philsnow

Description

@philsnow

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

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions