Skip to content
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

Ian UID2-1846 version in query param #591

Merged
merged 5 commits into from
May 31, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@ public ClientVersionCapturingHandler(String dir, String whitelistGlob) throws IO
}
@Override
public void handle(RoutingContext context) {
if (context.request().headers().contains(Const.Http.ClientVersionHeader)) {
final String clientVersion = context.request().headers().get(Const.Http.ClientVersionHeader);
if (clientVersion != null) {
final Counter counter = _clientVersionCounters.get(clientVersion);
if (counter != null) {
counter.increment();
}
String clientVersion = context.request().headers().get(Const.Http.ClientVersionHeader);
if (clientVersion == null) {
clientVersion = !context.queryParam("client").isEmpty() ? context.queryParam("client").get(0) : null;
}
if (clientVersion != null) {
final Counter counter = _clientVersionCounters.get(clientVersion);
if (counter != null) {
counter.increment();
}
}
context.next();
Expand Down
72 changes: 72 additions & 0 deletions src/test/java/com/uid2/operator/UIDOperatorVerticleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
import com.uid2.shared.secret.KeyHasher;
import com.uid2.shared.store.*;
import com.uid2.shared.store.reader.RotatingKeysetProvider;
import io.micrometer.core.instrument.Counter;
import io.micrometer.core.instrument.Metrics;
import io.micrometer.core.instrument.search.MeterNotFoundException;
import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
import io.vertx.core.AsyncResult;
import io.vertx.core.Future;
Expand Down Expand Up @@ -5005,4 +5007,74 @@ void secureLinkValidationFailsReturnsIdentityError(Vertx vertx, VertxTestContext
testContext.completeNow();
});
}

@ParameterizedTest // note that this test will be removed when we switch to logging versions
@ValueSource(strings = {"euid-sdk-1.0.0", "openid-sdk-1.0", "uid2-esp-0.0.1a", "uid2-sdk-0.0.1a",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the behavior when it's not one of these strings? should we add a test for that too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah sounds good, added test for it

"uid2-sdk-0.0.1b", "uid2-sdk-1.0.0", "uid2-sdk-2.0.0"})
void clientVersionHeader(String clientVersion, Vertx vertx, VertxTestContext testContext) {
WebClient client = WebClient.create(vertx);
HttpRequest<Buffer> req = client.getAbs(getUrlForEndpoint("/any/endpoint"));
req.putHeader("X-UID2-Client-Version", clientVersion);
req.send(ar -> {
assertEquals(404, ar.result().statusCode());
final double actual = Metrics.globalRegistry
.get("uid2.client_sdk_versions")
.tag("client_version", clientVersion)
.counter().count();
assertEquals(1, actual);
testContext.completeNow();
});
}

@ParameterizedTest // note that this test will be removed when we switch to logging versions
@ValueSource(strings = {"euid-sdk-1.0.0", "openid-sdk-1.0", "uid2-esp-0.0.1a", "uid2-sdk-0.0.1a",
"uid2-sdk-0.0.1b", "uid2-sdk-1.0.0", "uid2-sdk-2.0.0"})
void clientVersionQueryParameter(String clientVersion, Vertx vertx, VertxTestContext testContext) {
WebClient client = WebClient.create(vertx);
HttpRequest<Buffer> req = client.getAbs(getUrlForEndpoint("/any/endpoint?client=" + clientVersion));
req.send(ar -> {
assertEquals(404, ar.result().statusCode());
final double actual = Metrics.globalRegistry
.get("uid2.client_sdk_versions")
.tag("client_version", clientVersion)
.counter().count();
assertEquals(1, actual);
testContext.completeNow();
});
}

@Test // note that this test will be removed when we switch to logging versions
void clientVersionHeaderNotFound(Vertx vertx, VertxTestContext testContext) {
WebClient client = WebClient.create(vertx);
HttpRequest<Buffer> req = client.getAbs(getUrlForEndpoint("/any/endpoint"));
String clientVersion = "invalid-sdk";
req.putHeader("X-UID2-Client-Version", clientVersion);
req.send(ar -> {
assertEquals(404, ar.result().statusCode());
assertThrows(MeterNotFoundException.class, () -> {
Metrics.globalRegistry
.get("uid2.client_sdk_versions")
.tag("client_version", clientVersion)
.counter();
});
testContext.completeNow();
});
}

@Test // note that this test will be removed when we switch to logging versions
void clientVersionQueryParameterNotFound(Vertx vertx, VertxTestContext testContext) {
WebClient client = WebClient.create(vertx);
String clientVersion = "invalid-sdk";
HttpRequest<Buffer> req = client.getAbs(getUrlForEndpoint("/any/endpoint?client=" + clientVersion));
req.send(ar -> {
assertEquals(404, ar.result().statusCode());
assertThrows(MeterNotFoundException.class, () -> {
Metrics.globalRegistry
.get("uid2.client_sdk_versions")
.tag("client_version", clientVersion)
.counter();
});
testContext.completeNow();
});
}
}