Beispiel #1
0
 def testGCECredentialFailure(self, _):
   with SetBotoConfigForTest(getBotoCredentialsConfig(gce_creds="?")):
     with self.assertLogs() as logger:
       with self.assertRaises(Exception) as exc:
         gcs_json_api.GcsJsonApi(None, logging.getLogger(), None, None)
       self.assertIn(ERROR_MESSAGE, str(exc.exception))
       self.assertIn(CredTypes.GCE, logger.output[0])
Beispiel #2
0
 def testOauth2UserFailure(self, _):
   with SetBotoConfigForTest(getBotoCredentialsConfig(user_account_creds="?")):
     with self.assertLogs() as logger:
       with self.assertRaises(Exception) as exc:
         gcs_json_api.GcsJsonApi(None, logging.getLogger(), None, None)
       self.assertIn(ERROR_MESSAGE, str(exc.exception))
       self.assertIn(CredTypes.OAUTH2_USER_ACCOUNT, logger.output[0])
Beispiel #3
0
 def testExternalAccountCredential(self):
   contents = pkgutil.get_data(
       "gslib", "tests/test_data/test_external_account_credentials.json")
   tmpfile = self.CreateTempFile(contents=contents)
   with SetBotoConfigForTest(
       getBotoCredentialsConfig(external_account_creds=tmpfile)):
     client = gcs_json_api.GcsJsonApi(None, None, None, None)
     self.assertIsInstance(client.credentials, WrappedCredentials)
Beispiel #4
0
    def testRaisesErrorIfConflictingJsonAndMtlsHost(self,
                                                    mock_get_context_config):
        mock_context_config = mock.Mock()
        mock_context_config.use_client_certificate = True
        mock_get_context_config.return_value = mock_context_config

        with SetBotoConfigForTest([('Credentials', 'gs_json_host', 'host')]):
            with self.assertRaises(cloud_api.ArgumentException):
                gcs_json_api.GcsJsonApi(None, None, None, None)
Beispiel #5
0
 def testOauth2ServiceAccountAndOauth2UserCredential(self):
   with SetBotoConfigForTest(
       getBotoCredentialsConfig(user_account_creds="?",
                                service_account_creds={
                                    "keyfile": "?",
                                    "client_id": "?",
                                })):
     with self.assertRaises(CommandException):
       gcs_json_api.GcsJsonApi(None, None, None, None)
Beispiel #6
0
    def testSetsHostBaseToMtlsIfClientCertificateEnabled(
            self, mock_get_context_config):
        mock_context_config = mock.Mock()
        mock_context_config.use_client_certificate = True
        mock_get_context_config.return_value = mock_context_config

        with SetBotoConfigForTest([('Credentials', 'gs_json_host', None),
                                   ('Credentials', 'gs_host', None)]):
            client = gcs_json_api.GcsJsonApi(None, None, None, None)
            self.assertEqual(client.host_base, gcs_json_api.MTLS_HOST)
Beispiel #7
0
 def testOauth2ServiceAccountCredential(self):
   contents = pkgutil.get_data("gslib", "tests/test_data/test.p12")
   tmpfile = self.CreateTempFile(contents=contents)
   with SetBotoConfigForTest(
       getBotoCredentialsConfig(service_account_creds={
           "keyfile": tmpfile,
           "client_id": "?",
       })):
     self.assertTrue(gcs_json_credentials._HasOauth2ServiceAccountCreds())
     client = gcs_json_api.GcsJsonApi(None, None, None, None)
     self.assertIsInstance(client.credentials, ServiceAccountCredentials)
Beispiel #8
0
 def testExternalAccountFailure(self, _):
   contents = pkgutil.get_data(
       "gslib", "tests/test_data/test_external_account_credentials.json")
   tmpfile = self.CreateTempFile(contents=contents)
   with SetBotoConfigForTest(
       getBotoCredentialsConfig(external_account_creds=tmpfile)):
     with self.assertLogs() as logger:
       with self.assertRaises(Exception) as exc:
         gcs_json_api.GcsJsonApi(None, logging.getLogger(), None, None)
       self.assertIn(ERROR_MESSAGE, str(exc.exception))
       self.assertIn(CredTypes.EXTERNAL_ACCOUNT, logger.output[0])
Beispiel #9
0
 def testOauth2ServiceAccountFailure(self, _):
   contents = pkgutil.get_data("gslib", "tests/test_data/test.p12")
   tmpfile = self.CreateTempFile(contents=contents)
   with SetBotoConfigForTest(
       getBotoCredentialsConfig(service_account_creds={
           "keyfile": tmpfile,
           "client_id": "?",
       })):
     with self.assertLogs() as logger:
       with self.assertRaises(Exception) as exc:
         gcs_json_api.GcsJsonApi(None, logging.getLogger(), None, None)
       self.assertIn(ERROR_MESSAGE, str(exc.exception))
       self.assertIn(CredTypes.OAUTH2_SERVICE_ACCOUNT, logger.output[0])
Beispiel #10
0
  def testGCECredential(self, mock_credentials):

    def set_store(store):
      mock_credentials.return_value.store = store

    mock_credentials.return_value.client_id = None
    mock_credentials.return_value.refresh_token = "rEfrEshtOkEn"
    mock_credentials.return_value.set_store = set_store
    with SetBotoConfigForTest(getBotoCredentialsConfig(gce_creds="?")):
      self.assertTrue(gcs_json_credentials._HasGceCreds())
      client = gcs_json_api.GcsJsonApi(None, None, None, None)
      self.assertIsInstance(client.credentials, GceAssertionCredentials)
      self.assertEquals(client.credentials.refresh_token, "rEfrEshtOkEn")
      self.assertIs(client.credentials.client_id, None)
Beispiel #11
0
 def testSetsDefaultHost(self):
     with SetBotoConfigForTest([('Credentials', 'gs_json_host', None),
                                ('Credentials', 'gs_host', None)]):
         client = gcs_json_api.GcsJsonApi(None, None, None, None)
         self.assertEqual(client.host_base, gcs_json_api.DEFAULT_HOST)
Beispiel #12
0
 def testSetsCustomJsonHost(self):
     with SetBotoConfigForTest([('Credentials', 'gs_json_host', 'host')]):
         client = gcs_json_api.GcsJsonApi(None, None, None, None)
         self.assertEqual(client.host_base, 'host')
Beispiel #13
0
 def testOauth2UserCredential(self):
   with SetBotoConfigForTest(getBotoCredentialsConfig(user_account_creds="?")):
     self.assertTrue(gcs_json_credentials._HasOauth2UserAccountCreds())
     client = gcs_json_api.GcsJsonApi(None, None, None, None)
     self.assertIsInstance(client.credentials,
                           reauth_creds.Oauth2WithReauthCredentials)