Skip to content

Commit a829112

Browse files
committed
More tests for V3 Identity Map
1 parent 4676497 commit a829112

File tree

5 files changed

+201
-93
lines changed

5 files changed

+201
-93
lines changed

src/test/java/app/component/Operator.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,15 +261,27 @@ public DecryptionResponse v2TokenDecrypt(String token) throws UID2ClientExceptio
261261
return dspClient.decrypt(token);
262262
}
263263

264+
// Need to use the manual mapping for error cases - SDK won't allow creating input with bad emails or disable optout check
264265
public JsonNode v2IdentityMap(String payload) throws Exception {
265266
V2Envelope envelope = v2CreateEnvelope(payload, getClientApiSecret());
266267
String encryptedResponse = HttpClient.post(getBaseUrl() + "/v2/identity/map", envelope.envelope(), getClientApiKey());
267268
return v2DecryptEncryptedResponse(encryptedResponse, envelope.nonce(), getClientApiSecret());
268269
}
269270

270-
public IdentityMapV3Response v3IdentityMap(List<String> emails, List<String> phones, List<String> emailHashes, List<String> phoneHashes) {
271+
public IdentityMapResponse v2IdentityMap(IdentityMapInput input) {
272+
IdentityMapClient identityMapClient = new IdentityMapClient(getBaseUrl(), CLIENT_API_KEY, CLIENT_API_SECRET);
273+
return identityMapClient.generateIdentityMap(input);
274+
}
275+
276+
// Need to use the manual mapping for error cases - SDK won't allow creating input with bad emails
277+
public JsonNode v3IdentityMap(String payload) throws Exception {
278+
V2Envelope envelope = v2CreateEnvelope(payload, getClientApiSecret());
279+
String encryptedResponse = HttpClient.post(getBaseUrl() + "/v3/identity/map", envelope.envelope(), getClientApiKey());
280+
return v2DecryptEncryptedResponse(encryptedResponse, envelope.nonce(), getClientApiSecret());
281+
}
282+
283+
public IdentityMapV3Response v3IdentityMap(IdentityMapV3Input input) {
271284
IdentityMapV3Client identityMapV3Client = new IdentityMapV3Client(getBaseUrl(), CLIENT_API_KEY, CLIENT_API_SECRET);
272-
IdentityMapV3Input input = new IdentityMapV3Input().withEmails(emails).withPhones(phones).withHashedEmails(emailHashes).withHashedPhones(phoneHashes);
273285
return identityMapV3Client.generateIdentityMap(input);
274286
}
275287

src/test/java/app/component/Validator.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
public class Validator extends App {
1010
private final PublisherUid2Helper publisherHelper;
11-
private final UID2Client dspClient;
1211
private final Headers standardHeaders;
1312
private final MediaType FORM = MediaType.get("application/x-www-form-urlencoded");;
1413

@@ -20,12 +19,6 @@ public Validator(String host, Integer port, String name, String clientApiKey, St
2019
.add("Authorization", "Bearer " + clientApiKey)
2120
.add("X-UID2-Client-Version: java-e2e-test")
2221
.build();
23-
24-
dspClient = new UID2Client(
25-
this.getBaseUrl(),
26-
clientApiKey,
27-
clientSecret,
28-
IdentityScope.UID2);
2922
}
3023

3124
public Response triggerGenerateTokenFromEmail(String email) throws IOException {

src/test/java/suite/operator/OperatorPublicOnlyTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import org.junit.jupiter.params.ParameterizedTest;
1010
import org.junit.jupiter.params.provider.MethodSource;
1111

12+
import java.util.List;
13+
1214
import static org.assertj.core.api.Assertions.assertThat;
1315
import static org.junit.jupiter.api.Assertions.*;
1416

@@ -81,6 +83,24 @@ public void testV2IdentityMapSpecialOptoutNoParam(String label, Operator operato
8183
assertThat(response.get("body").get("unmapped").get(0).get("reason").asText()).isEqualTo("optout");
8284
}
8385

86+
@ParameterizedTest(name = "/v3/identity/map - OPTOUT EMAIL, NO OPTOUT PARAM - {0} - {2} - Old Participant: {5}")
87+
@MethodSource({
88+
"suite.operator.TestData#tokenEmailArgsSpecialOptout",
89+
"suite.operator.TestData#tokenPhoneArgsSpecialOptout"
90+
})
91+
public void testV3IdentityMapSpecialOptout(String label, Operator operator, String operatorName, String type, String identity) throws Exception {
92+
if (isPrivateOperator(operator)) {
93+
return;
94+
}
95+
96+
// We need all properties to be there for Identity Map V3, so default all to empty
97+
// In JSON if a property appears multiple times, the last value wins
98+
String payload = "{\"email\":[], \"email_hash\":[], \"phone\":[], \"phone_hash\":[], \"" + type + "\": [\"" + identity + "\"]}";
99+
JsonNode response = operator.v3IdentityMap(payload);
100+
101+
assertThat(response.get("body").get(type).get(0).get("e").asText()).isEqualTo("optout");
102+
}
103+
84104
@EnabledIf("common.EnabledCondition#isLocal")
85105
@ParameterizedTest(name = "/v2/token/client-generate - {0} - {2}")
86106
@MethodSource({

src/test/java/suite/operator/OperatorTest.java

Lines changed: 48 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import java.time.Duration;
1414
import java.time.Instant;
1515
import java.util.List;
16-
import java.util.Objects;
1716

1817
import static org.assertj.core.api.Assertions.assertThat;
1918
import static org.junit.jupiter.api.Assertions.*;
@@ -99,62 +98,75 @@ public void testV2TokenValidate(String label, Operator operator, String operator
9998

10099
@ParameterizedTest(name = "/v2/identity/map - {0} - {2}")
101100
@MethodSource({
102-
"suite.operator.TestData#identityMapBatchEmailArgs",
103-
"suite.operator.TestData#identityMapBatchPhoneArgs",
104101
"suite.operator.TestData#identityMapBatchBadEmailArgs",
105102
"suite.operator.TestData#identityMapBatchBadPhoneArgs"
106103
})
107-
public void testV2IdentityMap(String label, Operator operator, String operatorName, String payload) throws Exception {
104+
public void testV2IdentityMapUnmapped(String label, Operator operator, String operatorName, String payload) throws Exception {
108105
JsonNode response = operator.v2IdentityMap(payload);
109106

110-
// TODO: Assert the value
111107
assertThat(response.at("/status").asText()).isEqualTo("success");
108+
assertThat(response.at("/body/unmapped/0/reason").asText()).isEqualTo("invalid identifier");
112109
}
113110

114111
@ParameterizedTest(name = "/v2/identity/map - {0} - {2}")
115112
@MethodSource({
116-
"suite.operator.TestData#identityMapBigBatchArgs"
113+
"suite.operator.TestData#identityMapBatchEmailArgs",
114+
"suite.operator.TestData#identityMapBatchPhoneArgs",
117115
})
118-
public void testV2IdentityMapLargeBatch(String label, Operator operator, String operatorName, String payload, List<String> diis) {
116+
public void testV2IdentityMapMapped(String label, Operator operator, String operatorName, String payload) throws Exception {
117+
JsonNode response = operator.v2IdentityMap(payload);
118+
119+
// TODO: Assert the value
120+
assertThat(response.at("/status").asText()).isEqualTo("success");
121+
}
122+
123+
@ParameterizedTest(name = "/v2/identity/map - {0} - {2}")
124+
@MethodSource({"suite.operator.TestData#identityMapArgs"})
125+
public void testV2IdentityMap(
126+
String label,
127+
Operator operator,
128+
String operatorName,
129+
IdentityMapInput input,
130+
List<String> diis
131+
) {
119132
assertTimeoutPreemptively(Duration.ofSeconds(5), () -> { // Validate we didn't make mapping too slow.
120-
JsonNode response = operator.v2IdentityMap(payload);
133+
var response = operator.v2IdentityMap(input);
121134

122-
assertThat(response.at("/status").asText()).isEqualTo("success");
135+
assertThat(response.isSuccess()).isTrue();
123136

124-
var mapped = response.at("/body/mapped");
125-
assertThat(mapped.size()).isEqualTo(10_000);
137+
assertThat(response.getUnmappedIdentities()).isEmpty();
126138

127-
for (int i = 0; i < 10_000; i++) {
128-
assertThat(mapped.get(i).get("identifier").asText()).isEqualTo(diis.get(i));
129-
assertThat(mapped.get(i).get("advertising_id").asText()).isNotNull().isNotEmpty();
130-
assertThat(mapped.get(i).get("bucket_id").asText()).isNotNull().isNotEmpty();
139+
var allMappedDiis = response.getMappedIdentities();
140+
assertThat(allMappedDiis.size()).isEqualTo(10_000);
141+
142+
for (var dii : diis) {
143+
var mappedDii = allMappedDiis.get(dii);
144+
assertThat(mappedDii).isNotNull();
145+
assertThat(mappedDii.getRawUid().length()).isEqualTo(RAW_UID_SIZE);
146+
assertThat(mappedDii.getBucketId()).isNotBlank();
131147
}
132148
});
133149
}
134150

135151
@ParameterizedTest(name = "/v3/identity/map - {0} - {2}")
136-
@MethodSource({
137-
"suite.operator.TestData#identityMapV3BigBatchArgs"
138-
})
152+
@MethodSource({"suite.operator.TestData#identityMapV3Args"})
139153
public void testV3IdentityMapLargeBatch(
140154
String label,
141155
Operator operator,
142156
String operatorName,
143-
List<String> emails,
144-
List<String> phones,
145-
List<String> emailHashes,
146-
List<String> phoneHashes,
157+
IdentityMapV3Input input,
147158
List<String> diis
148159
) {
149160
assertTimeoutPreemptively(Duration.ofSeconds(5), () -> { // Validate we didn't make mapping too slow.
150-
var response = operator.v3IdentityMap(emails, phones, emailHashes, phoneHashes);
161+
var response = operator.v3IdentityMap(input);
151162

152163
assertThat(response.isSuccess()).isTrue();
153164

165+
assertThat(response.getUnmappedIdentities()).isEmpty();
166+
154167
var allMappedDiis = response.getMappedIdentities();
155168
assertThat(allMappedDiis.size()).isEqualTo(10_000);
156169

157-
158170
for (var dii : diis) {
159171
var mappedDii = allMappedDiis.get(dii);
160172
assertThat(mappedDii).isNotNull();
@@ -176,6 +188,18 @@ public void testV3IdentityMapLargeBatch(
176188
});
177189
}
178190

191+
@ParameterizedTest(name = "/v3/identity/map - {0} - {2}")
192+
@MethodSource({
193+
"suite.operator.TestData#identityMapV3BatchBadEmailArgs",
194+
"suite.operator.TestData#identityMapV3BatchBadPhoneArgs"
195+
})
196+
public void testV3IdentityMapUnmapped(String label, Operator operator, String operatorName, String payload, String section) throws Exception {
197+
JsonNode response = operator.v3IdentityMap(payload);
198+
199+
assertThat(response.at("/status").asText()).isEqualTo("success");
200+
assertThat(response.at("/body/" + section + "/0/e").asText()).isEqualTo("invalid identifier");
201+
}
202+
179203

180204
@ParameterizedTest(name = "/v2/identity/map - VALIDATE EMAIL - {0} - {2}")
181205
@MethodSource({

0 commit comments

Comments
 (0)