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 @@ -12,7 +12,7 @@
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<vertx.version>4.5.13</vertx.version>
<uid2-shared.version>8.1.25</uid2-shared.version>
<uid2-shared.version>9.1.0</uid2-shared.version>
</properties>

<repositories>
Expand Down
10 changes: 6 additions & 4 deletions src/test/java/app/component/Core.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package app.component;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.uid2.shared.util.Mapper;
import common.Const;
import common.EnvUtil;
import common.HttpClient;
import common.Mapper;
import com.fasterxml.jackson.databind.JsonNode;

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

public class Core extends App {
private static final ObjectMapper OBJECT_MAPPER = Mapper.getInstance();
private static final String OPERATOR_API_KEY = EnvUtil.getEnv(Const.Config.Core.OPERATOR_API_KEY);
private static final String OPTOUT_API_KEY = EnvUtil.getEnv(Const.Config.Core.OPTOUT_API_KEY);
public static final String CORE_URL = EnvUtil.getEnv(Const.Config.Core.CORE_URL);
Expand All @@ -25,7 +27,7 @@ public Core(String host, String name) {

public JsonNode attest(String attestationRequest) throws Exception {
String response = HttpClient.post(getBaseUrl() + "/attest", attestationRequest, OPERATOR_API_KEY);
return Mapper.OBJECT_MAPPER.readTree(response);
return OBJECT_MAPPER.readTree(response);
}

public JsonNode getWithCoreApiToken(String path) throws Exception {
Expand All @@ -37,11 +39,11 @@ public JsonNode getWithCoreApiToken(String path, boolean encrypted) throws Excep
if (encrypted)
headers.put("Encrypted", "true");
String response = HttpClient.get(getBaseUrl() + path, OPERATOR_API_KEY, headers);
return Mapper.OBJECT_MAPPER.readTree(response);
return OBJECT_MAPPER.readTree(response);
}

public JsonNode getWithOptOutApiToken(String path) throws Exception {
String response = HttpClient.get(getBaseUrl() + path, OPTOUT_API_KEY);
return Mapper.OBJECT_MAPPER.readTree(response);
return OBJECT_MAPPER.readTree(response);
}
}
7 changes: 5 additions & 2 deletions src/test/java/app/component/Operator.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package app.component;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.uid2.client.IdentityScope;
import com.uid2.client.*;
import com.uid2.shared.util.Mapper;
import common.*;
import lombok.Getter;
import okhttp3.Request;
Expand Down Expand Up @@ -66,6 +68,7 @@ private record V2Envelope(String envelope, byte[] nonce) {
// When running via IntelliJ, environment variables are defined in the uid2-dev-workspace repo under .idea/runConfigurations.
// Test data is defined in the uid2-admin repo.

private static final ObjectMapper OBJECT_MAPPER = Mapper.getInstance();
private static final SecureRandom SECURE_RANDOM = new SecureRandom();
private static final int TIMESTAMP_LENGTH = 8;
private static final int PUBLIC_KEY_PREFIX_LENGTH = 9;
Expand Down Expand Up @@ -340,14 +343,14 @@ private JsonNode v2DecryptEncryptedResponse(String encryptedResponse, byte[] non
cons.setAccessible(true);
Uid2Helper uid2Helper = cons.newInstance(secret);
String decryptedResponse = uid2Helper.decrypt(encryptedResponse, nonceInRequest);
return Mapper.OBJECT_MAPPER.readTree(decryptedResponse);
return OBJECT_MAPPER.readTree(decryptedResponse);
}

private JsonNode v2DecryptResponseWithoutNonce(String response, byte[] key) throws Exception {
Method decryptTokenRefreshResponseMethod = Uid2Helper.class.getDeclaredMethod("decryptTokenRefreshResponse", String.class, byte[].class);
decryptTokenRefreshResponseMethod.setAccessible(true);
String decryptedResponse = (String) decryptTokenRefreshResponseMethod.invoke(Uid2Helper.class, response, key);
return Mapper.OBJECT_MAPPER.readTree(decryptedResponse);
return OBJECT_MAPPER.readTree(decryptedResponse);
}

private byte[] encryptGDM(byte[] b, byte[] secretBytes) throws Exception {
Expand Down
5 changes: 4 additions & 1 deletion src/test/java/common/EnvUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.uid2.shared.util.Mapper;
import org.apache.commons.lang3.StringUtils;
import org.junit.platform.commons.logging.Logger;
import org.junit.platform.commons.logging.LoggerFactory;
Expand All @@ -11,6 +13,7 @@

public final class EnvUtil {
private static final Logger LOGGER = LoggerFactory.getLogger(EnvUtil.class);
private static final ObjectMapper OBJECT_MAPPER = Mapper.getInstance();
private static final Map<String, String> ARGS = new HashMap<>();

static {
Expand All @@ -20,7 +23,7 @@ public final class EnvUtil {
if (StringUtils.isNotBlank(args)) {
TypeReference<HashMap<String, String>> typeRef = new TypeReference<>() {
};
ARGS.putAll(Mapper.OBJECT_MAPPER.readValue(args, typeRef));
ARGS.putAll(OBJECT_MAPPER.readValue(args, typeRef));
}
} catch (JsonProcessingException e) {
LOGGER.error(e::getMessage);
Expand Down
28 changes: 7 additions & 21 deletions src/test/java/common/HttpClient.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package common;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.uid2.shared.util.Mapper;
import lombok.Getter;
import okhttp3.*;

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

public final class HttpClient {
private static final ObjectMapper OBJECT_MAPPER = Mapper.getInstance();

public static final OkHttpClient RAW_CLIENT = new OkHttpClient();
public static final MediaType JSON = MediaType.get("application/json; charset=utf-8");

Expand All @@ -15,6 +20,7 @@ public enum HttpMethod {
POST
}

@Getter
public static class HttpException extends Exception {
private final HttpMethod method;
private final String url;
Expand All @@ -32,28 +38,8 @@ public HttpException(HttpMethod method, String url, int code, String codeMessage
this.response = response;
}

public HttpMethod getMethod() {
return method;
}

public String getUrl() {
return url;
}

public int getCode() {
return code;
}

public String getCodeMessage() {
return codeMessage;
}

public String getResponse() {
return response;
}

public JsonNode getResponseJson() throws Exception {
return Mapper.OBJECT_MAPPER.readTree(response);
return OBJECT_MAPPER.readTree(response);
}

private static String createErrorMessage(HttpMethod method, String url, int code, String message, String response) {
Expand Down
10 changes: 0 additions & 10 deletions src/test/java/common/Mapper.java

This file was deleted.

3 changes: 0 additions & 3 deletions src/test/java/suite/operator/V2ApiOperatorPublicOnlyTest.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package suite.operator;

import common.HttpClient;
import common.Mapper;
import app.component.Operator;
import com.fasterxml.jackson.databind.JsonNode;
import com.uid2.client.DecryptionResponse;
import com.uid2.client.IdentityTokens;
import com.uid2.client.TokenRefreshResponse;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.condition.EnabledIf;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
Expand Down
6 changes: 4 additions & 2 deletions src/test/java/suite/operator/V2ApiOperatorTest.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package suite.operator;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.uid2.shared.util.Mapper;
import common.Const;
import common.EnvUtil;
import common.Mapper;
import app.component.Operator;
import com.fasterxml.jackson.databind.JsonNode;
import com.uid2.client.*;
Expand All @@ -25,6 +26,7 @@ public class V2ApiOperatorTest {
// The advertiser token will be different on every call due to randomness used in encryption,
// so we can't assert on it

private static final ObjectMapper OBJECT_MAPPER = Mapper.getInstance();
private static final String CLIENT_SITE_ID = EnvUtil.getEnv(Const.Config.Operator.CLIENT_SITE_ID);

@ParameterizedTest(name = "/v2/token/generate - {0} - {2}")
Expand Down Expand Up @@ -86,7 +88,7 @@ public void testV2TokenValidate(String label, Operator operator, String operator
String advertisingToken = currentIdentity.getAdvertisingToken();
JsonNode response = operator.v2TokenValidate(type, identity, advertisingToken);

assertThat(response).isEqualTo(Mapper.OBJECT_MAPPER.readTree("{\"body\":true,\"status\":\"success\"}"));
assertThat(response).isEqualTo(OBJECT_MAPPER.readTree("{\"body\":true,\"status\":\"success\"}"));
}

@ParameterizedTest(name = "/v2/identity/map - {0} - {2}")
Expand Down
18 changes: 10 additions & 8 deletions src/test/java/suite/optout/OptoutTest.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package suite.optout;

import common.Mapper;
import app.component.Operator;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.uid2.client.IdentityTokens;
import com.uid2.shared.util.Mapper;
import org.junit.jupiter.api.*;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
Expand All @@ -24,6 +25,7 @@
public class OptoutTest {
// TODO: Test failure case

private static final ObjectMapper OBJECT_MAPPER = Mapper.getInstance();
private static final int OPTOUT_DELAY_MS = 1000;
private static final int OPTOUT_WAIT_SECONDS = 300;

Expand All @@ -46,14 +48,14 @@ public void testV2LogoutWithV2TokenGenerate(String label, Operator operator, Str
IdentityTokens generateResponse = operator.v2TokenGenerate(type, identity, false).getIdentity();
Thread.sleep(OPTOUT_DELAY_MS);
JsonNode logoutResponse = operator.v2TokenLogout(type, identity);
assertThat(logoutResponse).isEqualTo(Mapper.OBJECT_MAPPER.readTree("{\"body\":{\"optout\":\"OK\"},\"status\":\"success\"}"));
assertThat(logoutResponse).isEqualTo(OBJECT_MAPPER.readTree("{\"body\":{\"optout\":\"OK\"},\"status\":\"success\"}"));
addToken(
label,
operator,
"v2",
"v2",
generateResponse.getRefreshToken(),
Mapper.OBJECT_MAPPER.readTree(generateResponse.getJsonString()).at("/refresh_response_key").asText()
OBJECT_MAPPER.readTree(generateResponse.getJsonString()).at("/refresh_response_key").asText()
);
}

Expand All @@ -67,14 +69,14 @@ public void testV2LogoutWithV2TokenGenerateOldParticipant(String label, Operator
IdentityTokens generateResponse = operator.v2TokenGenerate(type, identity, true).getIdentity();
Thread.sleep(OPTOUT_DELAY_MS);
JsonNode logoutResponse = operator.v2TokenLogout(type, identity);
assertThat(logoutResponse).isEqualTo(Mapper.OBJECT_MAPPER.readTree("{\"body\":{\"optout\":\"OK\"},\"status\":\"success\"}"));
assertThat(logoutResponse).isEqualTo(OBJECT_MAPPER.readTree("{\"body\":{\"optout\":\"OK\"},\"status\":\"success\"}"));
addToken(
"old participant " + label,
operator,
"v2",
"v2",
generateResponse.getRefreshToken(),
Mapper.OBJECT_MAPPER.readTree(generateResponse.getJsonString()).at("/refresh_response_key").asText()
OBJECT_MAPPER.readTree(generateResponse.getJsonString()).at("/refresh_response_key").asText()
);
}

Expand All @@ -92,7 +94,7 @@ public void testV2LogoutWithV2IdentityMap(String label, Operator operator, Strin
if (toOptOut) {
Thread.sleep(OPTOUT_DELAY_MS);
JsonNode logoutResponse = operator.v2TokenLogout(type, emailOrPhone);
assertThat(logoutResponse).isEqualTo(Mapper.OBJECT_MAPPER.readTree("{\"body\":{\"optout\":\"OK\"},\"status\":\"success\"}"));
assertThat(logoutResponse).isEqualTo(OBJECT_MAPPER.readTree("{\"body\":{\"optout\":\"OK\"},\"status\":\"success\"}"));
}
outputAdvertisingIdArgs.add(Arguments.of(label, operator, operatorName, rawUID, toOptOut, beforeOptOutTimestamp));
}
Expand All @@ -105,7 +107,7 @@ public void testV2LogoutWithV2IdentityMap(String label, Operator operator, Strin
public void testV2TokenRefreshAfterOptOut(String label, Operator operator, String tokenGenerateVersion, String tokenLogoutVersion, String refreshToken, String refreshResponseKey) throws Exception {
assumeThat(tokenGenerateVersion).isEqualTo("v2");

with().pollInterval(5, TimeUnit.SECONDS).await("Get V2 Token Response").atMost(OPTOUT_WAIT_SECONDS, TimeUnit.SECONDS).until(() -> operator.v2TokenRefresh(refreshToken, refreshResponseKey).equals(Mapper.OBJECT_MAPPER.readTree("{\"status\":\"optout\"}")));
with().pollInterval(5, TimeUnit.SECONDS).await("Get V2 Token Response").atMost(OPTOUT_WAIT_SECONDS, TimeUnit.SECONDS).until(() -> operator.v2TokenRefresh(refreshToken, refreshResponseKey).equals(OBJECT_MAPPER.readTree("{\"status\":\"optout\"}")));
}

@Order(5)
Expand Down Expand Up @@ -164,7 +166,7 @@ private void addToken(String label, Operator operator, String tokenGenerateVersi
private void waitForOptOutResponse(Function<String, JsonNode> tokenRefreshFunction, String refreshToken, String expectedResponse) {
with().pollInterval(5, TimeUnit.SECONDS).await("Get Token Response").atMost(OPTOUT_WAIT_SECONDS, TimeUnit.SECONDS).until(() -> {
JsonNode response = tokenRefreshFunction.apply(refreshToken);
return response.equals(Mapper.OBJECT_MAPPER.readTree(expectedResponse));
return response.equals(OBJECT_MAPPER.readTree(expectedResponse));
});
}
}