Example #1
0
 def test_get_gcp_credentials_errors(self):
     """Test to get project id exceptions."""
     client = SourcesHTTPClient(auth_header=Config.SOURCES_FAKE_HEADER, source_id=self.source_id)
     with requests_mock.mock() as m:
         json_data = [None, [], [{"no-username": "******"}]]
         for test in json_data:
             with self.subTest(test=test):
                 m.get(
                     f"{MOCK_URL}/api/v1.0/{ENDPOINT_AUTHENTICATIONS}?source_id={self.source_id}",
                     status_code=200,
                     json={"data": test},
                 )
                 with self.assertRaises(SourcesHTTPClientError):
                     client._get_gcp_credentials()
Example #2
0
 def test_get_gcp_credentials_errors(self):
     """Test to get project id exceptions."""
     auth_type = AUTH_TYPES.get(Provider.PROVIDER_GCP)
     client = SourcesHTTPClient(auth_header=Config.SOURCES_FAKE_HEADER,
                                source_id=self.source_id)
     with requests_mock.mock() as m:
         json_data = [None, [], [{"no-username": "******"}]]
         for test in json_data:
             with self.subTest(test=test):
                 m.get(
                     f"{MOCK_URL}/api/v1.0/{ENDPOINT_AUTHENTICATIONS}?"
                     f"filter[source_id]={self.source_id}&filter[authtype]={auth_type}",
                     status_code=200,
                     json={"data": test},
                 )
                 with self.assertRaises(SourcesHTTPClientError):
                     client._get_gcp_credentials(COST_MGMT_APP_TYPE_ID)
Example #3
0
 def test_get_gcp_credentials_username(self):
     """Test to get project id from authentication service from username."""
     client = SourcesHTTPClient(auth_header=Config.SOURCES_FAKE_HEADER, source_id=self.source_id)
     with requests_mock.mock() as m:
         resource_id = 2
         m.get(
             f"{MOCK_URL}/api/v1.0/{ENDPOINT_AUTHENTICATIONS}?source_id={self.source_id}",
             status_code=200,
             json={"data": [{"id": resource_id, "username": self.authentication}]},
         )
         creds = client._get_gcp_credentials()
         self.assertEqual(creds.get("project_id"), self.authentication)
Example #4
0
 def test_get_gcp_credentials_username(self):
     """Test to get project id from authentication service from username."""
     auth_type = AUTH_TYPES.get(Provider.PROVIDER_GCP)
     client = SourcesHTTPClient(auth_header=Config.SOURCES_FAKE_HEADER,
                                source_id=self.source_id)
     with requests_mock.mock() as m:
         resource_id = 2
         m.get(
             f"{MOCK_URL}/api/v1.0/{ENDPOINT_AUTHENTICATIONS}?filter[source_id]={self.source_id}&filter[authtype]={auth_type}",  # noqa: E501
             status_code=200,
             json={
                 "data": [{
                     "id": resource_id,
                     "username": self.authentication
                 }]
             },
         )
         creds = client._get_gcp_credentials(COST_MGMT_APP_TYPE_ID)
         self.assertEqual(creds.get("project_id"), self.authentication)