Example #1
0
def test_ttl_action_not_in_cache():
    """Test that when a version is not in the cache, ttl_action returns TtlActions.EXPIRED."""
    store = MagicMock(__class__=ProviderStore)
    provider = CachingMostRecentProvider(provider_store=store,
                                         material_name="my material",
                                         version_ttl=10.0)

    assert provider._last_updated is None

    ttl_action = provider._ttl_action(0, "decrypt")
    assert ttl_action is TtlActions.EXPIRED
Example #2
0
def test_ttl_action_first_encrypt():
    """Test that when _last_updated has never been set, ttl_action returns TtlActions.EXPIRED."""
    store = MagicMock(__class__=ProviderStore)
    provider = CachingMostRecentProvider(provider_store=store,
                                         material_name="my material",
                                         version_ttl=10.0)

    assert provider._last_updated is None

    ttl_action = provider._ttl_action(0, "encrypt")
    assert ttl_action is TtlActions.EXPIRED
Example #3
0
def test_ttl_action_live():
    """Test that when a version is within the ttl, ttl_action returns TtlActions.LIVE."""
    version = 0
    store = MagicMock(__class__=ProviderStore)
    provider = CachingMostRecentProvider(provider_store=store,
                                         material_name="my material",
                                         version_ttl=10.0)
    provider._cache.put(version, (time.time(), "value"))

    assert provider._last_updated is None

    ttl_action = provider._ttl_action(version, "decrypt")
    assert ttl_action is TtlActions.LIVE
Example #4
0
def test_ttl_action_first_encrypt_previous_decrypt():
    """Test that on the first call to encrypt, ttl_action returns TtlActions.EXPIRED."""
    version = 0
    store = MagicMock(__class__=ProviderStore)
    provider = CachingMostRecentProvider(provider_store=store,
                                         material_name="my material",
                                         version_ttl=10.0)
    provider._cache.put(version, "bar")

    assert provider._last_updated is None

    ttl_action = provider._ttl_action(version, "encrypt")
    assert ttl_action is TtlActions.EXPIRED
Example #5
0
def test_ttl_action_expired():
    """Test that when a version is expired and not in the grace period, ttl_action returns TtlActions.EXPIRED."""
    version = 0
    store = MagicMock(__class__=ProviderStore)
    provider = CachingMostRecentProvider(provider_store=store,
                                         material_name="my material",
                                         version_ttl=0.0)
    provider._grace_period = 0.0
    provider._cache.put(version, (time.time(), "value"))

    assert provider._last_updated is None

    ttl_action = provider._ttl_action(version, "decrypt")
    assert ttl_action is TtlActions.EXPIRED