diff --git a/integration-tests/smallrye-graphql-client-keycloak/pom.xml b/integration-tests/smallrye-graphql-client-keycloak/pom.xml index e87c0810c3da8..b1481bb6df0bf 100644 --- a/integration-tests/smallrye-graphql-client-keycloak/pom.xml +++ b/integration-tests/smallrye-graphql-client-keycloak/pom.xml @@ -29,9 +29,14 @@ io.quarkus quarkus-resteasy-deployment + + io.quarkus + quarkus-oidc + io.rest-assured rest-assured + test @@ -85,7 +90,15 @@ io.quarkus quarkus-oidc-deployment + ${project.version} + pom test + + + * + * + + diff --git a/integration-tests/smallrye-graphql-client-keycloak/src/main/java/io/quarkus/io/smallrye/graphql/keycloak/GraphQLAuthExpiryTester.java b/integration-tests/smallrye-graphql-client-keycloak/src/main/java/io/quarkus/io/smallrye/graphql/keycloak/GraphQLAuthExpiryTester.java index 3aa53e1acb18a..9a8c49e6b28f4 100644 --- a/integration-tests/smallrye-graphql-client-keycloak/src/main/java/io/quarkus/io/smallrye/graphql/keycloak/GraphQLAuthExpiryTester.java +++ b/integration-tests/smallrye-graphql-client-keycloak/src/main/java/io/quarkus/io/smallrye/graphql/keycloak/GraphQLAuthExpiryTester.java @@ -8,9 +8,6 @@ import jakarta.ws.rs.Path; import jakarta.ws.rs.PathParam; -import org.eclipse.microprofile.config.inject.ConfigProperty; - -import io.restassured.RestAssured; import io.smallrye.common.annotation.Blocking; import io.smallrye.graphql.client.dynamic.api.DynamicGraphQLClient; import io.smallrye.graphql.client.dynamic.api.DynamicGraphQLClientBuilder; @@ -26,19 +23,14 @@ @Path("/") public class GraphQLAuthExpiryTester { - @ConfigProperty(name = "quarkus.oidc.auth-server-url") - String keycloakRealm; - @GET - @Path("/dynamic-subscription-auth-expiry/{url}") + @Path("/dynamic-subscription-auth-expiry/{token}/{url}") @Blocking - public void dynamicSubscription(@PathParam("url") String url) + public void dynamicSubscription(@PathParam("token") String token, @PathParam("url") String url) throws Exception { - String authHeader = getAuthHeader(); - DynamicGraphQLClientBuilder clientBuilder = DynamicGraphQLClientBuilder.newBuilder() .url(url + "/graphql") - .header("Authorization", authHeader) + .header("Authorization", "Bearer " + token) .executeSingleOperationsOverWebsocket(true); try (DynamicGraphQLClient client = clientBuilder.build()) { @@ -67,17 +59,4 @@ public void dynamicSubscription(@PathParam("url") String url) } } - private String getAuthHeader() { - io.restassured.response.Response response = RestAssured.given() - .contentType("application/x-www-form-urlencoded") - .accept("application/json") - .formParam("username", "alice") - .formParam("password", "alice") - .param("client_id", "quarkus-app") - .param("client_secret", "secret") - .formParam("grant_type", "password") - .post(keycloakRealm + "/protocol/openid-connect/token"); - - return "Bearer " + response.getBody().jsonPath().getString("access_token"); - } } diff --git a/integration-tests/smallrye-graphql-client-keycloak/src/test/java/io/quarkus/it/smallrye/graphql/keycloak/GraphQLAuthExpiryTest.java b/integration-tests/smallrye-graphql-client-keycloak/src/test/java/io/quarkus/it/smallrye/graphql/keycloak/GraphQLAuthExpiryTest.java index 554753d09fc98..01338e9915215 100644 --- a/integration-tests/smallrye-graphql-client-keycloak/src/test/java/io/quarkus/it/smallrye/graphql/keycloak/GraphQLAuthExpiryTest.java +++ b/integration-tests/smallrye-graphql-client-keycloak/src/test/java/io/quarkus/it/smallrye/graphql/keycloak/GraphQLAuthExpiryTest.java @@ -22,8 +22,9 @@ public class GraphQLAuthExpiryTest { @Test public void testDynamicClientWebSocketAuthenticationExpiry() { + String token = KeycloakRealmResourceManager.getAccessToken(); when() - .get("/dynamic-subscription-auth-expiry/" + url.toString()) + .get("/dynamic-subscription-auth-expiry/" + token + "/" + url.toString()) .then() .log().everything() .statusCode(204); diff --git a/integration-tests/smallrye-graphql-client-keycloak/src/test/java/io/quarkus/it/smallrye/graphql/keycloak/KeycloakRealmResourceManager.java b/integration-tests/smallrye-graphql-client-keycloak/src/test/java/io/quarkus/it/smallrye/graphql/keycloak/KeycloakRealmResourceManager.java index 80dd04f08a79e..a527c265f76af 100644 --- a/integration-tests/smallrye-graphql-client-keycloak/src/test/java/io/quarkus/it/smallrye/graphql/keycloak/KeycloakRealmResourceManager.java +++ b/integration-tests/smallrye-graphql-client-keycloak/src/test/java/io/quarkus/it/smallrye/graphql/keycloak/KeycloakRealmResourceManager.java @@ -130,4 +130,17 @@ public void stop() { .when() .delete(KEYCLOAK_SERVER_URL + "/admin/realms/" + KEYCLOAK_REALM).then().statusCode(204); } + + public static String getAccessToken() { + io.restassured.response.Response response = RestAssured.given() + .contentType("application/x-www-form-urlencoded") + .accept("application/json") + .formParam("username", "alice") + .formParam("password", "alice") + .param("client_id", "quarkus-app") + .param("client_secret", "secret") + .formParam("grant_type", "password") + .post(KEYCLOAK_SERVER_URL + "/realms/" + KEYCLOAK_REALM + "/protocol/openid-connect/token"); + return response.getBody().jsonPath().getString("access_token"); + } }