Skip to content

Commit 9078e80

Browse files
committed
Update unit tests
1 parent 3b2f090 commit 9078e80

File tree

2 files changed

+97
-0
lines changed

2 files changed

+97
-0
lines changed

src/test/java/com/uid2/client/BidstreamClientTests.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,21 @@ private static Stream<Arguments> data_IdentityScopeAndType_TestCases() {
206206
);
207207
}
208208

209+
@ParameterizedTest
210+
@ValueSource(strings = {"V2", "V3", "V4"})
211+
public void userOptedOutTest(TokenVersionForTesting tokenVersion) throws Exception {
212+
refresh(keyBidstreamResponse(IdentityScope.UID2, MASTER_KEY, SITE_KEY));
213+
int privacyBits = PrivacyBitsBuilder.Builder().WithOptedOut(true).Build();
214+
215+
String advertisingToken = AdvertisingTokenBuilder.builder().withVersion(tokenVersion).withPrivacyBits(privacyBits).build();
216+
217+
validateAdvertisingToken(advertisingToken, IdentityScope.UID2, IdentityType.Email, tokenVersion);
218+
DecryptionResponse res = bidstreamClient.decryptTokenIntoRawUid(advertisingToken, null);
219+
assertFalse(res.isSuccess());
220+
assertEquals(DecryptionStatus.SUCCESS, res.getStatus());
221+
assertNull(res.getUid());
222+
}
223+
209224
// These are the domain or app names associated with site SITE_ID, as defined by keyBidstreamResponse()
210225
@ParameterizedTest
211226
@CsvSource({

src/test/java/com/uid2/client/KeyParserTests.java

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,88 @@ public void parseErrorKeyList() {
9696
assertThrows(Exception.class, () -> parse("{\"body\": [{\"id\": 5}]}"));
9797
}
9898

99+
@Test
100+
public void parseMissingSiteData() {
101+
String json = "{ \"body\": {\n" +
102+
" \"keys\": [\n" +
103+
" {\n" +
104+
" \"id\": 3,\n" +
105+
" \"keyset_id\": 99999,\n" +
106+
" \"created\": 1609459200,\n" +
107+
" \"activates\": 1609459210,\n" +
108+
" \"expires\": 1893456000,\n" +
109+
" \"secret\": \"o8HsvkwJ5Ulnrd0uui3GpukpwDapj+JLqb7qfN/GJKo=\"\n" +
110+
" }\n" +
111+
" ]\n" +
112+
" }\n" +
113+
"}";
114+
KeyContainer keyContainer = parse(json);
115+
boolean isAllowed = keyContainer.isDomainOrAppNameAllowedForSite(1, "example.com");
116+
assertFalse(isAllowed);
117+
assertNotNull(keyContainer.getKey(3));
118+
}
119+
120+
@Test
121+
public void parseEmptySiteData() {
122+
String json = "{ \"body\": {\n" +
123+
" \"keys\": [\n" +
124+
" {\n" +
125+
" \"id\": 3,\n" +
126+
" \"keyset_id\": 99999,\n" +
127+
" \"created\": 1609459200,\n" +
128+
" \"activates\": 1609459210,\n" +
129+
" \"expires\": 1893456000,\n" +
130+
" \"secret\": \"o8HsvkwJ5Ulnrd0uui3GpukpwDapj+JLqb7qfN/GJKo=\"\n" +
131+
" }\n" +
132+
" ],\n" +
133+
" \"site_data\": []\n" +
134+
" }\n" +
135+
"}";
136+
KeyContainer keyContainer = parse(json);
137+
boolean isAllowed = keyContainer.isDomainOrAppNameAllowedForSite(1, "example.com");
138+
assertFalse(isAllowed);
139+
assertFalse(keyContainer.isDomainOrAppNameAllowedForSite(1, null));
140+
assertNotNull(keyContainer.getKey(3));
141+
}
142+
143+
@Test
144+
public void parseSiteDataSharingEndpoint() {
145+
String json = "{\n" +
146+
" \"body\": {\n" +
147+
" \"keys\": [\n" +
148+
" {\n" +
149+
" \"id\": 3,\n" +
150+
" \"keyset_id\": 99999,\n" +
151+
" \"created\": 1609459200,\n" +
152+
" \"activates\": 1609459210,\n" +
153+
" \"expires\": 1893456000,\n" +
154+
" \"secret\": \"o8HsvkwJ5Ulnrd0uui3GpukpwDapj+JLqb7qfN/GJKo=\"\n" +
155+
" }\n" +
156+
" ],\n" +
157+
" \"site_data\": [\n" +
158+
" {\n" +
159+
" \"id\": 9,\n" +
160+
" \"domain_names\": [\"example.com\"]\n" +
161+
" },\n" +
162+
" {\n" +
163+
" \"id\": 100,\n" +
164+
" \"domain_names\": [\"example.org\", \"example.net\"]\n" +
165+
" }\n" +
166+
" ]\n" +
167+
" }\n" +
168+
"}";
169+
KeyContainer keyContainer = parse(json);
170+
assertTrue(keyContainer.isDomainOrAppNameAllowedForSite(9, "example.com"));
171+
assertFalse(keyContainer.isDomainOrAppNameAllowedForSite(9, "example.org"));
172+
assertFalse(keyContainer.isDomainOrAppNameAllowedForSite(9, "example.net"));
173+
174+
assertFalse(keyContainer.isDomainOrAppNameAllowedForSite(100, "example.com"));
175+
assertTrue(keyContainer.isDomainOrAppNameAllowedForSite(100, "example.org"));
176+
assertTrue(keyContainer.isDomainOrAppNameAllowedForSite(100, "example.net"));
177+
178+
assertNotNull(keyContainer.getKey(3));
179+
}
180+
99181
@Test
100182
public void parseWithNullTokenExpirySecondField() {
101183
String s = "{ \"body\": { " +

0 commit comments

Comments
 (0)