コード例 #1
0
 def SetUp(self):
     signer = self.StartPatch('oauth2client.crypt.Signer', autospec=True)
     self.StartObjectPatch(crypt, 'OpenSSLSigner', new=signer)
     self.StartObjectPatch(google_auth_crypt.RSASigner,
                           'from_service_account_info')
     access_token_file = os.path.join(self.temp_path, 'access_token.db')
     self.access_token_cache = c_creds.AccessTokenCache(access_token_file)
     self.fake_account = 'fake-account'
コード例 #2
0
 def testAccessTokenCacheReadonlyRemove(self):
   access_token_cache = creds.AccessTokenCache(
       config.Paths().access_token_db_path)
   credentials = creds.FromJson(self.SERVICE_ACCOUNT_CREDENTIALS_JSON)
   self.StartObjectPatch(
       access_token_cache,
       '_Execute',
       side_effect=sqlite3.OperationalError(
           'attempt to write to read-only database'))
   access_token_cache.Remove(credentials.service_account_email)
   self.AssertLogContains('Could not delete access token from cache: '
                          'attempt to write to read-only database')
コード例 #3
0
 def testAttachAccessTokenCacheStore(self):
   access_token_cache = creds.AccessTokenCache(
       config.Paths().access_token_db_path)
   credentials = creds.FromJson(self.SERVICE_ACCOUNT_CREDENTIALS_JSON)
   credentials.token_response = json.loads("""{"id_token": "woweee"}""")
   self.assertIsNone(credentials.access_token)
   access_token_cache.Store(
       credentials.service_account_email,
       access_token='token1',
       token_expiry=datetime.datetime.utcnow() +
       datetime.timedelta(seconds=3600),
       rapt_token=None,
       id_token=None)
   self.assertIsNone(credentials.access_token)
   new_cred = creds.MaybeAttachAccessTokenCacheStore(credentials)
   self.assertIsNone(new_cred.token_response)
   self.assertEqual('token1', new_cred.access_token)
コード例 #4
0
 def testAccessTokenCacheReadonlyStore(self):
   access_token_cache = creds.AccessTokenCache(
       config.Paths().access_token_db_path)
   credentials = creds.FromJson(self.SERVICE_ACCOUNT_CREDENTIALS_JSON)
   credentials.token_response = json.loads("""{"id_token": "woweee"}""")
   self.assertIsNone(credentials.access_token)
   self.StartObjectPatch(
       access_token_cache,
       '_Execute',
       side_effect=sqlite3.OperationalError(
           'attempt to write to read-only database'))
   access_token_cache.Store(
       credentials.service_account_email,
       access_token='token1',
       token_expiry=datetime.datetime.utcnow() +
       datetime.timedelta(seconds=3600),
       rapt_token=None,
       id_token=None)
   self.AssertLogContains('Could not store access token in cache: '
                          'attempt to write to read-only database')
コード例 #5
0
  def testAttachAccessTokenCacheStoreGoogleAuth(self):
    # Create credentials.
    credentials = google_auth_service_account.Credentials(
        None, 'email', 'token_uri')
    self.assertIsNone(credentials.token)

    # Create access token cache.
    access_token_cache = creds.AccessTokenCache(
        config.Paths().access_token_db_path)
    access_token_cache.Store(
        credentials.service_account_email,
        access_token='token1',
        token_expiry=datetime.datetime.utcnow() +
        datetime.timedelta(seconds=3600),
        rapt_token=None,
        id_token=None)

    # Attach access token cache store to credentials.
    new_creds = creds.MaybeAttachAccessTokenCacheStoreGoogleAuth(credentials)
    self.assertEqual(new_creds.token, 'token1')
コード例 #6
0
 def SetUp(self):
     access_token_file = os.path.join(self.temp_path, 'access_token.db')
     self.access_token_cache = c_creds.AccessTokenCache(access_token_file)
     self.fake_account = 'fake-account'