-
Notifications
You must be signed in to change notification settings - Fork 0
Batch email test for identity map #104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,20 +3,20 @@ | |
| import app.AppsMap; | ||
| import app.component.App; | ||
| import app.component.Operator; | ||
| import com.fasterxml.jackson.core.JsonProcessingException; | ||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import com.uid2.client.DecryptionStatus; | ||
| import org.junit.jupiter.params.provider.Arguments; | ||
|
|
||
| import java.util.HashSet; | ||
| import java.util.List; | ||
| import java.util.Optional; | ||
| import java.util.Set; | ||
| import java.util.*; | ||
| import java.util.stream.Collectors; | ||
| import java.util.stream.Stream; | ||
|
|
||
| import static org.junit.jupiter.api.Named.named; | ||
|
|
||
| public final class TestData { | ||
| public static final int RAW_UID2_LENGTH = 44; | ||
| private static final Random RANDOM = new Random(); | ||
|
|
||
| private TestData() { | ||
| } | ||
|
|
@@ -326,6 +326,57 @@ public static Set<Arguments> identityMapBatchEmailArgs() { | |
| return args; | ||
| } | ||
|
|
||
| public static Set<Arguments> identityMapBigBatchArgs() throws JsonProcessingException { | ||
| ObjectMapper mapper = new ObjectMapper(); | ||
| Set<Operator> operators = AppsMap.getApps(Operator.class); | ||
|
|
||
| List<String> emails = new ArrayList<>(); | ||
| List<String> phones = new ArrayList<>(); | ||
| List<String> emailHashes = new ArrayList<>(); | ||
| List<String> phoneHashes = new ArrayList<>(); | ||
| for (int i = 0; i < 10_000; i++) { | ||
| emails.add(random_email()); | ||
| phones.add(randomPhoneNumber()); | ||
| emailHashes.add(randomHash()); | ||
| phoneHashes.add(randomHash()); | ||
| } | ||
|
|
||
| var emailsPayload = identityMapPayload(mapper, "email", emails); | ||
| var phonesPayload = identityMapPayload(mapper, "phone", phones); | ||
| var emailHashesPayload = identityMapPayload(mapper, "email_hash", emailHashes); | ||
| var phoneHashesPayload = identityMapPayload(mapper, "phone_hash", phoneHashes); | ||
|
|
||
| Set<Arguments> args = new HashSet<>(); | ||
| for (Operator operator : operators) { | ||
| args.add(Arguments.of("10k emails", operator, operator.getName(), emailsPayload, emails)); | ||
| args.add(Arguments.of("10k phones", operator, operator.getName(), phonesPayload, phones)); | ||
| args.add(Arguments.of("10k email hashes", operator, operator.getName(), emailHashesPayload, emailHashes)); | ||
| args.add(Arguments.of("10k phone hashes", operator, operator.getName(), phoneHashesPayload, phoneHashes)); | ||
| } | ||
| return args; | ||
| } | ||
|
|
||
| private static String identityMapPayload(ObjectMapper mapper, String field, List<String> diis) throws JsonProcessingException { | ||
| var json = mapper.createObjectNode().putPOJO(field, diis).put("policy", 1); | ||
| return mapper.writeValueAsString(json); | ||
| } | ||
|
|
||
| private static String random_email() { | ||
| return "email_" + Math.abs(RANDOM.nextLong()) + "@example.com"; | ||
| } | ||
|
|
||
| private static String randomPhoneNumber() { | ||
| // Phone numbers with 15 digits are technically valid but are not used in any country | ||
| return "+" + String.format("%015d", Math.abs(RANDOM.nextLong() % 1_000_000_000_000_000L)); | ||
| } | ||
|
|
||
| private static String randomHash() { | ||
| // This isn't really a hashed DII but looks like one ot UID2 | ||
| byte[] randomBytes = new byte[32]; | ||
| RANDOM.nextBytes(randomBytes); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would this result in an invalid mapping or would it return some UID2 in the response?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be some UID2. We don't check, and cannot possibly check, whether the hash maps back to any valid DII. From our perspective, it's just a certain amount of bytes. |
||
| return Base64.getEncoder().encodeToString(randomBytes); | ||
| } | ||
|
|
||
| public static Set<Arguments> identityMapBatchEmailArgsBadPolicy() { | ||
| Set<Operator> operators = getPublicOperators(); | ||
| Set<List<String>> inputs = Set.of( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,9 @@ | |
| import org.junit.jupiter.params.ParameterizedTest; | ||
| import org.junit.jupiter.params.provider.MethodSource; | ||
|
|
||
| import java.time.Duration; | ||
| import java.util.List; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.junit.jupiter.api.Assertions.*; | ||
|
|
||
|
|
@@ -105,6 +108,28 @@ public void testV2IdentityMap(String label, Operator operator, String operatorNa | |
| assertThat(response.at("/status").asText()).isEqualTo("success"); | ||
| } | ||
|
|
||
| @ParameterizedTest(name = "/v2/identity/map - {0} - {2}") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to be clear, did we only want to test v2 identity map here and not v3?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We want both, but we don't have Identity Map V3 SDK yet. It's not merged, and the tests go via the SDK. I'll add the v3 test when we have the SDK merged. |
||
| @MethodSource({ | ||
| "suite.operator.TestData#identityMapBigBatchArgs" | ||
| }) | ||
| public void testV2IdentityMapLargeBatch(String label, Operator operator, String operatorName, String payload, List<String> diis) { | ||
| assertTimeoutPreemptively(Duration.ofSeconds(5), () -> { // Validate we didn't make mapping too slow. | ||
| JsonNode response = operator.v2IdentityMap(payload); | ||
|
|
||
| assertThat(response.at("/status").asText()).isEqualTo("success"); | ||
|
|
||
| var mapped = response.at("/body/mapped"); | ||
| assertThat(mapped.size()).isEqualTo(10_000); | ||
|
|
||
| for (int i = 0; i < 10_000; i++) { | ||
| assertThat(mapped.get(i).get("identifier").asText()).isEqualTo(diis.get(i)); | ||
| assertThat(mapped.get(i).get("advertising_id").asText()).isNotNull().isNotEmpty(); | ||
| assertThat(mapped.get(i).get("bucket_id").asText()).isNotNull().isNotEmpty(); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
|
|
||
| @ParameterizedTest(name = "/v2/identity/map - VALIDATE EMAIL - {0} - {2}") | ||
| @MethodSource({ | ||
| "suite.operator.TestData#tokenValidateEmailArgs", | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.