Skip to content
Merged
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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<vertx.version>3.9.4</vertx.version>
<!-- check micrometer.version vertx-micrometer-metrics consumes before bumping up -->
<micrometer.version>1.1.0</micrometer.version>
<uid2-shared.version>1.2.1</uid2-shared.version>
<uid2-shared.version>1.12.0</uid2-shared.version>
<image.version>${project.version}</image.version>
</properties>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ private Router createRouter() {
router.route(WRITE_METHOD)
.handler(auth.internalOnly(this::handleWrite));
router.route(REPLICATE_METHOD)
.handler(auth.handle(this::handleReplicate, Role.OPERATOR));
.handler(auth.handle(this::handleReplicate, Role.OPTOUT));
router.route(REFRESH_METHOD)
.handler(auth.handle(attest.handle(this::handleRefresh), Role.OPERATOR));
router.get(HEALTHCHECK_METHOD)
Expand Down
14 changes: 12 additions & 2 deletions src/main/resources/com.uid2.core/test/operators/operators.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,23 @@
"name": "partner@uid2.com",
"contact": "partner@uid2.com",
"created": 1617149276,
"protocol": "aws-nitro"
"protocol": "aws-nitro",
"disabled" : false,
"site_id": 123,
"roles" : [
"OPERATOR"
]
},
{
"key": "trusted-partner-key",
"name": "partner@uid2.com",
"contact": "partner@uid2.com",
"created": 1617149276,
"protocol": "trusted"
"protocol": "trusted",
"site_id": 123,
"roles" : [
"OPERATOR",
"OPTOUT"
]
}
]
5 changes: 2 additions & 3 deletions src/test/java/com/uid2/optout/TestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

import com.uid2.optout.vertx.OptOutLogProducer;
import com.uid2.optout.vertx.OptOutServiceVerticle;
import com.uid2.optout.vertx.TestClientKeyProvider;
import com.uid2.optout.vertx.TestOperatorKeyProvider;
import com.uid2.shared.optout.*;
import com.uid2.shared.vertx.VertxUtils;
import io.vertx.core.Vertx;
import io.vertx.core.json.JsonObject;

Expand All @@ -25,7 +24,7 @@ public static OptOutLogProducer createOptOutLogProducer(Vertx vertx, JsonObject
}

public static OptOutServiceVerticle createOptOutService(Vertx vertx, JsonObject config) throws Exception {
return new OptOutServiceVerticle(vertx, TestClientKeyProvider.INSTANCE, null, config);
return new OptOutServiceVerticle(vertx, new TestOperatorKeyProvider(), null, config);
}

public static OptOutEntry[] toEntries(long... ids) {
Expand Down
23 changes: 16 additions & 7 deletions src/test/java/com/uid2/optout/vertx/OptOutServiceVerticleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@
import java.util.ArrayList;
import java.util.List;

import static com.uid2.optout.vertx.TestOperatorKeyProvider.TEST_OPERATOR_KEY;
import static com.uid2.optout.vertx.TestOperatorKeyProvider.TEST_OPTOUT_KEY;

@RunWith(VertxUnitRunner.class)
public class OptOutServiceVerticleTest {
private static String internalTestKey = "test-operator-key";
private static String internalTestBearerToken = "Bearer test-operator-key";
private static String internalTestKey = TEST_OPERATOR_KEY.getKey();
private static Vertx vertx;

@BeforeClass
Expand Down Expand Up @@ -56,7 +58,7 @@ private static Future<String> deployLogProducer(TestContext context, JsonObject
// set data_dir option to use tmpDir during test
config
.put(Const.Config.OptOutDataDirProp, OptOutUtils.tmpDir)
.put(Const.Config.OptOutInternalApiTokenProp, internalTestKey)
.put(Const.Config.OptOutInternalApiTokenProp, TEST_OPERATOR_KEY.getKey())
.put(Const.Config.OptOutReplicaUris, "http://127.0.0.1:8081/optout/write,http://127.0.0.1:8081/optout/write,http://127.0.0.1:8081/optout/write");

OptOutLogProducer producer = TestUtils.createOptOutLogProducer(vertx, config);
Expand Down Expand Up @@ -127,8 +129,12 @@ public void writeIdsParallel_expect200(TestContext context) {

// optout/add forwards request to remote optout/write api endpoints
@Test
public void replicateWithoutOptoutRole_expect401(TestContext context) {
verifyStatus(context, replicateQuery(234), 401);
}
@Test
public void replicate_expect200(TestContext context) {
verifyStatus(context, replicateQuery(234), 200);
verifyStatus(context, replicateQuery(234), 200, TEST_OPTOUT_KEY.getKey());
}

@Test
Expand Down Expand Up @@ -216,8 +222,11 @@ private String replicateQuery(String identityHashB64, String advertisingIdB64) {
OptOutServiceVerticle.ADVERTISING_ID,
advertisingIdB64);
}

private Future<Void> verifyStatus(TestContext context, String pq, int status) {
return verifyStatus(context, pq, status, internalTestKey);
}

private Future<Void> verifyStatus(TestContext context, String pq, int status, String token) {
Promise<Void> promise = Promise.promise();
Async async = context.async();
int port = Const.Port.ServicePortForOptOut;
Expand All @@ -228,7 +237,7 @@ private Future<Void> verifyStatus(TestContext context, String pq, int status) {
promise.complete();
});
req.headers()
.add("Authorization", internalTestBearerToken);
.add("Authorization", "Bearer " + token);
req.end();
return promise.future();
}
Expand All @@ -247,7 +256,7 @@ private Future<Void> verifyStatusAndBody(TestContext context, String pq, int sta
});
});
req.headers()
.add("Authorization", internalTestBearerToken);
.add("Authorization", "Bearer " + internalTestKey);
req.end();
return promise.future();
}
Expand Down
38 changes: 0 additions & 38 deletions src/test/java/com/uid2/optout/vertx/TestClientKeyProvider.java

This file was deleted.

42 changes: 42 additions & 0 deletions src/test/java/com/uid2/optout/vertx/TestOperatorKeyProvider.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.uid2.optout.vertx;

import com.uid2.shared.auth.IAuthorizable;
import com.uid2.shared.auth.OperatorKey;
import com.uid2.shared.auth.Role;
import com.uid2.shared.store.IOperatorKeyProvider;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;

public class TestOperatorKeyProvider implements IOperatorKeyProvider {
public static final OperatorKey TEST_OPERATOR_KEY = new OperatorKey("test-operator-key", "test_operator", "test_operator", "trusted", 0,
false, 5, new HashSet<>(Arrays.asList(Role.OPERATOR)));

public static final OperatorKey TEST_OPTOUT_KEY = new OperatorKey("test-optout-operator-key", "test_optout_operator", "test_optout_operator", "trusted", 0,
false, 5, new HashSet<>(Arrays.asList(Role.OPERATOR, Role.OPTOUT)));

private static final Collection<OperatorKey> ALL_KEYS = new ArrayList<>();

static {
ALL_KEYS.add(TEST_OPERATOR_KEY);
ALL_KEYS.add(TEST_OPTOUT_KEY);
}

@Override
public OperatorKey getOperatorKey(String token) {
return ALL_KEYS.stream().filter(t -> t.getKey().equals(token))
.findAny().orElse(TEST_OPERATOR_KEY);
}

@Override
public Collection<OperatorKey> getAll() {
return ALL_KEYS;
}

@Override
public IAuthorizable get(String key) {
return getOperatorKey(key);
}
}