-
Notifications
You must be signed in to change notification settings - Fork 0
V3 Identity Map test #106
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
base: main
Are you sure you want to change the base?
V3 Identity Map test #106
Changes from all 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 |
---|---|---|
|
@@ -9,11 +9,13 @@ | |
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
|
||
import java.util.List; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
@SuppressWarnings("unused") | ||
public class V2ApiOperatorPublicOnlyTest { | ||
public class OperatorPublicOnlyTest { | ||
private static final String EMAIL_OPTOUT_ID = "optout@unifiedid.com"; | ||
private static final String PHONE_OPTOUT_ID = "+00000000001"; | ||
|
||
|
@@ -81,6 +83,24 @@ public void testV2IdentityMapSpecialOptoutNoParam(String label, Operator operato | |
assertThat(response.get("body").get("unmapped").get(0).get("reason").asText()).isEqualTo("optout"); | ||
} | ||
|
||
@ParameterizedTest(name = "/v3/identity/map - OPTOUT EMAIL, NO OPTOUT PARAM - {0} - {2} - Old Participant: {5}") | ||
@MethodSource({ | ||
"suite.operator.TestData#tokenEmailArgsSpecialOptout", | ||
"suite.operator.TestData#tokenPhoneArgsSpecialOptout" | ||
}) | ||
public void testV3IdentityMapSpecialOptout(String label, Operator operator, String operatorName, String type, String identity) throws Exception { | ||
if (isPrivateOperator(operator)) { | ||
return; | ||
} | ||
|
||
// We need all properties to be there for Identity Map V3, so default all to empty | ||
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 don't need all properties to be present |
||
// In JSON if a property appears multiple times, the last value wins | ||
String payload = "{\"email\":[], \"email_hash\":[], \"phone\":[], \"phone_hash\":[], \"" + type + "\": [\"" + identity + "\"]}"; | ||
JsonNode response = operator.v3IdentityMap(payload); | ||
|
||
assertThat(response.get("body").get(type).get(0).get("e").asText()).isEqualTo("optout"); | ||
} | ||
|
||
@EnabledIf("common.EnabledCondition#isLocal") | ||
@ParameterizedTest(name = "/v2/token/client-generate - {0} - {2}") | ||
@MethodSource({ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,13 +11,14 @@ | |
import org.junit.jupiter.params.provider.MethodSource; | ||
|
||
import java.time.Duration; | ||
import java.time.Instant; | ||
import java.util.List; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
@SuppressWarnings("unused") | ||
public class V2ApiOperatorTest { | ||
public class OperatorTest { | ||
/* | ||
TODO: | ||
/v2/token/generate - Add failure case | ||
|
@@ -31,6 +32,7 @@ public class V2ApiOperatorTest { | |
|
||
private static final ObjectMapper OBJECT_MAPPER = Mapper.getInstance(); | ||
private static final String CLIENT_SITE_ID = EnvUtil.getEnv(Const.Config.Operator.CLIENT_SITE_ID); | ||
private static final int RAW_UID_SIZE = 44; | ||
|
||
@ParameterizedTest(name = "/v2/token/generate - {0} - {2}") | ||
@MethodSource({ | ||
|
@@ -96,39 +98,108 @@ public void testV2TokenValidate(String label, Operator operator, String operator | |
|
||
@ParameterizedTest(name = "/v2/identity/map - {0} - {2}") | ||
@MethodSource({ | ||
"suite.operator.TestData#identityMapBatchEmailArgs", | ||
"suite.operator.TestData#identityMapBatchPhoneArgs", | ||
"suite.operator.TestData#identityMapBatchBadEmailArgs", | ||
"suite.operator.TestData#identityMapBatchBadPhoneArgs" | ||
}) | ||
public void testV2IdentityMap(String label, Operator operator, String operatorName, String payload) throws Exception { | ||
public void testV2IdentityMapUnmapped(String label, Operator operator, String operatorName, String payload) throws Exception { | ||
JsonNode response = operator.v2IdentityMap(payload); | ||
|
||
// TODO: Assert the value | ||
assertThat(response.at("/status").asText()).isEqualTo("success"); | ||
assertThat(response.at("/body/unmapped/0/reason").asText()).isEqualTo("invalid identifier"); | ||
} | ||
|
||
@ParameterizedTest(name = "/v2/identity/map - {0} - {2}") | ||
@MethodSource({ | ||
"suite.operator.TestData#identityMapBigBatchArgs" | ||
"suite.operator.TestData#identityMapBatchEmailArgs", | ||
"suite.operator.TestData#identityMapBatchPhoneArgs", | ||
}) | ||
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); | ||
public void testV2IdentityMapMapped(String label, Operator operator, String operatorName, String payload) throws Exception { | ||
JsonNode response = operator.v2IdentityMap(payload); | ||
|
||
assertThat(response.at("/status").asText()).isEqualTo("success"); | ||
// TODO: Assert the value | ||
assertThat(response.at("/status").asText()).isEqualTo("success"); | ||
} | ||
|
||
var mapped = response.at("/body/mapped"); | ||
assertThat(mapped.size()).isEqualTo(10_000); | ||
@ParameterizedTest(name = "/v2/identity/map - {0} - {2}") | ||
@MethodSource({"suite.operator.TestData#identityMapArgs"}) | ||
public void testV2IdentityMap( | ||
String label, | ||
Operator operator, | ||
String operatorName, | ||
IdentityMapInput input, | ||
List<String> diis | ||
) { | ||
assertTimeoutPreemptively(Duration.ofSeconds(5), () -> { // Validate we didn't make mapping too slow. | ||
var response = operator.v2IdentityMap(input); | ||
|
||
assertThat(response.isSuccess()).isTrue(); | ||
|
||
assertThat(response.getUnmappedIdentities()).isEmpty(); | ||
|
||
var allMappedDiis = response.getMappedIdentities(); | ||
assertThat(allMappedDiis.size()).isEqualTo(10_000); | ||
|
||
for (var dii : diis) { | ||
var mappedDii = allMappedDiis.get(dii); | ||
assertThat(mappedDii).isNotNull(); | ||
assertThat(mappedDii.getRawUid().length()).isEqualTo(RAW_UID_SIZE); | ||
assertThat(mappedDii.getBucketId()).isNotBlank(); | ||
} | ||
}); | ||
} | ||
|
||
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 = "/v3/identity/map - {0} - {2}") | ||
@MethodSource({"suite.operator.TestData#identityMapV3Args"}) | ||
public void testV3IdentityMapLargeBatch( | ||
String label, | ||
Operator operator, | ||
String operatorName, | ||
IdentityMapV3Input input, | ||
List<String> diis | ||
) { | ||
assertTimeoutPreemptively(Duration.ofSeconds(5), () -> { // Validate we didn't make mapping too slow. | ||
var response = operator.v3IdentityMap(input); | ||
|
||
assertThat(response.isSuccess()).isTrue(); | ||
|
||
assertThat(response.getUnmappedIdentities()).isEmpty(); | ||
|
||
var allMappedDiis = response.getMappedIdentities(); | ||
assertThat(allMappedDiis.size()).isEqualTo(10_000); | ||
|
||
for (var dii : diis) { | ||
var mappedDii = allMappedDiis.get(dii); | ||
assertThat(mappedDii).isNotNull(); | ||
|
||
// Current UID should always be there and should have correct length | ||
assertThat(mappedDii.getCurrentRawUid().length()).isEqualTo(RAW_UID_SIZE); | ||
|
||
// Previous UID is there for 90 days after rotation only, then it's null. | ||
// If it's there, it should have the correct size | ||
assertThat(mappedDii.getPreviousRawUid()).satisfiesAnyOf( | ||
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 don't want to do an assertion based on the dii's last updated? |
||
uid -> assertThat(uid).isNull(), | ||
uid -> assertThat(uid).hasSize(RAW_UID_SIZE) | ||
); | ||
|
||
// Sanity check that refresh from is a date not too far in the past. | ||
// If it is, either there is an Operator issue or salt rotation hasn't been running for a long time. | ||
assertThat(mappedDii.getRefreshFrom()).isAfter(Instant.now().minus(Duration.ofDays(10))); | ||
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. Do we want to let the test pass if refresh from is in the past at all? |
||
} | ||
}); | ||
} | ||
|
||
@ParameterizedTest(name = "/v3/identity/map - {0} - {2}") | ||
@MethodSource({ | ||
"suite.operator.TestData#identityMapV3BatchBadEmailArgs", | ||
"suite.operator.TestData#identityMapV3BatchBadPhoneArgs" | ||
}) | ||
public void testV3IdentityMapUnmapped(String label, Operator operator, String operatorName, String payload, String section) throws Exception { | ||
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. Maybe rename |
||
JsonNode response = operator.v3IdentityMap(payload); | ||
|
||
assertThat(response.at("/status").asText()).isEqualTo("success"); | ||
assertThat(response.at("/body/" + section + "/0/e").asText()).isEqualTo("invalid identifier"); | ||
} | ||
|
||
|
||
@ParameterizedTest(name = "/v2/identity/map - VALIDATE EMAIL - {0} - {2}") | ||
@MethodSource({ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can get rid of all the
getClientApiKey()
orgetClientApiSecret()
calls and use the consts directly