Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/main/java/com/uid2/operator/vertx/UIDOperatorVerticle.java
Original file line number Diff line number Diff line change
Expand Up @@ -301,11 +301,6 @@ private void setUpEncryptedRoutes(Router mainRouter, BodyHandler bodyHandler) {
rc -> encryptedPayloadHandler.handle(rc, this::handleKeysRequestV2), Role.ID_READER));
mainRouter.post(V2_TOKEN_LOGOUT.toString()).handler(bodyHandler).handler(auth.handleV1(
rc -> encryptedPayloadHandler.handleAsync(rc, this::handleLogoutAsyncV2), Role.OPTOUT));
if (this.optOutStatusApiEnabled) {
mainRouter.post(V2_OPTOUT_STATUS.toString()).handler(bodyHandler).handler(auth.handleV1(
rc -> encryptedPayloadHandler.handle(rc, this::handleOptoutStatus),
Role.MAPPER, Role.SHARER, Role.ID_READER));
}

if (this.clientSideTokenGenerate)
mainRouter.post(V2_TOKEN_CLIENTGENERATE.toString()).handler(bodyHandler).handler(this::handleClientSideTokenGenerate);
Expand All @@ -322,6 +317,11 @@ private void setUpEncryptedRoutes(Router mainRouter, BodyHandler bodyHandler) {
rc -> encryptedPayloadHandler.handle(rc, this::handleIdentityMapV2), Role.MAPPER), false);
mainRouter.post(V3_IDENTITY_MAP.toString()).handler(bodyHandler).blockingHandler(auth.handleV1(
rc -> encryptedPayloadHandler.handle(rc, this::handleIdentityMapV3), Role.MAPPER), false);
if (this.optOutStatusApiEnabled) {
mainRouter.post(V2_OPTOUT_STATUS.toString()).handler(bodyHandler).blockingHandler(auth.handleV1(
rc -> encryptedPayloadHandler.handle(rc, this::handleOptoutStatus),
Role.MAPPER, Role.SHARER, Role.ID_READER), false);
}
} else {
LOGGER.info("Async batch requests disabled");
mainRouter.post(V2_KEY_SHARING.toString()).handler(bodyHandler).handler(auth.handleV1(
Expand All @@ -334,6 +334,11 @@ private void setUpEncryptedRoutes(Router mainRouter, BodyHandler bodyHandler) {
rc -> encryptedPayloadHandler.handle(rc, this::handleIdentityMapV2), Role.MAPPER));
mainRouter.post(V3_IDENTITY_MAP.toString()).handler(bodyHandler).handler(auth.handleV1(
rc -> encryptedPayloadHandler.handle(rc, this::handleIdentityMapV3), Role.MAPPER));
if (this.optOutStatusApiEnabled) {
mainRouter.post(V2_OPTOUT_STATUS.toString()).handler(bodyHandler).handler(auth.handleV1(
rc -> encryptedPayloadHandler.handle(rc, this::handleOptoutStatus),
Role.MAPPER, Role.SHARER, Role.ID_READER));
}
}
}

Expand Down
26 changes: 26 additions & 0 deletions src/test/java/com/uid2/operator/UIDOperatorVerticleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ void deployVerticle(Vertx vertx, VertxTestContext testContext, TestInfo testInfo
asyncBatchRequestLogWatcher.start();
((Logger) LoggerFactory.getLogger(UIDOperatorVerticle.class)).addAppender(asyncBatchRequestLogWatcher);
}
if (testInfo.getTestMethod().isPresent() &&
testInfo.getTestMethod().get().getName().equals("optOutStatusRequestWithAsyncBatchEnabled")) {
config.put(Const.Config.EnableAsyncBatchRequestProp, true);
}
when(configStore.getConfig()).thenAnswer(x -> runtimeConfig);

this.uidInstanceIdProvider = new UidInstanceIdProvider("test-instance", "id");
Expand Down Expand Up @@ -2308,6 +2312,28 @@ void optOutStatusRequest(boolean useV4Uid, Map<String, Long> optedOutIds, int op
});
}

@Test
void optOutStatusRequestWithAsyncBatchEnabled(Vertx vertx, VertxTestContext testContext) {
fakeAuth(126, Role.MAPPER);
setupKeys();
setupSalts(true);

String rawUid = "qAmIGxqLk_RhOtm4f1nLlqYewqSma8fgvjEXYnQ3Jr0K";
long optedOutSince = Instant.now().minus(1, DAYS).getEpochSecond();
when(this.optOutStore.getOptOutTimestampByAdId(rawUid)).thenReturn(optedOutSince);

JsonObject requestJson = new JsonObject();
requestJson.put("advertising_ids", new JsonArray().add(rawUid));

send(vertx, "v2/optout/status", requestJson, 200, respJson -> {
assertEquals("success", respJson.getString("status"));
JsonArray optOutJsonArray = respJson.getJsonObject("body").getJsonArray("opted_out");
assertEquals(1, optOutJsonArray.size());
assertEquals(rawUid, optOutJsonArray.getJsonObject(0).getString("advertising_id"));
testContext.completeNow();
});
}

private static Stream<Arguments> optOutStatusValidationErrorData() {
// Test case 1
JsonArray rawUIDs = new JsonArray();
Expand Down