Skip to content

Commit ac62ec8

Browse files
committed
update tests
1 parent 5efe9ad commit ac62ec8

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

tests/test_bidstream_client.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,15 @@ def encode_keys(keys):
2626
return key_json
2727

2828

29-
def key_bidstream_response_json(keys, identity_scope=IdentityScope.UID2):
29+
def key_bidstream_response_with_lifetime_json(keys, identity_scope, max_bidstream_lifetime_seconds):
30+
if identity_scope is None:
31+
identity_scope = IdentityScope.UID2
32+
if max_bidstream_lifetime_seconds is None:
33+
max_bidstream_lifetime_seconds = dt.timedelta(days=3).total_seconds()
3034
encoded_keys = encode_keys(keys)
3135
json_obj = {
3236
"body": {
33-
"max_bidstream_lifetime_seconds": dt.timedelta(days=3).total_seconds(),
37+
"max_bidstream_lifetime_seconds": max_bidstream_lifetime_seconds,
3438
"identity_scope": identity_scope.name,
3539
"allow_clock_skew_seconds": 1800, # 30 mins
3640
"keys": encoded_keys,
@@ -52,8 +56,12 @@ def key_bidstream_response_json(keys, identity_scope=IdentityScope.UID2):
5256
return json.dumps(json_obj)
5357

5458

59+
def key_bidstream_response_json(keys, identity_scope=IdentityScope.UID2, max_bidstream_lifetime_seconds=None):
60+
return key_bidstream_response_with_lifetime_json(keys, identity_scope, max_bidstream_lifetime_seconds)
61+
62+
5563
def key_bidstream_response_json_default_keys(identity_scope=IdentityScope.UID2):
56-
return key_bidstream_response_json([master_key, site_key], identity_scope)
64+
return key_bidstream_response_with_lifetime_json([master_key, site_key], identity_scope, None)
5765

5866

5967
class TestBidStreamClient(unittest.TestCase):
@@ -118,11 +126,13 @@ def test_phone_uids(self): # PhoneTest
118126
def test_token_lifetime_too_long_for_bidstream_but_remaining_lifetime_allowed(self): # TokenLifetimeTooLongForBidstreamButRemainingLifetimeAllowed
119127
generated = YESTERDAY
120128
expires_in_sec = generated + dt.timedelta(days=3) + dt.timedelta(minutes=1)
129+
max_bidstream_lifetime_seconds = dt.timedelta(days=3).total_seconds()
121130
for expected_scope, expected_version in test_cases_all_scopes_all_versions:
122131
with self.subTest(expected_scope=expected_scope, expected_version=expected_version):
123132
token = generate_uid_token(expected_scope, expected_version, generated_at=generated,
124133
expires_at=expires_in_sec)
125-
self.refresh(key_bidstream_response_json_default_keys(expected_scope))
134+
self.refresh(key_bidstream_response_json([master_key, site_key], expected_scope,
135+
max_bidstream_lifetime_seconds))
126136
result = self._client.decrypt_token_into_raw_uid(token, None)
127137
if expected_version == AdvertisingTokenVersion.ADVERTISING_TOKEN_V2:
128138
self.assert_success(result, expected_version, expected_scope)

tests/test_sharing_client.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ def encode_keys(keys):
3535
return key_json
3636

3737

38-
def key_sharing_response_json(keys, identity_scope=IdentityScope.UID2, caller_site_id=site_id, default_keyset_id=None, token_expiry_seconds=2592000):
38+
def key_sharing_response_json(keys, identity_scope=IdentityScope.UID2, caller_site_id=site_id, default_keyset_id=None, token_expiry_seconds=2592000, max_sharing_lifetime_seconds=None):
39+
if max_sharing_lifetime_seconds is None:
40+
max_sharing_lifetime_seconds = dt.timedelta(days=30).total_seconds()
3941
encoded_keys = encode_keys(keys)
4042
json_obj = {
4143
"body": {
@@ -44,7 +46,7 @@ def key_sharing_response_json(keys, identity_scope=IdentityScope.UID2, caller_si
4446
"token_expiry_seconds": token_expiry_seconds,
4547
"identity_scope": identity_scope.name,
4648
"allow_clock_skew_seconds": 1800, # 30 mins
47-
"max_sharing_lifetime_seconds": dt.timedelta(days=30).total_seconds(),
49+
"max_sharing_lifetime_seconds": max_sharing_lifetime_seconds,
4850
"keys": encoded_keys,
4951
"unexpected_header_field": 12345 # ensure new fields can be handled by old SDK versions
5052
}
@@ -94,11 +96,13 @@ def test_smoke_test_for_sharing(self): # SmokeTestForSharing
9496
def test_token_lifetime_too_long_for_sharing_but_remaining_lifetime_allowed(self): # TokenLifetimeTooLongForSharingButRemainingLifetimeAllowed
9597
generated = YESTERDAY
9698
expires_in_sec = generated + dt.timedelta(days=31)
99+
max_sharing_lifetime_seconds = dt.timedelta(days=30).total_seconds()
97100
for expected_scope, expected_version in test_cases_all_scopes_all_versions:
98101
with self.subTest(expected_scope=expected_scope, expected_version=expected_version):
99102
token = generate_uid_token(expected_scope, expected_version, generated_at=generated,
100103
expires_at=expires_in_sec)
101-
self.refresh(key_sharing_response_json_default_keys(expected_scope))
104+
self.refresh(key_sharing_response_json([master_key, site_key], expected_scope,
105+
max_sharing_lifetime_seconds=max_sharing_lifetime_seconds))
102106

103107
result = self._client.decrypt_token_into_raw_uid(token)
104108
if expected_version == AdvertisingTokenVersion.ADVERTISING_TOKEN_V2:

0 commit comments

Comments
 (0)