Skip to content

Commit 4676497

Browse files
committed
V3 Identity Map test
1 parent 695c75b commit 4676497

File tree

9 files changed

+93
-17
lines changed

9 files changed

+93
-17
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
<dependency>
9191
<groupId>com.uid2</groupId>
9292
<artifactId>uid2-client</artifactId>
93-
<version>4.3.22</version>
93+
<version>4.6.8-alpha-29-SNAPSHOT</version>
9494
</dependency>
9595
<dependency>
9696
<groupId>org.assertj</groupId>

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.time.Clock;
2626
import java.time.Instant;
2727
import java.util.Base64;
28+
import java.util.List;
2829

2930
public class Operator extends App {
3031
public enum Type {
@@ -266,6 +267,12 @@ public JsonNode v2IdentityMap(String payload) throws Exception {
266267
return v2DecryptEncryptedResponse(encryptedResponse, envelope.nonce(), getClientApiSecret());
267268
}
268269

270+
public IdentityMapV3Response v3IdentityMap(List<String> emails, List<String> phones, List<String> emailHashes, List<String> phoneHashes) {
271+
IdentityMapV3Client identityMapV3Client = new IdentityMapV3Client(getBaseUrl(), CLIENT_API_KEY, CLIENT_API_SECRET);
272+
IdentityMapV3Input input = new IdentityMapV3Input().withEmails(emails).withPhones(phones).withHashedEmails(emailHashes).withHashedPhones(phoneHashes);
273+
return identityMapV3Client.generateIdentityMap(input);
274+
}
275+
269276
public JsonNode v2IdentityBuckets(String payload) throws Exception {
270277
V2Envelope envelope = v2CreateEnvelope(payload, CLIENT_API_SECRET);
271278
String encryptedResponse = HttpClient.post(getBaseUrl() + "/v2/identity/buckets", envelope.envelope(), CLIENT_API_KEY);

src/test/java/suite/E2ELocalFullTestSuite.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
BasicTest.class,
1515
CoreTest.class,
1616
CoreRefreshTest.class,
17-
V2ApiOperatorTest.class,
18-
V2ApiOperatorPublicOnlyTest.class,
19-
V2ApiOperatorLocalOnlyTest.class,
17+
OperatorTest.class,
18+
OperatorPublicOnlyTest.class,
19+
OperatorLocalOnlyTest.class,
2020
OptoutTest.class,
2121
V2ApiValidatorTest.class
2222
})

src/test/java/suite/E2EPrivateOperatorTestSuite.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
import org.junit.platform.suite.api.SelectClasses;
44
import org.junit.platform.suite.api.Suite;
55
import suite.basic.BasicTest;
6-
import suite.operator.V2ApiOperatorTest;
6+
import suite.operator.OperatorTest;
77

88
@Suite
99
@SelectClasses({
1010
BasicTest.class,
11-
V2ApiOperatorTest.class
11+
OperatorTest.class
1212
})
1313
public class E2EPrivateOperatorTestSuite {
1414
}

src/test/java/suite/E2EPublicOperatorTestSuite.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
BasicTest.class,
1414
CoreTest.class,
1515
CoreRefreshTest.class,
16-
V2ApiOperatorTest.class,
17-
V2ApiOperatorPublicOnlyTest.class,
18-
V2ApiOperatorLocalOnlyTest.class,
16+
OperatorTest.class,
17+
OperatorPublicOnlyTest.class,
18+
OperatorLocalOnlyTest.class,
1919
OptoutTest.class
2020
})
2121
public class E2EPublicOperatorTestSuite {

src/test/java/suite/operator/V2ApiOperatorLocalOnlyTest.java renamed to src/test/java/suite/operator/OperatorLocalOnlyTest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
import app.component.App;
44
import app.component.Operator;
55
import com.uid2.client.*;
6-
import common.Const;
7-
import common.EnvUtil;
86
import org.junit.jupiter.api.condition.EnabledIf;
97
import org.junit.jupiter.params.ParameterizedTest;
108
import org.junit.jupiter.params.provider.MethodSource;
@@ -18,7 +16,7 @@
1816
import static org.junit.jupiter.api.Assertions.assertTrue;
1917

2018
@EnabledIf("common.EnabledCondition#isLocal")
21-
public class V2ApiOperatorLocalOnlyTest {
19+
public class OperatorLocalOnlyTest {
2220
@ParameterizedTest(name = "{index} ==> Sender {0} encrypts with {1}, recipient {2} decrypts with {3}, expected result is {4}")
2321
@MethodSource({
2422
"suite.operator.TestData#sharingArgs",

src/test/java/suite/operator/V2ApiOperatorPublicOnlyTest.java renamed to src/test/java/suite/operator/OperatorPublicOnlyTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import static org.junit.jupiter.api.Assertions.*;
1414

1515
@SuppressWarnings("unused")
16-
public class V2ApiOperatorPublicOnlyTest {
16+
public class OperatorPublicOnlyTest {
1717
private static final String EMAIL_OPTOUT_ID = "[email protected]";
1818
private static final String PHONE_OPTOUT_ID = "+00000000001";
1919

src/test/java/suite/operator/V2ApiOperatorTest.java renamed to src/test/java/suite/operator/OperatorTest.java

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@
1111
import org.junit.jupiter.params.provider.MethodSource;
1212

1313
import java.time.Duration;
14+
import java.time.Instant;
1415
import java.util.List;
16+
import java.util.Objects;
1517

1618
import static org.assertj.core.api.Assertions.assertThat;
1719
import static org.junit.jupiter.api.Assertions.*;
1820

1921
@SuppressWarnings("unused")
20-
public class V2ApiOperatorTest {
22+
public class OperatorTest {
2123
/*
2224
TODO:
2325
/v2/token/generate - Add failure case
@@ -31,6 +33,7 @@ public class V2ApiOperatorTest {
3133

3234
private static final ObjectMapper OBJECT_MAPPER = Mapper.getInstance();
3335
private static final String CLIENT_SITE_ID = EnvUtil.getEnv(Const.Config.Operator.CLIENT_SITE_ID);
36+
private static final int RAW_UID_SIZE = 44;
3437

3538
@ParameterizedTest(name = "/v2/token/generate - {0} - {2}")
3639
@MethodSource({
@@ -113,7 +116,7 @@ public void testV2IdentityMap(String label, Operator operator, String operatorNa
113116
"suite.operator.TestData#identityMapBigBatchArgs"
114117
})
115118
public void testV2IdentityMapLargeBatch(String label, Operator operator, String operatorName, String payload, List<String> diis) {
116-
assertTimeoutPreemptively(Duration.ofSeconds(5), () -> { // Validate we didn't make mapping too slow.
119+
assertTimeoutPreemptively(Duration.ofSeconds(5), () -> { // Validate we didn't make mapping too slow.
117120
JsonNode response = operator.v2IdentityMap(payload);
118121

119122
assertThat(response.at("/status").asText()).isEqualTo("success");
@@ -129,6 +132,50 @@ public void testV2IdentityMapLargeBatch(String label, Operator operator, String
129132
});
130133
}
131134

135+
@ParameterizedTest(name = "/v3/identity/map - {0} - {2}")
136+
@MethodSource({
137+
"suite.operator.TestData#identityMapV3BigBatchArgs"
138+
})
139+
public void testV3IdentityMapLargeBatch(
140+
String label,
141+
Operator operator,
142+
String operatorName,
143+
List<String> emails,
144+
List<String> phones,
145+
List<String> emailHashes,
146+
List<String> phoneHashes,
147+
List<String> diis
148+
) {
149+
assertTimeoutPreemptively(Duration.ofSeconds(5), () -> { // Validate we didn't make mapping too slow.
150+
var response = operator.v3IdentityMap(emails, phones, emailHashes, phoneHashes);
151+
152+
assertThat(response.isSuccess()).isTrue();
153+
154+
var allMappedDiis = response.getMappedIdentities();
155+
assertThat(allMappedDiis.size()).isEqualTo(10_000);
156+
157+
158+
for (var dii : diis) {
159+
var mappedDii = allMappedDiis.get(dii);
160+
assertThat(mappedDii).isNotNull();
161+
162+
// Current UID should always be there and should have correct length
163+
assertThat(mappedDii.getCurrentRawUid().length()).isEqualTo(RAW_UID_SIZE);
164+
165+
// Previous UID is there for 90 days after rotation only, then it's null.
166+
// If it's there, it should have the correct size
167+
assertThat(mappedDii.getPreviousRawUid()).satisfiesAnyOf(
168+
uid -> assertThat(uid).isNull(),
169+
uid -> assertThat(uid).hasSize(RAW_UID_SIZE)
170+
);
171+
172+
// Sanity check that refresh from is a date not too far in the past.
173+
// If it is, either there is an Operator issue or salt rotation hasn't been running for a long time.
174+
assertThat(mappedDii.getRefreshFrom()).isAfter(Instant.now().minus(Duration.ofDays(10)));
175+
}
176+
});
177+
}
178+
132179

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

src/test/java/suite/operator/TestData.java

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ public static Set<Arguments> tokenPhoneArgsSpecialOptout() {
103103
Set<Arguments> args = new HashSet<>();
104104
if (App.PHONE_SUPPORT) {
105105
for (Operator operator : operators) {
106-
args.add(Arguments.of("optout special phone", operator, operator.getName(), "phone", "+00000000000", true));
107-
args.add(Arguments.of("optout special phone", operator, operator.getName(), "phone", "+00000000000", false));
106+
args.add(Arguments.of("optout special phone", operator, operator.getName(), "phone", "+00000000000", true));
107+
args.add(Arguments.of("optout special phone", operator, operator.getName(), "phone", "+00000000000", false));
108108
}
109109
}
110110
return args;
@@ -356,6 +356,30 @@ public static Set<Arguments> identityMapBigBatchArgs() throws JsonProcessingExce
356356
return args;
357357
}
358358

359+
public static Set<Arguments> identityMapV3BigBatchArgs() {
360+
Set<Operator> operators = AppsMap.getApps(Operator.class);
361+
362+
List<String> emails = new ArrayList<>();
363+
List<String> phones = new ArrayList<>();
364+
List<String> emailHashes = new ArrayList<>();
365+
List<String> phoneHashes = new ArrayList<>();
366+
for (int i = 0; i < 10_000; i++) {
367+
emails.add(randomEmail());
368+
phones.add(randomPhoneNumber());
369+
emailHashes.add(randomHash());
370+
phoneHashes.add(randomHash());
371+
}
372+
373+
Set<Arguments> args = new HashSet<>();
374+
for (Operator operator : operators) {
375+
args.add(Arguments.of("10k emails", operator, operator.getName(), emails, List.of(), List.of(), List.of(), emails));
376+
args.add(Arguments.of("10k phones", operator, operator.getName(), List.of(), phones, List.of(), List.of(), phones));
377+
args.add(Arguments.of("10k email hashes", operator, operator.getName(), List.of(), List.of(), emailHashes, List.of(), emailHashes));
378+
args.add(Arguments.of("10k phone hashes", operator, operator.getName(), List.of(), List.of(), List.of(), phoneHashes, phoneHashes));
379+
}
380+
return args;
381+
}
382+
359383
private static String identityMapPayload(ObjectMapper mapper, String field, List<String> diis) throws JsonProcessingException {
360384
var json = mapper.createObjectNode().putPOJO(field, diis).put("policy", 1);
361385
return mapper.writeValueAsString(json);

0 commit comments

Comments
 (0)