@@ -206,16 +206,85 @@ private static Stream<Arguments> data_IdentityScopeAndType_TestCases() {
206206 );
207207 }
208208
209+ // These are the domain or app names associated with site SITE_ID, as defined by keyBidstreamResponse()
209210 @ ParameterizedTest
210211 @ CsvSource ({
211212 "example.com, V2" ,
212213 "example.org, V2" ,
214+ "com.123.Game.App.android, V2" ,
215+ "123456789, V2" ,
216+ "example.com, V3" ,
217+ "example.org, V3" ,
218+ "com.123.Game.App.android, V3" ,
219+ "123456789, V3" ,
213220 "example.com, V4" ,
214221 "example.org, V4" ,
215- "example.com, V4" ,
216- "example.org, V4"
222+ "com.123.Game.App.android, V4" ,
223+ "123456789, V4"
224+ })
225+ public void tokenIsCstgDerivedTest (String domainName , TokenVersionForTesting tokenVersion ) throws Exception {
226+ refresh (keyBidstreamResponse (IdentityScope .UID2 , MASTER_KEY , SITE_KEY ));
227+ int privacyBits = PrivacyBitsBuilder .Builder ().WithClientSideGenerated (true ).Build ();
228+
229+ String advertisingToken = AdvertisingTokenBuilder .builder ().withVersion (tokenVersion ).withPrivacyBits (privacyBits ).build ();
230+
231+ validateAdvertisingToken (advertisingToken , IdentityScope .UID2 , IdentityType .Email , tokenVersion );
232+ DecryptionResponse res = bidstreamClient .decryptTokenIntoRawUid (advertisingToken , domainName );
233+ assertTrue (res .getIsClientSideGenerated ());
234+ assertTrue (res .isSuccess ());
235+ assertEquals (DecryptionStatus .SUCCESS , res .getStatus ());
236+ assertEquals (EXAMPLE_UID , res .getUid ());
237+ }
238+
239+ // These are the domain or app names associated with site SITE_ID but vary in capitalization, as defined by keyBidstreamResponse()
240+ @ ParameterizedTest
241+ @ CsvSource ({
242+ "Example.com, V2" ,
243+ "Example.Org, V2" ,
244+ "com.123.Game.App.android, V2" ,
245+ "Example.com, V3" ,
246+ "Example.Org, V3" ,
247+ "com.123.Game.App.android, V3" ,
248+ "Example.com, V4" ,
249+ "Example.Org, V4" ,
250+ "com.123.Game.App.android, V4" ,
251+ })
252+ public void domainOrAppNameCaseInSensitiveTest (String domainName , TokenVersionForTesting tokenVersion ) throws Exception {
253+ refresh (keyBidstreamResponse (IdentityScope .UID2 , MASTER_KEY , SITE_KEY ));
254+ int privacyBits = PrivacyBitsBuilder .Builder ().WithClientSideGenerated (true ).Build ();
255+
256+ String advertisingToken = AdvertisingTokenBuilder .builder ().withVersion (tokenVersion ).withPrivacyBits (privacyBits ).build ();
257+
258+ validateAdvertisingToken (advertisingToken , IdentityScope .UID2 , IdentityType .Email , tokenVersion );
259+ DecryptionResponse res = bidstreamClient .decryptTokenIntoRawUid (advertisingToken , domainName );
260+ assertTrue (res .getIsClientSideGenerated ());
261+ assertTrue (res .isSuccess ());
262+ assertEquals (DecryptionStatus .SUCCESS , res .getStatus ());
263+ assertEquals (EXAMPLE_UID , res .getUid ());
264+ }
265+
266+ @ ParameterizedTest
267+ @ CsvSource ({
268+ ", V2" ,
269+ "example.net, V2" , // Domain associated with site SITE_ID2, as defined by keyBidstreamResponse().
270+ "example.edu, V2" , // Domain associated with site SITE_ID2, as defined by keyBidstreamResponse().
271+ "com.123.Game.App.ios, V2" , // App associated with site SITE_ID2, as defined by keyBidstreamResponse().
272+ "123456780, V2" , // App associated with site SITE_ID2, as defined by keyBidstreamResponse().
273+ "foo.com, V2" , // Domain not associated with any site.
274+ ", V3" ,
275+ "example.net, V3" , // Domain associated with site SITE_ID2, as defined by keyBidstreamResponse().
276+ "example.edu, V3" , // Domain associated with site SITE_ID2, as defined by keyBidstreamResponse().
277+ "com.123.Game.App.ios, V3" , // App associated with site SITE_ID2, as defined by keyBidstreamResponse().
278+ "123456780, V3" , // App associated with site SITE_ID2, as defined by keyBidstreamResponse().
279+ "foo.com, V3" , // Domain not associated with any site.
280+ ", V4" ,
281+ "example.net, V4" , // Domain associated with site SITE_ID2, as defined by keyBidstreamResponse().
282+ "example.edu, V4" , // Domain associated with site SITE_ID2, as defined by keyBidstreamResponse().
283+ "com.123.Game.App.ios, V4" , // App associated with site SITE_ID2, as defined by keyBidstreamResponse().
284+ "123456780, V4" , // App associated with site SITE_ID2, as defined by keyBidstreamResponse().
285+ "foo.com, V4" , // Domain not associated with any site.
217286 })
218- public void TokenIsCstgDerivedTest (String domainName , TokenVersionForTesting tokenVersion ) throws Exception {
287+ public void tokenIsCstgDerivedDomainOrAppNameFailTest (String domainName , TokenVersionForTesting tokenVersion ) throws Exception {
219288 refresh (keyBidstreamResponse (IdentityScope .UID2 , MASTER_KEY , SITE_KEY ));
220289 int privacyBits = PrivacyBitsBuilder .Builder ().WithClientSideGenerated (true ).Build ();
221290
@@ -224,6 +293,42 @@ public void TokenIsCstgDerivedTest(String domainName, TokenVersionForTesting tok
224293 validateAdvertisingToken (advertisingToken , IdentityScope .UID2 , IdentityType .Email , tokenVersion );
225294 DecryptionResponse res = bidstreamClient .decryptTokenIntoRawUid (advertisingToken , domainName );
226295 assertTrue (res .getIsClientSideGenerated ());
296+ assertFalse (res .isSuccess ());
297+ assertEquals (DecryptionStatus .DOMAIN_OR_APP_NAME_CHECK_FAILED , res .getStatus ());
298+ assertNull (res .getUid ());
299+ }
300+
301+ // Any domain or app name is OK, because the token is not client-side generated.
302+ @ ParameterizedTest
303+ @ CsvSource ({
304+ ", V2" ,
305+ "example.net, V2" , // Domain associated with site SITE_ID2, as defined by keyBidstreamResponse().
306+ "example.edu, V2" , // Domain associated with site SITE_ID2, as defined by keyBidstreamResponse().
307+ "com.123.Game.App.ios, V2" , // App associated with site SITE_ID2, as defined by keyBidstreamResponse().
308+ "123456780, V2" , // App associated with site SITE_ID2, as defined by keyBidstreamResponse().
309+ "foo.com, V2" , // Domain not associated with any site.
310+ ", V3" ,
311+ "example.net, V3" , // Domain associated with site SITE_ID2, as defined by keyBidstreamResponse().
312+ "example.edu, V3" , // Domain associated with site SITE_ID2, as defined by keyBidstreamResponse().
313+ "com.123.Game.App.ios, V3" , // App associated with site SITE_ID2, as defined by keyBidstreamResponse().
314+ "123456780, V3" , // App associated with site SITE_ID2, as defined by keyBidstreamResponse().
315+ "foo.com, V3" , // Domain not associated with any site.
316+ ", V4" ,
317+ "example.net, V4" , // Domain associated with site SITE_ID2, as defined by keyBidstreamResponse().
318+ "example.edu, V4" , // Domain associated with site SITE_ID2, as defined by keyBidstreamResponse().
319+ "com.123.Game.App.ios, V4" , // App associated with site SITE_ID2, as defined by keyBidstreamResponse().
320+ "123456780, V4" , // App associated with site SITE_ID2, as defined by keyBidstreamResponse().
321+ "foo.com, V4" , // Domain not associated with any site.
322+ })
323+ public void tokenIsNotCstgDerivedDomainNameSuccessTest (String domainName , TokenVersionForTesting tokenVersion ) throws Exception {
324+ refresh (keyBidstreamResponse (IdentityScope .UID2 , MASTER_KEY , SITE_KEY ));
325+ int privacyBits = PrivacyBitsBuilder .Builder ().WithClientSideGenerated (false ).Build ();
326+
327+ String advertisingToken = AdvertisingTokenBuilder .builder ().withVersion (tokenVersion ).withPrivacyBits (privacyBits ).build ();
328+
329+ validateAdvertisingToken (advertisingToken , IdentityScope .UID2 , IdentityType .Email , tokenVersion );
330+ DecryptionResponse res = bidstreamClient .decryptTokenIntoRawUid (advertisingToken , domainName );
331+ assertFalse (res .getIsClientSideGenerated ());
227332 assertTrue (res .isSuccess ());
228333 assertEquals (DecryptionStatus .SUCCESS , res .getStatus ());
229334 assertEquals (EXAMPLE_UID , res .getUid ());
@@ -352,16 +457,19 @@ private static String keyBidstreamResponse(IdentityScope identityScope, Key... k
352457 JsonArray domainNames1 = new JsonArray ();
353458 domainNames1 .add ("example.com" );
354459 domainNames1 .add ("example.org" );
460+ domainNames1 .add ("com.123.Game.App.android" );
461+ domainNames1 .add ("123456789" );
355462 site1 .add ("domain_names" , domainNames1 );
356463 site1 .addProperty ("unexpected_domain_field" , "123" );
357464
465+
358466 JsonObject site2 = new JsonObject ();
359- site1 .addProperty ("id" , SITE_ID2 );
467+ site2 .addProperty ("id" , SITE_ID2 );
360468 JsonArray domainNames2 = new JsonArray ();
361469 domainNames2 .add ("example.net" );
362470 domainNames2 .add ("example.edu" );
363- site1 .add ("domain_names" , domainNames2 );
364- site1 .addProperty ("unexpected_domain_field" , "123" );
471+ site2 .add ("domain_names" , domainNames2 );
472+ site2 .addProperty ("unexpected_domain_field" , "123" );
365473
366474 JsonArray siteData = new JsonArray ();
367475 siteData .add (site1 );
0 commit comments