From 245768a829d170c1331a5aa619efd90b2fd94cdf Mon Sep 17 00:00:00 2001 From: Vishal Egbert Date: Wed, 20 Nov 2024 13:49:14 +1100 Subject: [PATCH 1/3] Fix unbounded path label --- src/main/java/com/uid2/optout/Main.java | 8 +++--- .../java/com/uid2/optout/vertx/Endpoints.java | 27 +++++++++++++++++++ .../optout/vertx/OptOutServiceVerticle.java | 17 +++++------- .../vertx/OptOutServiceVerticleTest.java | 12 +++++---- 4 files changed, 44 insertions(+), 20 deletions(-) create mode 100644 src/main/java/com/uid2/optout/vertx/Endpoints.java diff --git a/src/main/java/com/uid2/optout/Main.java b/src/main/java/com/uid2/optout/Main.java index a7c7586..fab0668 100644 --- a/src/main/java/com/uid2/optout/Main.java +++ b/src/main/java/com/uid2/optout/Main.java @@ -1,9 +1,6 @@ package com.uid2.optout; -import com.uid2.optout.vertx.OptOutLogProducer; -import com.uid2.optout.vertx.OptOutServiceVerticle; -import com.uid2.optout.vertx.PartnerConfigMonitor; -import com.uid2.optout.vertx.PartnerConfigMonitorV2; +import com.uid2.optout.vertx.*; import com.uid2.shared.ApplicationVersion; import com.uid2.shared.Utils; import com.uid2.shared.attest.AttestationResponseHandler; @@ -223,7 +220,8 @@ private static void setupMetrics(MicrometerMetricsOptions metricOptions) { .meterFilter(new PrometheusRenameFilter()) .meterFilter(MeterFilter.replaceTagValues(Label.HTTP_PATH.toString(), actualPath -> { try { - return HttpUtils.normalizePath(actualPath).split("\\?")[0]; + String normalized = HttpUtils.normalizePath(actualPath).split("\\?")[0]; + return Endpoints.pathSet().contains(normalized) ? normalized : "/unknown"; } catch (IllegalArgumentException e) { return actualPath; } diff --git a/src/main/java/com/uid2/optout/vertx/Endpoints.java b/src/main/java/com/uid2/optout/vertx/Endpoints.java new file mode 100644 index 0000000..4f90065 --- /dev/null +++ b/src/main/java/com/uid2/optout/vertx/Endpoints.java @@ -0,0 +1,27 @@ +package com.uid2.optout.vertx; + +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public enum Endpoints { + OPS_HEALTHCHECK("/ops/healthcheck"), + OPTOUT_REFRESH("/optout/refresh"), + OPTOUT_WRITE("/optout/write"), + OPTOUT_REPLICATE("/optout/replicate"), + OPTOUT_PARTNER_MOCK("/optout/partner_mock"); + private final String path; + + Endpoints(final String path) { + this.path = path; + } + + public static Set pathSet() { + return Stream.of(Endpoints.values()).map(Endpoints::toString).collect(Collectors.toSet()); + } + + @Override + public String toString() { + return path; + } +} diff --git a/src/main/java/com/uid2/optout/vertx/OptOutServiceVerticle.java b/src/main/java/com/uid2/optout/vertx/OptOutServiceVerticle.java index df9a364..3a71a7e 100644 --- a/src/main/java/com/uid2/optout/vertx/OptOutServiceVerticle.java +++ b/src/main/java/com/uid2/optout/vertx/OptOutServiceVerticle.java @@ -39,14 +39,11 @@ import java.util.concurrent.atomic.AtomicReference; import java.util.stream.Collectors; +import static com.uid2.optout.vertx.Endpoints.*; + public class OptOutServiceVerticle extends AbstractVerticle { public static final String IDENTITY_HASH = "identity_hash"; public static final String ADVERTISING_ID = "advertising_id"; - public static final String REFRESH_METHOD = "/optout/refresh"; - public static final String WRITE_METHOD = "/optout/write"; - public static final String REPLICATE_METHOD = "/optout/replicate"; - public static final String HEALTHCHECK_METHOD = "/ops/healthcheck"; - public static final String OPTOUT_PARTNER_MOCK_METHOD = "/optout/partner_mock"; private static final Logger LOGGER = LoggerFactory.getLogger(OptOutServiceVerticle.class); private final HealthComponent healthComponent = HealthManager.instance.registerComponent("http-server"); @@ -168,18 +165,18 @@ private Router createRouter() { .allowedHeader("Access-Control-Allow-Headers") .allowedHeader("Content-Type")); - router.route(WRITE_METHOD) + router.route(Endpoints.OPTOUT_WRITE.toString()) .handler(internalAuth.handle(this::handleWrite)); - router.route(REPLICATE_METHOD) + router.route(Endpoints.OPTOUT_REPLICATE.toString()) .handler(auth.handle(this::handleReplicate, Role.OPTOUT)); - router.route(REFRESH_METHOD) + router.route(Endpoints.OPTOUT_REFRESH.toString()) .handler(auth.handle(attest.handle(this::handleRefresh, Role.OPERATOR), Role.OPERATOR)); - router.get(HEALTHCHECK_METHOD) + router.get(Endpoints.OPS_HEALTHCHECK.toString()) .handler(this::handleHealthCheck); if (this.enableOptOutPartnerMock) { final OperatorKey loopbackClient = new OperatorKey("", "", "loopback", "loopback", "loopback", 0, false, ""); - router.route(OPTOUT_PARTNER_MOCK_METHOD).handler(auth.loopbackOnly(this::handleOptOutPartnerMock, loopbackClient)); + router.route(Endpoints.OPTOUT_PARTNER_MOCK.toString()).handler(auth.loopbackOnly(this::handleOptOutPartnerMock, loopbackClient)); } //// if enabled, this would add handler for exposing prometheus metrics diff --git a/src/test/java/com/uid2/optout/vertx/OptOutServiceVerticleTest.java b/src/test/java/com/uid2/optout/vertx/OptOutServiceVerticleTest.java index eed7f24..504c502 100644 --- a/src/test/java/com/uid2/optout/vertx/OptOutServiceVerticleTest.java +++ b/src/test/java/com/uid2/optout/vertx/OptOutServiceVerticleTest.java @@ -23,6 +23,8 @@ import java.util.ArrayList; import java.util.List; +import static com.uid2.optout.vertx.Endpoints.OPTOUT_WRITE; + @RunWith(VertxUnitRunner.class) public class OptOutServiceVerticleTest { private static final String INTERNAL_TEST_KEY = "test-operator-key"; @@ -92,7 +94,7 @@ public void writeId_expect200(TestContext context) { @Test public void getHealthCheck_expectOK(TestContext context) { - verifyStatus(context, OptOutServiceVerticle.HEALTHCHECK_METHOD, 200); + verifyStatus(context, Endpoints.OPS_HEALTHCHECK.toString(), 200); } @Test @@ -139,7 +141,7 @@ public void replicate_expect200(TestContext context) { public void testQuorumClient_expectSuccess(TestContext context) { String[] uris = new String[3]; for (int i = 0; i < 3; ++i) { - uris[i] = String.format("http://127.0.0.1:%d%s", Const.Port.ServicePortForOptOut, OptOutServiceVerticle.WRITE_METHOD); + uris[i] = String.format("http://127.0.0.1:%d%s", Const.Port.ServicePortForOptOut, Endpoints.OPTOUT_WRITE); } QuorumWebClient quorumClient = new QuorumWebClient(vertx, uris); @@ -155,7 +157,7 @@ public void testQuorumClient_expectSuccess(TestContext context) { public void testQuorumClient1Failure_expectSuccess(TestContext context) { String[] uris = new String[3]; for (int i = 0; i < 2; ++i) { - uris[i] = String.format("http://127.0.0.1:%d%s", Const.Port.ServicePortForOptOut, OptOutServiceVerticle.WRITE_METHOD); + uris[i] = String.format("http://127.0.0.1:%d%s", Const.Port.ServicePortForOptOut, Endpoints.OPTOUT_WRITE); } uris[2] = "http://httpstat.us/404"; @@ -201,7 +203,7 @@ private String writeQuery(byte[] identityHash, byte[] advertisingId) { } private String writeQuery(String identityHashB64, String advertisingIdB64) { - return String.format("%s?%s=%s&%s=%s", OptOutServiceVerticle.WRITE_METHOD, + return String.format("%s?%s=%s&%s=%s", Endpoints.OPTOUT_WRITE, OptOutServiceVerticle.IDENTITY_HASH, identityHashB64, OptOutServiceVerticle.ADVERTISING_ID, @@ -214,7 +216,7 @@ private String replicateQuery(long id) { } private String replicateQuery(String identityHashB64, String advertisingIdB64) { - return String.format("%s?%s=%s&%s=%s", OptOutServiceVerticle.REPLICATE_METHOD, + return String.format("%s?%s=%s&%s=%s", Endpoints.OPTOUT_REPLICATE, OptOutServiceVerticle.IDENTITY_HASH, identityHashB64, OptOutServiceVerticle.ADVERTISING_ID, From 9269c3d465a747d2de078893566768d6d051d537 Mon Sep 17 00:00:00 2001 From: Release Workflow Date: Wed, 20 Nov 2024 02:53:14 +0000 Subject: [PATCH 2/3] [CI Pipeline] Released Snapshot version: 2.11.17-alpha-41-SNAPSHOT --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index c77d35c..7191f84 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.uid2 uid2-optout - 2.11.16 + 2.11.17-alpha-41-SNAPSHOT uid2-optout https://github.com/IABTechLab/uid2-optout From b0e652d9ce9ec4711224f6fb7d5e92d43103a541 Mon Sep 17 00:00:00 2001 From: Vishal Egbert Date: Fri, 22 Nov 2024 16:42:09 +1100 Subject: [PATCH 3/3] Remove snapshot --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 7191f84..c77d35c 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.uid2 uid2-optout - 2.11.17-alpha-41-SNAPSHOT + 2.11.16 uid2-optout https://github.com/IABTechLab/uid2-optout