def test_get_aws_credentials_no_auth(self): """Test to get AWS Role ARN from authentication service with auth not ready.""" resource_id = 2 authentication_id = 3 client = SourcesHTTPClient(auth_header=Config.SOURCES_FAKE_HEADER, source_id=self.source_id) with requests_mock.mock() as m: m.get( f"http://www.sources.com/api/v1.0/applications?filter[source_id]={self.source_id}", status_code=200, json={"data": [{ "id": resource_id }]}, ) m.get( (f"http://www.sources.com/api/v1.0/authentications?" f"[authtype]=arn&[resource_id]={resource_id}"), status_code=200, json={"data": []}, ) m.get( (f"http://www.sources.com/internal/v1.0/authentications/{authentication_id}" f"?expose_encrypted_attribute[]=password"), status_code=200, json={"password": self.authentication}, ) with self.assertRaises(SourcesHTTPClientError): client.get_aws_credentials()
def test_get_aws_credentials_connection_error(self): """Test to get AWS Role ARN from authentication service with connection errors.""" client = SourcesHTTPClient(auth_header=Config.SOURCES_FAKE_HEADER, source_id=self.source_id) with requests_mock.mock() as m: m.get( f"http://www.sources.com/api/v1.0/applications?filter[source_id]={self.source_id}", exc=RequestException, ) with self.assertRaises(SourcesHTTPClientError): client.get_aws_credentials()
def test_get_aws_credentials_no_endpoint(self): """Test to get AWS Role ARN from authentication service with no endpoint.""" client = SourcesHTTPClient(auth_header=Config.SOURCES_FAKE_HEADER, source_id=self.source_id) with requests_mock.mock() as m: m.get( f"http://www.sources.com/api/v1.0/applications?filter[source_id]={self.source_id}", status_code=200, json={"data": []}, ) with self.assertRaises(SourcesHTTPClientError): client.get_aws_credentials()
def test_get_aws_credentials_username(self): """Test to get AWS Role ARN from authentication service from username.""" resource_id = 2 authentication_id = 3 client = SourcesHTTPClient(auth_header=Config.SOURCES_FAKE_HEADER, source_id=self.source_id) with requests_mock.mock() as m: m.get( f"http://www.sources.com/api/v1.0/applications?filter[source_id]={self.source_id}", status_code=200, json={"data": [{ "id": resource_id }]}, ) m.get( (f"http://www.sources.com/api/v1.0/authentications?" f"[authtype]=arn&[resource_id]={resource_id}"), status_code=200, json={ "data": [{ "id": authentication_id, "username": self.authentication }] }, ) response = client.get_aws_credentials() self.assertEqual(response, {"role_arn": self.authentication})
def test_get_aws_credentials(self): """Test to get AWS Role ARN from authentication service.""" resource_id = 2 authentication_id = 3 client = SourcesHTTPClient(auth_header=Config.SOURCES_FAKE_HEADER, source_id=self.source_id) with requests_mock.mock() as m: m.get( f"http://www.sources.com/api/v1.0/endpoints?filter[source_id]={self.source_id}", status_code=200, json={"data": [{ "id": resource_id }]}, ) m.get( (f"http://www.sources.com/api/v1.0/authentications?filter[resource_type]=Endpoint" f"&[authtype]=arn&[resource_id]={resource_id}"), status_code=200, json={"data": [{ "id": authentication_id }]}, ) m.get( (f"http://www.sources.com/internal/v1.0/authentications/{authentication_id}" f"?expose_encrypted_attribute[]=password"), status_code=200, json={"password": self.authentication}, ) response = client.get_aws_credentials() self.assertEqual(response, {"role_arn": self.authentication})