Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<properties>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<uid2-shared.version>7.21.7</uid2-shared.version>
<uid2-shared.version>8.0.6</uid2-shared.version>
</properties>
<packaging>jar</packaging>

Expand Down
19 changes: 17 additions & 2 deletions src/test/java/app/common/HttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.fasterxml.jackson.databind.JsonNode;
import okhttp3.*;

import java.util.Map;
import java.util.Objects;

public final class HttpClient {
Expand Down Expand Up @@ -65,11 +66,15 @@ private static String createErrorMessage(HttpMethod method, String url, int code
private HttpClient() {
}

public static String get(String url, String bearerToken) throws Exception {
Request request = buildRequest(HttpMethod.GET, url, null, bearerToken);
public static String get(String url, String bearerToken, Map<String, String> additionalHeaders) throws Exception {
Request request = buildRequest(HttpMethod.GET, url, null, bearerToken, additionalHeaders);
return execute(request, HttpMethod.GET);
}

public static String get(String url, String bearerToken) throws Exception {
return get(url, bearerToken, null);
}

public static String get(String url) throws Exception {
return get(url, null);
}
Expand All @@ -89,13 +94,23 @@ public static String execute(Request request, HttpMethod method) throws Exceptio
}

private static Request buildRequest(HttpMethod method, String url, String body, String bearerToken) {
return buildRequest(method, url, body, bearerToken, null);
}

private static Request buildRequest(HttpMethod method, String url, String body, String bearerToken, Map<String, String> additionalHeaders) {
Request.Builder requestBuilder = new Request.Builder()
.url(url);

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

if (additionalHeaders != null) {
for (Map.Entry<String, String> header : additionalHeaders.entrySet()) {
requestBuilder = requestBuilder.addHeader(header.getKey(), header.getValue());
}
}

return (switch (method) {
case GET -> requestBuilder.get();
case POST -> requestBuilder.post(RequestBody.create(body, JSON));
Expand Down
11 changes: 10 additions & 1 deletion src/test/java/app/component/Core.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import app.common.Mapper;
import com.fasterxml.jackson.databind.JsonNode;

import java.util.HashMap;
import java.util.Map;

public class Core extends App {
private static final String CORE_API_TOKEN = EnvUtil.getEnv("UID2_E2E_CORE_API_TOKEN");
private static final String OPTOUT_TO_CALL_CORE_API_TOKEN = EnvUtil.getEnv("UID2_E2E_OPTOUT_TO_CALL_CORE_API_TOKEN");
Expand All @@ -25,7 +28,13 @@ public JsonNode attest(String attestationRequest) throws Exception {
}

public JsonNode getWithCoreApiToken(String path) throws Exception {
String response = HttpClient.get(getBaseUrl() + path, CORE_API_TOKEN);
return getWithCoreApiToken(path, "0.0.0");
}

public JsonNode getWithCoreApiToken(String path, String operatorVersion) throws Exception {
Map<String, String> headers = new HashMap<>();
headers.put("X-UID2-AppVersion", "uid2-operator=" + operatorVersion);
String response = HttpClient.get(getBaseUrl() + path, CORE_API_TOKEN, headers);
return Mapper.OBJECT_MAPPER.readTree(response);
}

Expand Down
39 changes: 36 additions & 3 deletions src/test/java/suite/core/CoreRefreshTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,27 @@

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

assertAll("testLocationRefresh_Public_Success has version and location",
() -> assertNotNull(response),
() -> assertNotEquals("", response.at("/version").asText(), "Version was empty"),
() -> assertNotEquals("", response.at("/" + jsonPath + "/location").asText(), "/" + jsonPath + "/location was empty"));
() -> assertNotEquals("", response.at("/" + jsonPath + "/location").asText(), "/" + jsonPath + "/location was empty"),
() -> assertFalse(response.at("/" + jsonPath + "/location").asText().contains("encrypted")));
}

@ParameterizedTest(name = "Refresh test - UrlPath: {1} - JsonPath: {2}")
@MethodSource({"suite.core.TestData#refreshArgsEncrypted"})
public void testLocationRefreshCloudEncryption_Public_Success(Core core, String urlPath, String jsonPath) throws Exception {
JsonNode response = core.getWithCoreApiToken(urlPath, "10000.0.1");

assertAll("testLocationRefresh_Public_Success has version and location",
() -> assertNotNull(response),
() -> assertNotEquals("", response.at("/version").asText(), "Version was empty"),
() -> assertNotEquals("", response.at("/" + jsonPath + "/location").asText(), "/" + jsonPath + "/location was empty"),
() -> assertTrue(response.at("/" + jsonPath + "/location").asText().contains("encrypted")));
}

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

@ParameterizedTest(name = "Refresh test - UrlPath: {1} - CollectionName: {2}")
@MethodSource({"suite.core.TestData#collectionEndpointArgs"})
public void testCollectionRefreshCloud_Encryption_Public_Success(Core core, String urlPath, String collectionName) throws Exception {
JsonNode response = core.getWithCoreApiToken(urlPath, "10000.0.1");

assertAll("testCollectionRefresh_Public_Success has version and collection",
() -> assertNotNull(response, "Response should not be null"),
() -> assertNotEquals("", response.at("/version").asText(), "Version was empty"),
() -> assertNotNull(response.at("/" + collectionName), "Collection should not be null")
);

ArrayNode nodes = (ArrayNode) response.at("/" + collectionName);
for (JsonNode node : nodes) {
assertTrue(JsonAssert.hasContentInFields(
node, List.of("/effective", "/expires", "/location", "/size")
), "Collection node was missing expected content");
assertTrue(node.get("location").asText().contains("encrypted"));
}
}

@ParameterizedTest(name = "Refresh test - UrlPath: {1} - JsonPath: {2}")
@MethodSource({"suite.core.TestData#optOutRefreshArgs"})
public void testOptOut_LocationRefresh_Public_Success(Core core, String urlPath, String jsonPath) throws Exception {
Expand Down
12 changes: 12 additions & 0 deletions src/test/java/suite/core/TestData.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,19 @@ public static Set<Arguments> refreshArgs() {
for (Core core : cores) {
args.add(Arguments.of(core, "/key/acl/refresh", "keys_acl"));
args.add(Arguments.of(core, "/key/refresh", "keys"));
}

return args;
}

public static Set<Arguments> refreshArgsEncrypted() {
Set<Core> cores = AppsMap.getApps(Core.class);
Set<Arguments> args = new HashSet<>();
for (Core core : cores) {
args.add(Arguments.of(core, "/key/keyset/refresh", "keysets"));
args.add(Arguments.of(core, "/key/keyset-keys/refresh", "keyset_keys"));
args.add(Arguments.of(core, "/clients/refresh", "client_keys"));
args.add(Arguments.of(core, "/sites/refresh", "sites"));
args.add(Arguments.of(core, "/client_side_keypairs/refresh", "client_side_keypairs"));
}

Expand Down
Loading