Skip to content

Commit 2a2e40b

Browse files
Merge pull request #48 from IABTechLab/cbc-UID2-4380-cloud-encryption-e2e-tests
Adding new tests for cloud encryption on core
2 parents cc16684 + cd3e09e commit 2a2e40b

File tree

5 files changed

+76
-7
lines changed

5 files changed

+76
-7
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<properties>
1212
<maven.compiler.source>21</maven.compiler.source>
1313
<maven.compiler.target>21</maven.compiler.target>
14-
<uid2-shared.version>7.21.7</uid2-shared.version>
14+
<uid2-shared.version>8.0.6</uid2-shared.version>
1515
</properties>
1616
<packaging>jar</packaging>
1717

src/test/java/app/common/HttpClient.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.fasterxml.jackson.databind.JsonNode;
44
import okhttp3.*;
55

6+
import java.util.Map;
67
import java.util.Objects;
78

89
public final class HttpClient {
@@ -65,11 +66,15 @@ private static String createErrorMessage(HttpMethod method, String url, int code
6566
private HttpClient() {
6667
}
6768

68-
public static String get(String url, String bearerToken) throws Exception {
69-
Request request = buildRequest(HttpMethod.GET, url, null, bearerToken);
69+
public static String get(String url, String bearerToken, Map<String, String> additionalHeaders) throws Exception {
70+
Request request = buildRequest(HttpMethod.GET, url, null, bearerToken, additionalHeaders);
7071
return execute(request, HttpMethod.GET);
7172
}
7273

74+
public static String get(String url, String bearerToken) throws Exception {
75+
return get(url, bearerToken, null);
76+
}
77+
7378
public static String get(String url) throws Exception {
7479
return get(url, null);
7580
}
@@ -89,13 +94,23 @@ public static String execute(Request request, HttpMethod method) throws Exceptio
8994
}
9095

9196
private static Request buildRequest(HttpMethod method, String url, String body, String bearerToken) {
97+
return buildRequest(method, url, body, bearerToken, null);
98+
}
99+
100+
private static Request buildRequest(HttpMethod method, String url, String body, String bearerToken, Map<String, String> additionalHeaders) {
92101
Request.Builder requestBuilder = new Request.Builder()
93102
.url(url);
94103

95104
if (bearerToken != null) {
96105
requestBuilder = requestBuilder.addHeader("Authorization", "Bearer " + bearerToken);
97106
}
98107

108+
if (additionalHeaders != null) {
109+
for (Map.Entry<String, String> header : additionalHeaders.entrySet()) {
110+
requestBuilder = requestBuilder.addHeader(header.getKey(), header.getValue());
111+
}
112+
}
113+
99114
return (switch (method) {
100115
case GET -> requestBuilder.get();
101116
case POST -> requestBuilder.post(RequestBody.create(body, JSON));

src/test/java/app/component/Core.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
import app.common.Mapper;
66
import com.fasterxml.jackson.databind.JsonNode;
77

8+
import java.util.HashMap;
9+
import java.util.Map;
10+
811
public class Core extends App {
912
private static final String CORE_API_TOKEN = EnvUtil.getEnv("UID2_E2E_CORE_API_TOKEN");
1013
private static final String OPTOUT_TO_CALL_CORE_API_TOKEN = EnvUtil.getEnv("UID2_E2E_OPTOUT_TO_CALL_CORE_API_TOKEN");
@@ -25,7 +28,13 @@ public JsonNode attest(String attestationRequest) throws Exception {
2528
}
2629

2730
public JsonNode getWithCoreApiToken(String path) throws Exception {
28-
String response = HttpClient.get(getBaseUrl() + path, CORE_API_TOKEN);
31+
return getWithCoreApiToken(path, "0.0.0");
32+
}
33+
34+
public JsonNode getWithCoreApiToken(String path, String operatorVersion) throws Exception {
35+
Map<String, String> headers = new HashMap<>();
36+
headers.put("X-UID2-AppVersion", "uid2-operator=" + operatorVersion);
37+
String response = HttpClient.get(getBaseUrl() + path, CORE_API_TOKEN, headers);
2938
return Mapper.OBJECT_MAPPER.readTree(response);
3039
}
3140

src/test/java/suite/core/CoreRefreshTest.java

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,27 @@
1313

1414
public class CoreRefreshTest {
1515
@ParameterizedTest(name = "Refresh test - UrlPath: {1} - JsonPath: {2}")
16-
@MethodSource({"suite.core.TestData#refreshArgs"})
16+
@MethodSource({"suite.core.TestData#refreshArgs", "suite.core.TestData#refreshArgsEncrypted"})
1717
public void testLocationRefresh_Public_Success(Core core, String urlPath, String jsonPath) throws Exception {
18-
JsonNode response = core.getWithCoreApiToken(urlPath);
18+
JsonNode response = core.getWithCoreApiToken(urlPath, "5.0.1");
1919

2020
assertAll("testLocationRefresh_Public_Success has version and location",
2121
() -> assertNotNull(response),
2222
() -> assertNotEquals("", response.at("/version").asText(), "Version was empty"),
23-
() -> assertNotEquals("", response.at("/" + jsonPath + "/location").asText(), "/" + jsonPath + "/location was empty"));
23+
() -> assertNotEquals("", response.at("/" + jsonPath + "/location").asText(), "/" + jsonPath + "/location was empty"),
24+
() -> assertFalse(response.at("/" + jsonPath + "/location").asText().contains("encrypted")));
25+
}
26+
27+
@ParameterizedTest(name = "Refresh test - UrlPath: {1} - JsonPath: {2}")
28+
@MethodSource({"suite.core.TestData#refreshArgsEncrypted"})
29+
public void testLocationRefreshCloudEncryption_Public_Success(Core core, String urlPath, String jsonPath) throws Exception {
30+
JsonNode response = core.getWithCoreApiToken(urlPath, "10000.0.1");
31+
32+
assertAll("testLocationRefresh_Public_Success has version and location",
33+
() -> assertNotNull(response),
34+
() -> assertNotEquals("", response.at("/version").asText(), "Version was empty"),
35+
() -> assertNotEquals("", response.at("/" + jsonPath + "/location").asText(), "/" + jsonPath + "/location was empty"),
36+
() -> assertTrue(response.at("/" + jsonPath + "/location").asText().contains("encrypted")));
2437
}
2538

2639
@ParameterizedTest(name = "Refresh test - UrlPath: {1} - CollectionName: {2}")
@@ -42,6 +55,26 @@ public void testCollectionRefresh_Public_Success(Core core, String urlPath, Stri
4255
}
4356
}
4457

58+
@ParameterizedTest(name = "Refresh test - UrlPath: {1} - CollectionName: {2}")
59+
@MethodSource({"suite.core.TestData#collectionEndpointArgs"})
60+
public void testCollectionRefreshCloud_Encryption_Public_Success(Core core, String urlPath, String collectionName) throws Exception {
61+
JsonNode response = core.getWithCoreApiToken(urlPath, "10000.0.1");
62+
63+
assertAll("testCollectionRefresh_Public_Success has version and collection",
64+
() -> assertNotNull(response, "Response should not be null"),
65+
() -> assertNotEquals("", response.at("/version").asText(), "Version was empty"),
66+
() -> assertNotNull(response.at("/" + collectionName), "Collection should not be null")
67+
);
68+
69+
ArrayNode nodes = (ArrayNode) response.at("/" + collectionName);
70+
for (JsonNode node : nodes) {
71+
assertTrue(JsonAssert.hasContentInFields(
72+
node, List.of("/effective", "/expires", "/location", "/size")
73+
), "Collection node was missing expected content");
74+
assertTrue(node.get("location").asText().contains("encrypted"));
75+
}
76+
}
77+
4578
@ParameterizedTest(name = "Refresh test - UrlPath: {1} - JsonPath: {2}")
4679
@MethodSource({"suite.core.TestData#optOutRefreshArgs"})
4780
public void testOptOut_LocationRefresh_Public_Success(Core core, String urlPath, String jsonPath) throws Exception {

src/test/java/suite/core/TestData.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,19 @@ public static Set<Arguments> refreshArgs() {
2727
for (Core core : cores) {
2828
args.add(Arguments.of(core, "/key/acl/refresh", "keys_acl"));
2929
args.add(Arguments.of(core, "/key/refresh", "keys"));
30+
}
31+
32+
return args;
33+
}
34+
35+
public static Set<Arguments> refreshArgsEncrypted() {
36+
Set<Core> cores = AppsMap.getApps(Core.class);
37+
Set<Arguments> args = new HashSet<>();
38+
for (Core core : cores) {
39+
args.add(Arguments.of(core, "/key/keyset/refresh", "keysets"));
40+
args.add(Arguments.of(core, "/key/keyset-keys/refresh", "keyset_keys"));
3041
args.add(Arguments.of(core, "/clients/refresh", "client_keys"));
42+
args.add(Arguments.of(core, "/sites/refresh", "sites"));
3143
args.add(Arguments.of(core, "/client_side_keypairs/refresh", "client_side_keypairs"));
3244
}
3345

0 commit comments

Comments
 (0)