@@ -45,21 +45,31 @@ def cross_platform_consistency_check_base64_url_test(self, raw_input, expected_b
4545 decoded = Uid2Base64UrlCoder .decode (base64_url_encoded_str )
4646 self .assertEqual (decoded , raw_input )
4747
48- def validate_advertising_token (self , advertising_token_string , identity_scope , identity_type ):
48+ def validate_advertising_token (self , advertising_token_string , identity_scope , identity_type ,
49+ token_version = AdvertisingTokenVersion .ADVERTISING_TOKEN_V4 ):
50+
51+ if token_version == AdvertisingTokenVersion .ADVERTISING_TOKEN_V2 :
52+ self .assertEqual ("A" , advertising_token_string [0 ])
53+ self .assertEqual ("g" , advertising_token_string [1 ])
54+ return
55+
4956 first_char = advertising_token_string [0 ]
5057 if identity_scope == IdentityScope .UID2 :
5158 self .assertEqual ("A" if identity_type == IdentityType .Email .value else "B" , first_char )
5259 else :
5360 self .assertEqual ("E" if identity_type == IdentityType .Email .value else "F" , first_char )
5461
5562 second_char = advertising_token_string [1 ]
56- self .assertEqual ("4" , second_char )
57-
58- # No URL-unfriendly characters allowed
59- self .assertEqual (- 1 , advertising_token_string .find ("=" ))
60- self .assertEqual (- 1 , advertising_token_string .find ("+" ))
61- self .assertEqual (- 1 , advertising_token_string .find ("/" ))
63+ if token_version == AdvertisingTokenVersion .ADVERTISING_TOKEN_V3 :
64+ self .assertEqual ("3" , second_char )
65+ return
66+ else :
67+ self .assertEqual ("4" , second_char )
6268
69+ # No URL-unfriendly characters allowed
70+ self .assertEqual (- 1 , advertising_token_string .find ("=" ))
71+ self .assertEqual (- 1 , advertising_token_string .find ("+" ))
72+ self .assertEqual (- 1 , advertising_token_string .find ("/" ))
6373
6474 def generate_uid2_token_v4 (self , uid , master_key , site_id , site_key , params = Params (), identity_type = IdentityType .Email , identity_scope = IdentityScope .UID2 ):
6575 advertising_token = UID2TokenGenerator .generate_uid2_token_v4 (uid , master_key , site_id , site_key , params )
0 commit comments