Skip to content

Commit

Permalink
Fix native mode GraphQLAuthExpiryIT
Browse files Browse the repository at this point in the history
  • Loading branch information
jmartisk committed Nov 16, 2023
1 parent 631a307 commit c1fde71
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 25 deletions.
13 changes: 13 additions & 0 deletions integration-tests/smallrye-graphql-client-keycloak/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,14 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-oidc</artifactId>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>

<dependency>
Expand Down Expand Up @@ -85,7 +90,15 @@
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-oidc-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()) {
Expand Down Expand Up @@ -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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}

0 comments on commit c1fde71

Please sign in to comment.