@@ -16,16 +16,38 @@ def setUp(self):
1616 self ._key_collection = create_key_collection (IdentityScope .UID2 )
1717 self ._client = SharingClient (self ._CONST_BASE_URL , self ._CONST_API_KEY , client_secret )
1818
19+ def _assert_success (self , decryption_response , token_version , scope ):
20+ self .assertTrue (decryption_response .success )
21+ self .assertEqual (decryption_response .uid , example_uid )
22+ self .assertEqual (decryption_response .advertising_token_version , token_version )
23+ if (token_version == AdvertisingTokenVersion .ADVERTISING_TOKEN_V3
24+ or token_version == AdvertisingTokenVersion .ADVERTISING_TOKEN_V4 ):
25+ self .assertEqual (decryption_response .identity_type , IdentityType .Email )
26+ else :
27+ self .assertEqual (decryption_response .identity_type , None )
28+ self .assertEqual (decryption_response .identity_scope , scope )
29+ self .assertEqual (decryption_response .is_client_side_generated , False )
30+
31+ def _assert_fails (self , decryption_response , token_version , scope ):
32+ self .assertFalse (decryption_response .success )
33+ self .assertEqual (decryption_response .status , DecryptionStatus .INVALID_TOKEN_LIFETIME )
34+ self .assertEqual (decryption_response .advertising_token_version , token_version )
35+ self .assertEqual (decryption_response .identity_scope , scope )
36+ if (token_version == AdvertisingTokenVersion .ADVERTISING_TOKEN_V3
37+ or token_version == AdvertisingTokenVersion .ADVERTISING_TOKEN_V4 ):
38+ self .assertEqual (decryption_response .identity_type , IdentityType .Email )
39+
40+ def decrypt_and_assert_success (self , token , token_version , scope ):
41+ decrypted = self ._client .decrypt_token_into_raw_uid (token )
42+ self ._assert_success (decrypted , token_version , scope )
43+
1944 def test_smoke_test (self , mock_refresh_sharing_keys ): # SmokeTest
2045 for expected_scope , expected_version in test_cases_all_scopes_all_versions :
2146 with self .subTest (expected_scope = expected_scope , expected_version = expected_version ):
2247 token = generate_uid_token (expected_scope , expected_version )
2348 mock_refresh_sharing_keys .return_value = RefreshResponse .make_success (create_key_collection (expected_scope ))
2449 self ._client .refresh ()
25- decrypted = self ._client .decrypt_token_into_raw_uid (token )
26- self .assertEqual (decrypted .identity_scope , expected_scope )
27- self .assertEqual (decrypted .advertising_token_version , expected_version )
28- self .assertEqual ((now - decrypted .established ).total_seconds (), 0 )
50+ self .decrypt_and_assert_success (token , expected_version , expected_scope )
2951
3052 def test_token_lifetime_too_long_for_sharing (self , mock_refresh_sharing_keys ): # TokenLifetimeTooLongForSharing
3153 expires_in_sec = dt .datetime .now (tz = timezone .utc ) + dt .timedelta (days = 31 )
@@ -38,8 +60,7 @@ def test_token_lifetime_too_long_for_sharing(self, mock_refresh_sharing_keys):
3860 99999 , 86400 , max_sharing_lifetime ))
3961 self ._client .refresh ()
4062 result = self ._client .decrypt_token_into_raw_uid (token )
41- self .assertFalse (result .success )
42- self .assertEqual (DecryptionStatus .INVALID_TOKEN_LIFETIME , result .status )
63+ self ._assert_fails (result , expected_version , expected_scope )
4364
4465 def test_token_generated_in_the_future_to_simulate_clock_skew (self , mock_refresh_sharing_keys ): # TokenGeneratedInTheFutureToSimulateClockSkew
4566 created_at_future = dt .datetime .now (tz = timezone .utc ) + dt .timedelta (minutes = 31 ) #max allowed clock skew is 30m
@@ -51,8 +72,7 @@ def test_token_generated_in_the_future_to_simulate_clock_skew(self, mock_refresh
5172 99999 , 86400 ))
5273 self ._client .refresh ()
5374 result = self ._client .decrypt_token_into_raw_uid (token )
54- self .assertFalse (result .success )
55- self .assertEqual (DecryptionStatus .INVALID_TOKEN_LIFETIME , result .status )
75+ self ._assert_fails (result , expected_version , expected_scope )
5676
5777 def test_token_generated_in_the_future_within_allowed_clock_skew (self , mock_refresh_sharing_keys ): # TokenGeneratedInTheFutureWithinAllowedClockSkew
5878 created_at_future = dt .datetime .now (tz = timezone .utc ) + dt .timedelta (minutes = 29 ) #max allowed clock skew is 30m
0 commit comments