Ejemplo n.º 1
0
 def test_get_gcp_credentials_no_auth(self):
     """Test to get GCP project id 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": []},
         )
         m.get(
             (f"http://www.sources.com/api/v1.0/authentications?"
              f"[authtype]=project_id_service_account_json&[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_gcp_credentials()
Ejemplo n.º 2
0
 def test_get_gcp_credentials_from_app_auth(self):
     """Test to get project id from authentication service for Application authentication."""
     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]=project_id&[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_gcp_credentials()
         self.assertEqual(response, {"project_id": self.authentication})
Ejemplo n.º 3
0
 def test_get_gcp_credentials_no_password(self):
     """Test to get GCP project id from authentication service with auth not containing password."""
     resource_id = 2
     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]=project_id_service_account_json&[resource_id]={resource_id}"
             ),
             status_code=200,
             json={"data": [{"other": self.authentication}]},
         )
         with self.assertRaises(SourcesHTTPClientError):
             client.get_gcp_credentials()