1212# language governing permissions and limitations under the License.
1313"""Functional tests for ``dynamodb_encryption_sdk.material_providers.most_recent``."""
1414import time
15- import warnings
1615from collections import defaultdict
1716
1817import pytest
1918from mock import MagicMock , sentinel
2019
2120from dynamodb_encryption_sdk .exceptions import NoKnownVersionError
2221from dynamodb_encryption_sdk .material_providers import CryptographicMaterialsProvider
23- from dynamodb_encryption_sdk .material_providers .most_recent import (
24- CachingMostRecentProvider ,
25- MostRecentProvider ,
26- TtlActions ,
27- )
22+ from dynamodb_encryption_sdk .material_providers .most_recent import CachingMostRecentProvider , TtlActions
2823from dynamodb_encryption_sdk .material_providers .store import ProviderStore
2924
3025from ..functional_test_utils import example_table # noqa=F401 pylint: disable=unused-import
@@ -76,12 +71,11 @@ def version_from_material_description(self, material_description):
7671 return material_description
7772
7873
79- @pytest .mark .parametrize ("provider_class" , (MostRecentProvider , CachingMostRecentProvider ))
80- def test_constructor (provider_class ):
74+ def test_constructor ():
8175 """Tests that when the cache is expired on encrypt, we evict the entry from the cache."""
8276 store = MockProviderStore ()
8377 name = "material"
84- provider = provider_class (provider_store = store , material_name = name , version_ttl = 1.0 , cache_size = 42 )
78+ provider = CachingMostRecentProvider (provider_store = store , material_name = name , version_ttl = 1.0 , cache_size = 42 )
8579
8680 assert provider ._provider_store == store
8781 assert provider ._material_name == name
@@ -277,10 +271,9 @@ def test_get_most_recent_version_grace_period_lock_not_acquired():
277271 assert store .provider_calls == expected_calls
278272
279273
280- @pytest .mark .parametrize ("provider_class" , (MostRecentProvider , CachingMostRecentProvider ))
281- def test_failed_lock_acquisition (provider_class ):
274+ def test_failed_lock_acquisition ():
282275 store = MagicMock (__class__ = ProviderStore )
283- provider = provider_class (provider_store = store , material_name = "my material" , version_ttl = 10.0 )
276+ provider = CachingMostRecentProvider (provider_store = store , material_name = "my material" , version_ttl = 10.0 )
284277 provider ._version = 9
285278 provider ._cache .put (provider ._version , (time .time (), sentinel .nine ))
286279
@@ -291,11 +284,10 @@ def test_failed_lock_acquisition(provider_class):
291284 assert not store .mock_calls
292285
293286
294- @pytest .mark .parametrize ("provider_class" , (MostRecentProvider , CachingMostRecentProvider ))
295- def test_encryption_materials_cache_use (provider_class ):
287+ def test_encryption_materials_cache_use ():
296288 store = MockProviderStore ()
297289 name = "material"
298- provider = provider_class (provider_store = store , material_name = name , version_ttl = 10.0 )
290+ provider = CachingMostRecentProvider (provider_store = store , material_name = name , version_ttl = 10.0 )
299291
300292 test1 = provider .encryption_materials (sentinel .encryption_context_1 )
301293 assert test1 is sentinel .material_0_encryption
@@ -320,11 +312,10 @@ def test_encryption_materials_cache_use(provider_class):
320312 assert store .provider_calls == expected_calls
321313
322314
323- @pytest .mark .parametrize ("provider_class" , (MostRecentProvider , CachingMostRecentProvider ))
324- def test_encryption_materials_cache_expired (provider_class ):
315+ def test_encryption_materials_cache_expired ():
325316 store = MockProviderStore ()
326317 name = "material"
327- provider = provider_class (provider_store = store , material_name = name , version_ttl = 0.0 )
318+ provider = CachingMostRecentProvider (provider_store = store , material_name = name , version_ttl = 0.0 )
328319
329320 test1 = provider .encryption_materials (sentinel .encryption_context_1 )
330321 assert test1 is sentinel .material_0_encryption
@@ -354,12 +345,11 @@ def test_encryption_materials_cache_expired(provider_class):
354345 assert store .provider_calls == expected_calls
355346
356347
357- @pytest .mark .parametrize ("provider_class" , (MostRecentProvider , CachingMostRecentProvider ))
358- def test_encryption_materials_cache_expired_cache_removed (provider_class ):
348+ def test_encryption_materials_cache_expired_cache_removed ():
359349 """Tests that when the cache is expired on encrypt, we evict the entry from the cache."""
360350 store = MockProviderStore ()
361351 name = "material"
362- provider = provider_class (provider_store = store , material_name = name , version_ttl = 0.0 )
352+ provider = CachingMostRecentProvider (provider_store = store , material_name = name , version_ttl = 0.0 )
363353 provider ._cache = MagicMock ()
364354 provider ._cache .get .return_value = (0.0 , MagicMock ())
365355
@@ -379,16 +369,15 @@ def test_decryption_materials_cache_expired_cache_removed():
379369 provider ._cache .evict .assert_called_once ()
380370
381371
382- @pytest .mark .parametrize ("provider_class" , (MostRecentProvider , CachingMostRecentProvider ))
383- def test_encryption_materials_cache_in_grace_period_acquire_lock (provider_class ):
372+ def test_encryption_materials_cache_in_grace_period_acquire_lock ():
384373 """Test encryption grace period behavior.
385374
386375 When the TTL is GRACE_PERIOD and we successfully acquire the lock for retrieving new materials,
387376 we call to the provider store for new materials.
388377 """
389378 store = MockProviderStore ()
390379 name = "material"
391- provider = provider_class (provider_store = store , material_name = name , version_ttl = 0.0 )
380+ provider = CachingMostRecentProvider (provider_store = store , material_name = name , version_ttl = 0.0 )
392381 provider ._grace_period = 10.0
393382
394383 test1 = provider .encryption_materials (sentinel .encryption_context_1 )
@@ -422,16 +411,15 @@ def test_encryption_materials_cache_in_grace_period_acquire_lock(provider_class)
422411 assert store .provider_calls == expected_calls
423412
424413
425- @pytest .mark .parametrize ("provider_class" , (MostRecentProvider , CachingMostRecentProvider ))
426- def test_encryption_materials_cache_in_grace_period_fail_to_acquire_lock (provider_class ):
414+ def test_encryption_materials_cache_in_grace_period_fail_to_acquire_lock ():
427415 """Test encryption grace period behavior.
428416
429417 When the TTL is GRACE_PERIOD and we fail to acquire the lock for retrieving new materials,
430418 we use the materials from the cache.
431419 """
432420 store = MockProviderStore ()
433421 name = "material"
434- provider = provider_class (provider_store = store , material_name = name , version_ttl = 0.0 )
422+ provider = CachingMostRecentProvider (provider_store = store , material_name = name , version_ttl = 0.0 )
435423 provider ._grace_period = 10.0
436424
437425 test1 = provider .encryption_materials (sentinel .encryption_context_1 )
@@ -463,43 +451,10 @@ def test_encryption_materials_cache_in_grace_period_fail_to_acquire_lock(provide
463451 assert store .provider_calls == expected_calls
464452
465453
466- @pytest .mark .parametrize ("provider_class" , (CachingMostRecentProvider , CachingMostRecentProvider ))
467- def test_decryption_materials_cache_use (provider_class ):
468- store = MockProviderStore ()
469- name = "material"
470- provider = provider_class (provider_store = store , material_name = name , version_ttl = 10.0 )
471-
472- context = MagicMock (material_description = 0 )
473-
474- test1 = provider .decryption_materials (context )
475- assert test1 is sentinel .material_0_decryption
476-
477- assert len (provider ._cache ._cache ) == 1
478-
479- expected_calls = [("version_from_material_description" , 0 ), ("get_or_create_provider" , name , 0 )]
480-
481- assert store .provider_calls == expected_calls
482-
483- test2 = provider .decryption_materials (context )
484- assert test2 is sentinel .material_0_decryption
485-
486- assert len (provider ._cache ._cache ) == 1
487-
488- expected_calls .append (("version_from_material_description" , 0 ))
489-
490- assert store .provider_calls == expected_calls
491-
492-
493- def test_most_recent_provider_decryption_materials_cache_expired ():
494- """Test decryption expiration behavior for MostRecentProvider.
495-
496- When using a MostRecentProvider and the cache is expired on decryption, we do not retrieve new
497- materials from the provider store. Note that this test only runs for MostRecentProvider, to ensure that our legacy
498- behavior has not changed.
499- """
454+ def test_decryption_materials_cache_use ():
500455 store = MockProviderStore ()
501456 name = "material"
502- provider = MostRecentProvider (provider_store = store , material_name = name , version_ttl = 0 .0 )
457+ provider = CachingMostRecentProvider (provider_store = store , material_name = name , version_ttl = 10 .0 )
503458
504459 context = MagicMock (material_description = 0 )
505460
@@ -517,7 +472,6 @@ def test_most_recent_provider_decryption_materials_cache_expired():
517472
518473 assert len (provider ._cache ._cache ) == 1
519474
520- # The MostRecentProvider does not use TTLs on decryption, so we should not see a new call to the provider store
521475 expected_calls .append (("version_from_material_description" , 0 ))
522476
523477 assert store .provider_calls == expected_calls
@@ -629,13 +583,3 @@ def test_caching_provider_decryption_materials_cache_in_grace_period_fail_to_acq
629583
630584def test_cache_use_encrypt (mock_metastore , example_table , caplog ):
631585 check_metastore_cache_use_encrypt (mock_metastore , TEST_TABLE_NAME , caplog )
632-
633-
634- def test_most_recent_provider_deprecated ():
635- warnings .simplefilter ("error" )
636-
637- with pytest .raises (DeprecationWarning ) as excinfo :
638- store = MockProviderStore ()
639- name = "material"
640- MostRecentProvider (provider_store = store , material_name = name , version_ttl = 0.0 )
641- excinfo .match ("MostRecentProvider is deprecated, use CachingMostRecentProvider instead" )
0 commit comments