def test_exception_propogated_on_error_during_mandatory_period(self): fail_refresh = mock.Mock(side_effect=Exception("refresh failed")) creds = IntegerRefresher( creds_last_for=5, advisory_refresh=10, # Note we're in the mandatory period now (5 < 7< 10). mandatory_refresh=7, refresh_function=fail_refresh) with self.assertRaisesRegexp(Exception, 'refresh failed'): creds.get_frozen_credentials()
def test_exception_propogated_on_error_during_mandatory_period(self): fail_refresh = mock.Mock(side_effect=Exception("refresh failed")) creds = IntegerRefresher( creds_last_for=5, advisory_refresh=10, # Note we're in the mandatory period now (5 < 7< 10). mandatory_refresh=7, refresh_function=fail_refresh ) with self.assertRaisesRegexp(Exception, 'refresh failed'): creds.get_frozen_credentials()
def test_exception_propogated_on_expired_credentials(self): fail_refresh = mock.Mock(side_effect=Exception("refresh failed")) creds = IntegerRefresher( # Setting this to 0 mean the credentials are immediately # expired. creds_last_for=0, advisory_refresh=10, mandatory_refresh=7, refresh_function=fail_refresh) with self.assertRaisesRegexp(Exception, 'refresh failed'): # Because credentials are actually expired, any # failure to refresh should be propagated. creds.get_frozen_credentials()
def test_exception_propogated_on_expired_credentials(self): fail_refresh = mock.Mock(side_effect=Exception("refresh failed")) creds = IntegerRefresher( # Setting this to 0 mean the credentials are immediately # expired. creds_last_for=0, advisory_refresh=10, mandatory_refresh=7, refresh_function=fail_refresh ) with self.assertRaisesRegexp(Exception, 'refresh failed'): # Because credentials are actually expired, any # failure to refresh should be propagated. creds.get_frozen_credentials()
def test_advisory_refresh_needed(self): creds = IntegerRefresher( # These values will immediately trigger # a manadatory refresh. creds_last_for=4, mandatory_refresh=2, advisory_refresh=5) temp = creds.get_frozen_credentials() self.assertEqual(temp, credentials.ReadOnlyCredentials('1', '1', '1'))
def test_advisory_refresh_needed(self): creds = IntegerRefresher( # These values will immediately trigger # a manadatory refresh. creds_last_for=4, mandatory_refresh=2, advisory_refresh=5) temp = creds.get_frozen_credentials() self.assertEqual( temp, credentials.ReadOnlyCredentials('1', '1', '1'))
def test_refresh_giving_expired_credentials_raises_exception(self): # This verifies an edge cases where refreshed credentials # still give expired credentials: # 1. We see credentials are expired. # 2. We try to refresh the credentials. # 3. The "refreshed" credentials are still expired. # # In this case, we hard fail and let the user know what # happened. creds = IntegerRefresher( # Negative number indicates that the credentials # have already been expired for 2 seconds, even # on refresh. creds_last_for=-2, ) err_msg = 'refreshed credentials are still expired' with self.assertRaisesRegexp(RuntimeError, err_msg): # Because credentials are actually expired, any # failure to refresh should be propagated. creds.get_frozen_credentials()
def test_refresh_giving_expired_credentials_raises_exception(self): # This verifies an edge cases where refreshed credentials # still give expired credentials: # 1. We see credentials are expired. # 2. We try to refresh the credentials. # 3. The "refreshed" credentials are still expired. # # In this case, we hard fail and let the user know what # happened. creds = IntegerRefresher( # Negative number indicates that the credentials # have already been expired for 2 seconds, even # on refresh. creds_last_for=-2, ) err_msg = 'refreshed credentials are still expired' with self.assertRaisesRegexp(RuntimeError, err_msg): # Because credentials are actually expired, any # failure to refresh should be propagated. creds.get_frozen_credentials()
def test_refresh_fails_is_not_an_error_during_advisory_period(self): fail_refresh = mock.Mock(side_effect=Exception("refresh failed")) creds = IntegerRefresher(creds_last_for=5, advisory_refresh=7, mandatory_refresh=3, refresh_function=fail_refresh) temp = creds.get_frozen_credentials() # We should have called the refresh function. self.assertTrue(fail_refresh.called) # The fail_refresh function will raise an exception. # Because we're in the advisory period we'll not propogate # the exception and return the current set of credentials # (generation '1'). self.assertEqual(temp, credentials.ReadOnlyCredentials('0', '0', '0'))
def test_refresh_fails_is_not_an_error_during_advisory_period(self): fail_refresh = mock.Mock(side_effect=Exception("refresh failed")) creds = IntegerRefresher( creds_last_for=5, advisory_refresh=7, mandatory_refresh=3, refresh_function=fail_refresh ) temp = creds.get_frozen_credentials() # We should have called the refresh function. self.assertTrue(fail_refresh.called) # The fail_refresh function will raise an exception. # Because we're in the advisory period we'll not propogate # the exception and return the current set of credentials # (generation '1'). self.assertEqual( temp, credentials.ReadOnlyCredentials('0', '0', '0'))