def test_can_remove_providers(self): self.provider1.load.return_value = credentials.Credentials( 'a', 'b', 'test') self.provider2.load.return_value = credentials.Credentials( 'd', 'e', 'test') resolver = credentials.CredentialResolver(providers=[self.provider1, self.provider2]) resolver.remove('provider1') creds = resolver.load_credentials() self.assertIsNotNone(creds) self.assertEqual(creds.access_key_id, 'd') self.assertEqual(creds.private_key, 'e') self.assertTrue(not self.provider1.load.called) self.provider2.load.assert_called_with()
def test_inject_additional_providers_after_existing(self): self.provider1.load.return_value = None self.provider2.load.return_value = self.fake_creds resolver = credentials.CredentialResolver(providers=[self.provider1, self.provider2]) # Now, if we were to call resolver.load() now, provider2 would # win because it's returning a non None response. # However we can inject a new provider before provider2 to # override this process. # Providers can be added by the METHOD name of each provider. new_provider = mock.Mock() new_provider.METHOD = 'new_provider' new_provider.load.return_value = credentials.Credentials('d', 'e', 'test') resolver.insert_after('provider1', new_provider) creds = resolver.load_credentials() self.assertIsNotNone(creds) self.assertEqual(creds.access_key_id, 'd') self.assertEqual(creds.private_key, 'e') # Provider 1 should have been called, but provider2 should # *not* have been called because new_provider already returned # a non-None response. self.provider1.load.assert_called_with() self.assertTrue(not self.provider2.called)
def setUp(self): super(CredentialResolverTest, self).setUp() self.provider1 = mock.Mock() self.provider1.METHOD = 'provider1' self.provider2 = mock.Mock() self.provider2.METHOD = 'provider2' self.fake_creds = credentials.Credentials('a', 'b', 'test')
def test_frozen_credentials(self): cred = credentials.Credentials("key", "secret", "test") frozen_creds = cred.get_frozen_credentials() self.assertEqual("key", frozen_creds.access_key_id) self.assertEqual("secret", frozen_creds.private_key) cred.access_key_id = "foobar" cred.private_key = "foo" self.assertEqual("key", frozen_creds.access_key_id) self.assertEqual("secret", frozen_creds.private_key)
def _ensure_credential_is_normalized_as_unicode(self, access, secret, token): c = credentials.Credentials(access_key_id=access, private_key=secret, access_token=token, method='test') self.assertTrue(isinstance(c.access_key_id, type(u'u'))) self.assertTrue(isinstance(c.private_key, type(u'u'))) self.assertTrue(isinstance(c.access_token, type(u'u')))
def setUp(self): super(CredentialResolverTest, self).setUp() self.provider1 = mock.Mock() self.provider1.METHOD = 'provider1' self.provider2 = mock.Mock() self.provider2.METHOD = 'provider2' self.fake_creds = credentials.Credentials(access_key_id='a', private_key='b', method='test')
def test_inject_provider_before_existing(self): new_provider = mock.Mock() new_provider.METHOD = 'override' new_provider.load.return_value = credentials.Credentials('x', 'y', 'test') resolver = credentials.CredentialResolver(providers=[self.provider1, self.provider2]) resolver.insert_before(self.provider1.METHOD, new_provider) creds = resolver.load_credentials() self.assertEqual(creds.access_key_id, 'x') self.assertEqual(creds.private_key, 'y')
def test_frozen_credentials(self): cred = credentials.Credentials(access_key_id="key", private_key="secret", access_token='token', method="test") frozen_creds = cred.get_frozen_credentials() self.assertEqual("key", frozen_creds.access_key_id) self.assertEqual("secret", frozen_creds.private_key) self.assertEqual("token", frozen_creds.access_token) cred.access_key_id = "foobar" cred.private_key = "foo" cred.access_token = "bar" self.assertEqual("key", frozen_creds.access_key_id) self.assertEqual("secret", frozen_creds.private_key) self.assertEqual("token", frozen_creds.access_token)
def _ensure_credential_is_normalized_as_unicode(self, access, secret): c = credentials.Credentials(access, secret, 'test') self.assertTrue(isinstance(c.access_key_id, type(u'u'))) self.assertTrue(isinstance(c.private_key, type(u'u')))