def test_insert_after(self): # Sanity check. self.assertEqual(self.small_resolver.available_methods, [ 'boto', 'config', ]) self.small_resolver.insert_after('boto', credentials.EnvProvider()) self.assertEqual(self.small_resolver.available_methods, [ 'boto', 'env', 'config', ]) self.small_resolver.insert_after('config', credentials.OriginalEC2Provider()) self.assertEqual(self.small_resolver.available_methods, [ 'boto', 'env', 'config', 'credentials-file', ]) # Test a failed insert. with self.assertRaises(botocore.exceptions.UnknownCredentialError): self.small_resolver.insert_after( 'foobar', credentials.InstanceMetadataProvider())
def test_load_ec2_credentials_file_exists(self): environ = { 'AWS_CREDENTIAL_FILE': 'foo.cfg', } parser = mock.Mock() parser.return_value = { 'AWSAccessKeyId': 'a', 'AWSSecretKey': 'b', } provider = credentials.OriginalEC2Provider(environ=environ, parser=parser) creds = provider.load() self.assertIsNotNone(creds) self.assertEqual(creds.access_key, 'a') self.assertEqual(creds.secret_key, 'b') self.assertIsNone(creds.token) self.assertEqual(creds.method, 'ec2-credentials-file')
def test_load_ec2_credentials_file_not_exist(self): provider = credentials.OriginalEC2Provider(environ={}) creds = provider.load() self.assertIsNone(creds)