@@ -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+
5563def 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
5967class 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 )
0 commit comments