Skip to content

Commit

Permalink
Merge pull request #1813 from fedinskiy/oidc-tp
Browse files Browse the repository at this point in the history
Coverage for JSON tokens
  • Loading branch information
mocenas authored May 30, 2024
2 parents ca9ac92 + 1ab2b90 commit 563efd8
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package io.quarkus.ts.security.keycloak.oidcclient.extended.restclient.principal;

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

import org.eclipse.microprofile.rest.client.inject.RestClient;

import io.quarkus.ts.security.keycloak.oidcclient.extended.restclient.principal.clients.JsonTokenClient;

@Path("/json-propagation-filter")
public class JsonTokenResource {

@Inject
@RestClient
JsonTokenClient jsonClient;

@GET
public String getUserNameThroughJson() {
return jsonClient.getUserName();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package io.quarkus.ts.security.keycloak.oidcclient.extended.restclient.principal.clients;

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

import org.eclipse.microprofile.rest.client.annotation.RegisterClientHeaders;
import org.eclipse.microprofile.rest.client.annotation.RegisterProvider;
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;

import io.quarkus.oidc.token.propagation.JsonWebTokenRequestFilter;

@RegisterRestClient
@RegisterClientHeaders
@Path("/principal")
@RegisterProvider(JsonWebTokenRequestFilter.class)
public interface JsonTokenClient {

@GET
String getUserName();
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ io.quarkus.ts.security.keycloak.oidcclient.extended.restclient.ping.clients.Auto
io.quarkus.ts.security.keycloak.oidcclient.extended.restclient.ping.clients.TokenPropagationPongClient/mp-rest/url=http://localhost:${quarkus.http.port}

io.quarkus.ts.security.keycloak.oidcclient.extended.restclient.principal.clients.TokenPropagationFilteredClient/mp-rest/url=http://localhost:${quarkus.http.port}
io.quarkus.ts.security.keycloak.oidcclient.extended.restclient.principal.clients.JsonTokenClient/mp-rest/url=http://localhost:${quarkus.http.port}

#OpenAPI
quarkus.smallrye-openapi.store-schema-directory=target/generated/jakarta-rest/
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
import static org.hamcrest.CoreMatchers.containsString;

import org.apache.http.HttpStatus;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

import io.quarkus.test.scenarios.QuarkusScenario;
import io.restassured.response.Response;

@Tag("QUARKUS-3680")
@QuarkusScenario
Expand All @@ -21,4 +23,13 @@ public void usernameTest() {
.then().statusCode(HttpStatus.SC_OK)
.body(containsString(USER));
}

@Test
public void jsonUsernameTest() {
Response response = given()
.auth().oauth2(createToken())
.when().get("/json-propagation-filter");
Assertions.assertEquals(HttpStatus.SC_OK, response.statusCode());
Assertions.assertEquals(USER, response.body().asString());
}
}

0 comments on commit 563efd8

Please sign in to comment.