Skip to content

Commit

Permalink
Update unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
asloobq committed Oct 8, 2024
1 parent 3b2f090 commit 9078e80
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/test/java/com/uid2/client/BidstreamClientTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,21 @@ private static Stream<Arguments> data_IdentityScopeAndType_TestCases() {
);
}

@ParameterizedTest
@ValueSource(strings = {"V2", "V3", "V4"})
public void userOptedOutTest(TokenVersionForTesting tokenVersion) throws Exception {
refresh(keyBidstreamResponse(IdentityScope.UID2, MASTER_KEY, SITE_KEY));
int privacyBits = PrivacyBitsBuilder.Builder().WithOptedOut(true).Build();

String advertisingToken = AdvertisingTokenBuilder.builder().withVersion(tokenVersion).withPrivacyBits(privacyBits).build();

validateAdvertisingToken(advertisingToken, IdentityScope.UID2, IdentityType.Email, tokenVersion);
DecryptionResponse res = bidstreamClient.decryptTokenIntoRawUid(advertisingToken, null);
assertFalse(res.isSuccess());
assertEquals(DecryptionStatus.SUCCESS, res.getStatus());
assertNull(res.getUid());
}

// These are the domain or app names associated with site SITE_ID, as defined by keyBidstreamResponse()
@ParameterizedTest
@CsvSource({
Expand Down
82 changes: 82 additions & 0 deletions src/test/java/com/uid2/client/KeyParserTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,88 @@ public void parseErrorKeyList() {
assertThrows(Exception.class, () -> parse("{\"body\": [{\"id\": 5}]}"));
}

@Test
public void parseMissingSiteData() {
String json = "{ \"body\": {\n" +
" \"keys\": [\n" +
" {\n" +
" \"id\": 3,\n" +
" \"keyset_id\": 99999,\n" +
" \"created\": 1609459200,\n" +
" \"activates\": 1609459210,\n" +
" \"expires\": 1893456000,\n" +
" \"secret\": \"o8HsvkwJ5Ulnrd0uui3GpukpwDapj+JLqb7qfN/GJKo=\"\n" +
" }\n" +
" ]\n" +
" }\n" +
"}";
KeyContainer keyContainer = parse(json);
boolean isAllowed = keyContainer.isDomainOrAppNameAllowedForSite(1, "example.com");
assertFalse(isAllowed);
assertNotNull(keyContainer.getKey(3));
}

@Test
public void parseEmptySiteData() {
String json = "{ \"body\": {\n" +
" \"keys\": [\n" +
" {\n" +
" \"id\": 3,\n" +
" \"keyset_id\": 99999,\n" +
" \"created\": 1609459200,\n" +
" \"activates\": 1609459210,\n" +
" \"expires\": 1893456000,\n" +
" \"secret\": \"o8HsvkwJ5Ulnrd0uui3GpukpwDapj+JLqb7qfN/GJKo=\"\n" +
" }\n" +
" ],\n" +
" \"site_data\": []\n" +
" }\n" +
"}";
KeyContainer keyContainer = parse(json);
boolean isAllowed = keyContainer.isDomainOrAppNameAllowedForSite(1, "example.com");
assertFalse(isAllowed);
assertFalse(keyContainer.isDomainOrAppNameAllowedForSite(1, null));
assertNotNull(keyContainer.getKey(3));
}

@Test
public void parseSiteDataSharingEndpoint() {
String json = "{\n" +
" \"body\": {\n" +
" \"keys\": [\n" +
" {\n" +
" \"id\": 3,\n" +
" \"keyset_id\": 99999,\n" +
" \"created\": 1609459200,\n" +
" \"activates\": 1609459210,\n" +
" \"expires\": 1893456000,\n" +
" \"secret\": \"o8HsvkwJ5Ulnrd0uui3GpukpwDapj+JLqb7qfN/GJKo=\"\n" +
" }\n" +
" ],\n" +
" \"site_data\": [\n" +
" {\n" +
" \"id\": 9,\n" +
" \"domain_names\": [\"example.com\"]\n" +
" },\n" +
" {\n" +
" \"id\": 100,\n" +
" \"domain_names\": [\"example.org\", \"example.net\"]\n" +
" }\n" +
" ]\n" +
" }\n" +
"}";
KeyContainer keyContainer = parse(json);
assertTrue(keyContainer.isDomainOrAppNameAllowedForSite(9, "example.com"));
assertFalse(keyContainer.isDomainOrAppNameAllowedForSite(9, "example.org"));
assertFalse(keyContainer.isDomainOrAppNameAllowedForSite(9, "example.net"));

assertFalse(keyContainer.isDomainOrAppNameAllowedForSite(100, "example.com"));
assertTrue(keyContainer.isDomainOrAppNameAllowedForSite(100, "example.org"));
assertTrue(keyContainer.isDomainOrAppNameAllowedForSite(100, "example.net"));

assertNotNull(keyContainer.getKey(3));
}

@Test
public void parseWithNullTokenExpirySecondField() {
String s = "{ \"body\": { " +
Expand Down

0 comments on commit 9078e80

Please sign in to comment.