def test_get_secret_string_empty(self):
     response = {}
     versions = {'01234567890123456789012345678901': ['AWSCURRENT']}
     version_response = {}
     cache = SecretCache(
         client=self.get_client(response, versions, version_response))
     self.assertIsNone(cache.get_secret_string('test'))
 def test_get_secret_string_no_current(self):
     response = {}
     versions = {'01234567890123456789012345678901': ['NOTCURRENT']}
     version_response = {'Name': 'test'}
     cache = SecretCache(
         client=self.get_client(response, versions, version_response))
     self.assertIsNone(cache.get_secret_string('test'))
 def test_get_secret_string(self):
     secret = 'mysecret'
     response = {}
     versions = {'01234567890123456789012345678901': ['AWSCURRENT']}
     version_response = {'SecretString': secret}
     cache = SecretCache(
         client=self.get_client(response, versions, version_response))
     for _ in range(10):
         self.assertEqual(secret, cache.get_secret_string('test'))
コード例 #4
0
    def test_get_secret_string(self, client, secret_string):
        cache = SecretCache(client=client)
        secret = client.get_secret_value(
            SecretId=secret_string['ARN'])['SecretString']

        for _ in range(10):
            assert cache.get_secret_string("{0}{1}{2}".format(
                TestAwsSecretsManagerCachingInteg.fixture_prefix,
                inspect.stack()[0][3],
                TestAwsSecretsManagerCachingInteg.uuid_suffix)) == secret
コード例 #5
0
    def test_get_secret_string_refresh(self, client, secret_string):
        cache = SecretCache(
            config=SecretCacheConfig(secret_refresh_interval=1), client=client)
        secret = client.get_secret_value(
            SecretId=secret_string['ARN'])['SecretString']

        for _ in range(10):
            assert cache.get_secret_string("{0}{1}{2}".format(
                TestAwsSecretsManagerCachingInteg.fixture_prefix,
                inspect.stack()[0][3],
                TestAwsSecretsManagerCachingInteg.uuid_suffix)) == secret

        client.put_secret_value(SecretId=secret_string['ARN'],
                                SecretString='test2',
                                VersionStages=['AWSCURRENT'])

        time.sleep(2)
        secret = client.get_secret_value(
            SecretId=secret_string['ARN'])['SecretString']
        for _ in range(10):
            assert cache.get_secret_string("{0}{1}{2}".format(
                TestAwsSecretsManagerCachingInteg.fixture_prefix,
                inspect.stack()[0][3],
                TestAwsSecretsManagerCachingInteg.uuid_suffix)) == secret
コード例 #6
0
    def test_calls_hook_string(self):
        secret = 'mysecret'
        hooked_secret = secret + "+hook_put+hook_get"
        response = {}
        versions = {
            '01234567890123456789012345678901': ['AWSCURRENT']
        }
        version_response = {'SecretString': secret}

        hook = DummySecretCacheHook()
        config = SecretCacheConfig(secret_cache_hook=hook)

        cache = SecretCache(config=config, client=self.get_client(response,
                                                                  versions,
                                                                  version_response))

        for _ in range(10):
            fetched_secret = cache.get_secret_string('test')
            self.assertTrue(fetched_secret.startswith(hooked_secret))
コード例 #7
0
 def test_get_secret_string_empty(self, client, secret_binary):
     cache = SecretCache(client=client)
     assert cache.get_secret_string("{0}{1}{2}".format(
         TestAwsSecretsManagerCachingInteg.fixture_prefix,
         inspect.stack()[0][3],
         TestAwsSecretsManagerCachingInteg.uuid_suffix)) is None
 def test_get_secret_string_no_versions(self):
     response = {'Name': 'test'}
     cache = SecretCache(client=self.get_client(response))
     self.assertIsNone(cache.get_secret_string('test'))
 def test_get_secret_string_none(self):
     cache = SecretCache(client=self.get_client())
     self.assertIsNone(cache.get_secret_string('test'))
 def test_get_secret_string_multiple(self):
     cache = SecretCache(client=self.get_client())
     for _ in range(100):
         self.assertIsNone(cache.get_secret_string('test'))