Skip to content

Commit

Permalink
Add test to OpenTelemetry for URI template verification
Browse files Browse the repository at this point in the history
  • Loading branch information
geoand committed Jul 12, 2023
1 parent b6c0c5b commit 51385e6
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 7 deletions.
19 changes: 19 additions & 0 deletions integration-tests/opentelemetry-reactive/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@
<artifactId>opentelemetry-sdk-testing</artifactId>
</dependency>

<!-- Security -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-elytron-security-properties-file</artifactId>
</dependency>

<!-- Test Dependencies -->
<dependency>
<groupId>io.quarkus</groupId>
Expand Down Expand Up @@ -121,6 +127,19 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-elytron-security-properties-file-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package io.quarkus.it.opentelemetry.reactive;

import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;

import org.jboss.resteasy.reactive.RestPath;

@Path("secured")
public class SecuredResource {
@GET
@Path("item/{value}")
public String get(@RestPath String value) {
return "Received: " + value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,12 @@ quarkus.rest-client.client.url=${test.url

quarkus.otel.bsp.schedule.delay=100
quarkus.otel.bsp.export.timeout=5s

quarkus.security.users.embedded.enabled=true
quarkus.security.users.embedded.plain-text=true
quarkus.security.users.embedded.users.scott=reader
quarkus.security.users.embedded.users.stuart=writer
quarkus.security.users.embedded.roles.scott=READER
quarkus.security.users.embedded.roles.stuart=READER,WRITER
quarkus.http.auth.permission.secured.policy=authenticated
quarkus.http.auth.permission.secured.paths=/secured/*
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
import static io.quarkus.it.opentelemetry.reactive.Utils.getSpans;
import static io.quarkus.it.opentelemetry.reactive.Utils.getSpansByKindAndParentId;
import static io.restassured.RestAssured.given;
import static io.restassured.RestAssured.when;
import static java.net.HttpURLConnection.HTTP_OK;
import static java.util.concurrent.TimeUnit.SECONDS;
import static java.util.stream.Collectors.toSet;
import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.await;
Expand All @@ -21,7 +23,6 @@
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.TimeUnit;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
Expand All @@ -36,7 +37,7 @@ public class OpenTelemetryReactiveTest {
@AfterEach
void reset() {
given().get("/reset").then().statusCode(HTTP_OK);
await().atMost(5, TimeUnit.SECONDS).until(() -> getSpans().size() == 0);
await().atMost(5, SECONDS).until(() -> getSpans().size() == 0);
}

@Test
Expand All @@ -49,7 +50,7 @@ void get() {
.statusCode(200)
.body(equalTo("Hello Naruto"));

await().atMost(5, TimeUnit.SECONDS).until(() -> getSpans().size() == 2);
await().atMost(5, SECONDS).until(() -> getSpans().size() == 2);
List<Map<String, Object>> spans = getSpans();
assertEquals(2, spans.size());
assertEquals(spans.get(0).get("traceId"), spans.get(1).get("traceId"));
Expand Down Expand Up @@ -78,7 +79,7 @@ void reactiveException() {
}

private static void assertExceptionRecorded() {
await().atMost(5, TimeUnit.SECONDS).until(() -> getExceptionEventData().size() == 1);
await().atMost(5, SECONDS).until(() -> getExceptionEventData().size() == 1);
assertThat(getExceptionEventData()).singleElement().satisfies(s -> {
assertThat(s).contains("dummy");
});
Expand All @@ -94,7 +95,7 @@ void post() {
.statusCode(200)
.body(equalTo("Hello Naruto"));

await().atMost(5, TimeUnit.SECONDS).until(() -> getSpans().size() == 2);
await().atMost(5, SECONDS).until(() -> getSpans().size() == 2);
List<Map<String, Object>> spans = getSpans();
assertEquals(2, spans.size());
assertEquals(spans.get(0).get("traceId"), spans.get(1).get("traceId"));
Expand All @@ -109,7 +110,7 @@ void multipleUsingChain() {
.statusCode(200)
.body(equalTo("Hello Naruto and Hello Goku"));

await().atMost(5, TimeUnit.SECONDS).until(() -> getSpans().size() == 7);
await().atMost(5, SECONDS).until(() -> getSpans().size() == 7);

List<Map<String, Object>> spans = getSpans();
assertEquals(7, spans.size());
Expand Down Expand Up @@ -158,7 +159,7 @@ void multipleUsingCombine() {
.statusCode(200)
.body(equalTo("Hello Naruto and Hello Goku"));

await().atMost(5, TimeUnit.SECONDS).until(() -> getSpans().size() == 7);
await().atMost(5, SECONDS).until(() -> getSpans().size() == 7);

List<Map<String, Object>> spans = getSpans();
assertEquals(7, spans.size());
Expand Down Expand Up @@ -197,4 +198,28 @@ void multipleUsingCombine() {
Map<String, Object> gokuInternal = getSpanByKindAndParentId(spans, INTERNAL, gokuServer.get("spanId"));
assertEquals("helloGet", gokuInternal.get("name"));
}

@Test
public void securedInvalidCredential() {
given().auth().preemptive().basic("scott", "reader2").when().get("/secured/item/something")
.then()
.statusCode(401);

await().atMost(5, SECONDS).until(() -> getSpans().size() == 1);
assertThat(getSpans()).singleElement().satisfies(m -> {
assertThat(m).extractingByKey("name").isEqualTo("GET /secured/item/{value}");
});
}

@Test
public void securedProperCredentials() {
given().auth().preemptive().basic("scott", "reader").when().get("/secured/item/something")
.then()
.statusCode(200);

await().atMost(5, SECONDS).until(() -> getSpans().size() == 1);
assertThat(getSpans()).singleElement().satisfies(m -> {
assertThat(m).extractingByKey("name").isEqualTo("GET /secured/item/{value}");
});
}
}

0 comments on commit 51385e6

Please sign in to comment.