Skip to content

Commit

Permalink
Merge pull request #2 from IABTechLab/gdm-UID2-988-optout
Browse files Browse the repository at this point in the history
Enabled local E2E optout tests
  • Loading branch information
gmsdelmundo authored Dec 11, 2023
2 parents 233d6c0 + 7d1ea63 commit d0b406a
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ on:

jobs:
Image:
uses: IABTechLab/uid2-shared-actions/.github/workflows/shared-publish-docker-versioned.yaml@v2.4.1-pre
uses: IABTechLab/uid2-shared-actions/.github/workflows/shared-publish-docker-versioned.yaml@v2.3.6
with:
release_type: ${{ inputs.release_type }}
version_number_input: ${{ inputs.version_number_input }}
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/validate-image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ on:

jobs:
build-publish-docker-default:
uses: IABTechLab/uid2-shared-actions/.github/workflows/shared-validate-image.yaml@v2.4.1-pre
uses: IABTechLab/uid2-shared-actions/.github/workflows/shared-validate-image.yaml@v2.3.6
with:
failure_severity: ${{ inputs.failure_severity || 'HIGH'}}
fail_on_error: ${{ inputs.fail_on_error || true }}
Expand All @@ -25,7 +25,7 @@ jobs:
skip_tests: true
secrets: inherit
build-publish-docker-aws:
uses: IABTechLab/uid2-shared-actions/.github/workflows/shared-validate-image.yaml@v2.4.1-pre
uses: IABTechLab/uid2-shared-actions/.github/workflows/shared-validate-image.yaml@v2.3.6
with:
failure_severity: ${{ inputs.failure_severity || 'HIGH'}}
fail_on_error: ${{ inputs.fail_on_error || true }}
Expand All @@ -35,7 +35,7 @@ jobs:
secrets: inherit
needs: [build-publish-docker-default]
build-publish-docker-gcp:
uses: IABTechLab/uid2-shared-actions/.github/workflows/shared-validate-image.yaml@v2.4.1-pre
uses: IABTechLab/uid2-shared-actions/.github/workflows/shared-validate-image.yaml@v2.3.6
with:
failure_severity: ${{ inputs.failure_severity || 'HIGH'}}
fail_on_error: ${{ inputs.fail_on_error || true }}
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/suite/E2EFullTestSuite.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
@SelectClasses({
BasicTestSuite.class,
OperatorTestSuite.class,
LogoutTestSuite.class,
OptoutTestSuite.class,
ValidatorTestSuite.class
})
public class E2EFullTestSuite {
Expand Down
13 changes: 0 additions & 13 deletions src/test/java/suite/E2ELocalPublicOperatorTestSuite.java

This file was deleted.

3 changes: 2 additions & 1 deletion src/test/java/suite/E2EPrivateOperatorTestSuite.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
@Suite
@SelectClasses({
BasicTestSuite.class,
V2ApiOperatorTest.class
V2ApiOperatorTest.class,
OptoutTestSuite.class
})
public class E2EPrivateOperatorTestSuite {
}
2 changes: 1 addition & 1 deletion src/test/java/suite/E2EPublicOperatorTestSuite.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
@SelectClasses({
BasicTestSuite.class,
OperatorTestSuite.class,
LogoutTestSuite.class
OptoutTestSuite.class
})
public class E2EPublicOperatorTestSuite {
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

import org.junit.platform.suite.api.SelectClasses;
import org.junit.platform.suite.api.Suite;
import suite.optout.BeforeOptoutTest;

@Suite
@SelectClasses(suite.logout.BeforeLogoutTest.class)
public class LogoutTestSuite {
@SelectClasses(BeforeOptoutTest.class)
public class OptoutTestSuite {
}
4 changes: 3 additions & 1 deletion src/test/java/suite/operator/V2ApiOperatorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ 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 String SITE_ID = EnvUtil.getEnv("UID2_E2E_SITE_ID");

public static final String EMAIL_OPTOUT_ID = "optout@unifiedid.com";
public static final String PHONE_OPTOUT_ID = "+00000000001";
private static final String SITE_ID = EnvUtil.getEnv("UID2_E2E_SITE_ID");


@ParameterizedTest(name = "/v2/token/generate - {0} - {2}")
@MethodSource({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package suite.logout;
package suite.optout;

import app.AppsMap;
import app.common.Mapper;
Expand All @@ -17,8 +17,8 @@

// Tests in this class are currently run manually
@SuppressWarnings("unused")
public class AfterLogoutTest {
@ParameterizedTest(name = "/v0/token/refresh after {3} generate and {4} logout - {0}")
public class AfterOptoutTest {
@ParameterizedTest(name = "/v0/token/refresh after {3} generate and {4} logout - {0} - {2}")
@MethodSource({
"refreshTokenArgs"
})
Expand All @@ -30,7 +30,7 @@ public void testV0TokenRefresh(String label, Operator operator, String operatorN
assertThat(response).isEqualTo(Mapper.OBJECT_MAPPER.readTree("{\"advertisement_token\":\"\",\"advertising_token\":\"\",\"refresh_token\":\"\"}"));
}

@ParameterizedTest(name = "/v1/token/refresh after {3} generate and {4} logout - {0}")
@ParameterizedTest(name = "/v1/token/refresh after {3} generate and {4} logout - {0} - {2}")
@MethodSource({
"refreshTokenArgs"
})
Expand All @@ -42,7 +42,7 @@ public void testV1TokenRefresh(String label, Operator operator, String operatorN
assertThat(response).isEqualTo(Mapper.OBJECT_MAPPER.readTree("{\"status\":\"optout\"}"));
}

@ParameterizedTest(name = "/v2/token/refresh after {3} generate and {4} logout - {0}")
@ParameterizedTest(name = "/v2/token/refresh after {3} generate and {4} logout - {0} - {2}")
@MethodSource({
"refreshTokenArgs"
})
Expand All @@ -57,7 +57,7 @@ public void testV2TokenRefresh(String label, Operator operator, String operatorN
private static Set<Arguments> refreshTokenArgs() {
Set<Operator> operators = AppsMap.getApps(Operator.class);
Set<List<String>> refreshTokens = Set.of(
// Copy and paste BeforeLogoutTest output here
// Copy and paste BeforeOptoutTest output here
// WARNING: DO NOT COMMIT ANYTHING PASTED INTO THIS SET
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package suite.logout;
package suite.optout;

import app.common.Mapper;
import app.component.Operator;
import com.fasterxml.jackson.databind.JsonNode;
import com.uid2.client.IdentityTokens;
import helper.DisableCondition;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.condition.DisabledIf;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

Expand All @@ -17,14 +15,10 @@
import static org.assertj.core.api.Assertions.assertThat;

@SuppressWarnings("unused")
@DisabledIf(
value = "isDisabled",
disabledReason = "Optout not integrated to local dev env")
public class BeforeLogoutTest {
// TODO: UID2-988 - Integrate optout into local dev env
public class BeforeOptoutTest {
// TODO: Test failure case

private static final int LOGOUT_DELAY_MS = 1000;
private static final int OPTOUT_DELAY_MS = 1000;
private static List<String> outputs;

@BeforeAll
Expand All @@ -41,11 +35,11 @@ public static void teardownAll() {

@ParameterizedTest(name = "/v2/token/logout with /v0/token/generate - {0} - {2}")
@MethodSource({
"suite.logout.TestData#tokenEmailArgs"
"suite.optout.TestData#tokenEmailArgs"
})
public void testV2LogoutWithV0TokenGenerate(String label, Operator operator, String operatorName, String type, String identity) throws Exception {
JsonNode generateResponse = operator.v0TokenGenerate(type, identity);
Thread.sleep(LOGOUT_DELAY_MS);
Thread.sleep(OPTOUT_DELAY_MS);
JsonNode logoutResponse = operator.v2TokenLogout(type, identity);

assertThat(logoutResponse).isEqualTo(Mapper.OBJECT_MAPPER.readTree("{\"body\":{\"optout\":\"OK\"},\"status\":\"success\"}"));
Expand All @@ -61,12 +55,12 @@ public void testV2LogoutWithV0TokenGenerate(String label, Operator operator, Str

@ParameterizedTest(name = "/v2/token/logout with /v1/token/generate - {0} - {2}")
@MethodSource({
"suite.logout.TestData#tokenEmailArgs",
"suite.logout.TestData#tokenPhoneArgs"
"suite.optout.TestData#tokenEmailArgs",
"suite.optout.TestData#tokenPhoneArgs"
})
public void testV2LogoutWithV1TokenGenerate(String label, Operator operator, String operatorName, String type, String identity) throws Exception {
JsonNode generateResponse = operator.v1TokenGenerate(type, identity);
Thread.sleep(LOGOUT_DELAY_MS);
Thread.sleep(OPTOUT_DELAY_MS);
JsonNode logoutResponse = operator.v2TokenLogout(type, identity);

assertThat(logoutResponse).isEqualTo(Mapper.OBJECT_MAPPER.readTree("{\"body\":{\"optout\":\"OK\"},\"status\":\"success\"}"));
Expand All @@ -82,12 +76,12 @@ public void testV2LogoutWithV1TokenGenerate(String label, Operator operator, Str

@ParameterizedTest(name = "/v2/token/logout with /v2/token/generate - {0} - {2}")
@MethodSource({
"suite.logout.TestData#logoutTokenEmailArgs",
"suite.logout.TestData#logoutTokenPhoneArgs"
"suite.optout.TestData#optoutTokenEmailArgs",
"suite.optout.TestData#optoutTokenPhoneArgs"
})
public void testV2LogoutWithV2TokenGenerate(String label, Operator operator, String operatorName, String type, String identity) throws Exception {
IdentityTokens generateResponse = operator.v2TokenGenerate(type, identity, false).getIdentity();
Thread.sleep(LOGOUT_DELAY_MS);
Thread.sleep(OPTOUT_DELAY_MS);
JsonNode logoutResponse = operator.v2TokenLogout(type, identity);
assertThat(logoutResponse).isEqualTo(Mapper.OBJECT_MAPPER.readTree("{\"body\":{\"optout\":\"OK\"},\"status\":\"success\"}"));
addToken(
Expand All @@ -102,12 +96,12 @@ public void testV2LogoutWithV2TokenGenerate(String label, Operator operator, Str

@ParameterizedTest(name = "/v2/token/logout with /v2/token/generate - {0} - {2}")
@MethodSource({
"suite.logout.TestData#logoutTokenEmailArgs",
"suite.logout.TestData#logoutTokenPhoneArgs"
"suite.optout.TestData#optoutTokenEmailArgsOldParticipant",
"suite.optout.TestData#optoutTokenPhoneArgsOldParticipant"
})
public void testV2LogoutWithV2TokenGenerateOldParticipant(String label, Operator operator, String operatorName, String type, String identity) throws Exception {
IdentityTokens generateResponse = operator.v2TokenGenerate(type, identity, true).getIdentity();
Thread.sleep(LOGOUT_DELAY_MS);
Thread.sleep(OPTOUT_DELAY_MS);
JsonNode logoutResponse = operator.v2TokenLogout(type, identity);
assertThat(logoutResponse).isEqualTo(Mapper.OBJECT_MAPPER.readTree("{\"body\":{\"optout\":\"OK\"},\"status\":\"success\"}"));
addToken(
Expand All @@ -126,8 +120,4 @@ private void addToken(String label, String operatorName, String tokenGenerateVer
)
);
}

private static boolean isDisabled() {
return DisableCondition.isLocal();
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package suite.logout;
package suite.optout;

import app.AppsMap;
import app.common.EnvUtil;
Expand All @@ -9,6 +9,7 @@
import java.util.List;
import java.util.Random;
import java.util.Set;
import java.util.stream.Collectors;

public final class TestData {
private static final boolean PHONE_SUPPORT = Boolean.parseBoolean(EnvUtil.getEnv("UID2_E2E_PHONE_SUPPORT"));
Expand All @@ -31,7 +32,7 @@ public static Set<Arguments> tokenEmailArgs() {
return args;
}

public static Set<Arguments> logoutTokenEmailArgs() {
public static Set<Arguments> optoutTokenEmailArgs() {
Set<Operator> operators = AppsMap.getApps(Operator.class);
Random random = new Random();
int number = random.nextInt(100000000);
Expand All @@ -49,6 +50,10 @@ public static Set<Arguments> logoutTokenEmailArgs() {
return args;
}

public static Set<Arguments> optoutTokenEmailArgsOldParticipant() {
return filterPublicOperators(optoutTokenEmailArgs(), 1);
}

public static Set<Arguments> tokenPhoneArgs() {
Set<Operator> operators = AppsMap.getApps(Operator.class);
Set<List<String>> inputs = Set.of(
Expand All @@ -66,7 +71,7 @@ public static Set<Arguments> tokenPhoneArgs() {
return args;
}

public static Set<Arguments> logoutTokenPhoneArgs() {
public static Set<Arguments> optoutTokenPhoneArgs() {
Set<Operator> operators = AppsMap.getApps(Operator.class);
Random random = new Random();
StringBuilder phone = new StringBuilder(String.valueOf(random.nextLong((10000000000L - 1000000000L) +1) + 1000000000L));
Expand All @@ -89,6 +94,9 @@ public static Set<Arguments> logoutTokenPhoneArgs() {
return args;
}

public static Set<Arguments> optoutTokenPhoneArgsOldParticipant() {
return filterPublicOperators(optoutTokenPhoneArgs(), 1);
}

private static String getRandomString(int minLength, int maxLength) {
String alphabet = "abcdefghijklmnopqrstuvwxyz0123456789";
Expand All @@ -101,4 +109,10 @@ private static String getRandomString(int minLength, int maxLength) {
}
return s.toString();
}

private static Set<Arguments> filterPublicOperators(Set<Arguments> arguments, int operatorIndex) {
return arguments.stream()
.filter(args -> ((Operator) args.get()[operatorIndex]).getType() == Operator.Type.PUBLIC)
.collect(Collectors.toSet());
}
}

0 comments on commit d0b406a

Please sign in to comment.