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

Simplify wiremock config in oidc #35749

Merged
merged 2 commits into from
Sep 9, 2023
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
2 changes: 1 addition & 1 deletion build-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@

<assertj.version>3.24.2</assertj.version>

<wiremock.version>3.0.0</wiremock.version>
<wiremock.version>3.0.3</wiremock.version>
<wiremock-maven-plugin.version>7.3.0</wiremock-maven-plugin.version>

<!-- Artemis test dependencies -->
Expand Down
2 changes: 1 addition & 1 deletion independent-projects/tools/analytics-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<properties>
<segment.analytics.version>3.3.1</segment.analytics.version>
<httpclient.version>4.5.14</httpclient.version>
<wiremock.version>3.0.0</wiremock.version>
<wiremock.version>3.0.3</wiremock.version>
<commons-logging-jboss-logging.version>1.0.0.Final</commons-logging-jboss-logging.version>
</properties>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static com.github.tomakehurst.wiremock.client.WireMock.containing;
import static com.github.tomakehurst.wiremock.client.WireMock.get;
import static com.github.tomakehurst.wiremock.client.WireMock.matching;
import static com.github.tomakehurst.wiremock.client.WireMock.post;
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
import static com.github.tomakehurst.wiremock.client.WireMock.urlPathMatching;
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
Expand All @@ -12,7 +13,6 @@

import java.security.cert.X509Certificate;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
Expand All @@ -25,10 +25,6 @@
import org.jose4j.keys.X509Util;

import com.github.tomakehurst.wiremock.WireMockServer;
import com.github.tomakehurst.wiremock.client.WireMock;
import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
import com.github.tomakehurst.wiremock.extension.responsetemplating.ResponseTemplateTransformer;
import com.github.tomakehurst.wiremock.extension.responsetemplating.TemplateEngine;
import com.google.common.collect.ImmutableSet;

import io.quarkus.test.common.QuarkusTestResourceLifecycleManager;
Expand All @@ -55,11 +51,7 @@ public class OidcWiremockTestResource implements QuarkusTestResourceLifecycleMan
@Override
public Map<String, String> start() {

WireMockConfiguration wireMockConfiguration = wireMockConfig();
server = new WireMockServer(wireMockConfiguration
.extensions(new ResponseTemplateTransformer(TemplateEngine.defaultTemplateEngine(), false,
wireMockConfiguration.filesRoot(), Collections.emptyList()))
.dynamicPort());
server = new WireMockServer(wireMockConfig().dynamicPort());
server.start();

server.stubFor(
Expand Down Expand Up @@ -245,10 +237,9 @@ private void defineUserInfoStubForJwt() {

private void defineValidIntrospectionMockTokenStubForUserWithRoles(String user, Set<String> roles) {
long exp = now() + 300;
server.stubFor(WireMock.post("/auth/realms/quarkus/protocol/openid-connect/token/introspect")
server.stubFor(post("/auth/realms/quarkus/protocol/openid-connect/token/introspect")
.withRequestBody(matching("token=" + user + "&token_type_hint=access_token"))
.willReturn(WireMock
.aResponse()
.willReturn(aResponse()
.withHeader("Content-Type", "application/json")
.withBody(
"{\"active\":true,\"scope\":\"" + roles.stream().collect(joining(" ")) + "\",\"username\":\""
Expand All @@ -262,10 +253,9 @@ private static final long now() {
}

private void defineInvalidIntrospectionMockTokenStubForUserWithRoles(String user, Set<String> roles) {
server.stubFor(WireMock.post("/auth/realms/quarkus/protocol/openid-connect/token/introspect")
server.stubFor(post("/auth/realms/quarkus/protocol/openid-connect/token/introspect")
.withRequestBody(matching("token=" + user + "&token_type_hint=access_token"))
.willReturn(WireMock
.aResponse()
.willReturn(aResponse()
.withHeader("Content-Type", "application/json")
.withBody(
"{\"active\":true,\"scope\":\"" + roles.stream().collect(joining(" ")) + "\",\"username\":\""
Expand All @@ -274,14 +264,14 @@ private void defineInvalidIntrospectionMockTokenStubForUserWithRoles(String user
}

private void defineJwtBearerGrantTokenStub() {
server.stubFor(WireMock.post("/auth/realms/quarkus/jwt-bearer-token")
server.stubFor(post("/auth/realms/quarkus/jwt-bearer-token")
.withRequestBody(containing("client_id=quarkus-app"))
.withRequestBody(containing("client_secret=secret"))
.withRequestBody(containing("grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Ajwt-bearer"))
.withRequestBody(containing("scope=https%3A%2F%2Fgraph.microsoft.com%2Fuser.read+offline_access"))
.withRequestBody(containing("requested_token_use=on_behalf_of"))
.withRequestBody(containing("assertion"))
.willReturn(WireMock.aResponse()
.willReturn(aResponse()
.withHeader("Content-Type", "application/json")
.withBody("{\n" +
" \"access_token\": \""
Expand All @@ -290,9 +280,9 @@ private void defineJwtBearerGrantTokenStub() {
}

private void defineCodeFlowAuthorizationMockTokenStub() {
server.stubFor(WireMock.post("/auth/realms/quarkus/token")
server.stubFor(post("/auth/realms/quarkus/token")
.withRequestBody(containing("authorization_code"))
.willReturn(WireMock.aResponse()
.willReturn(aResponse()
.withHeader("Content-Type", "application/json")
.withBody("{\n" +
" \"access_token\": \""
Expand All @@ -304,9 +294,9 @@ private void defineCodeFlowAuthorizationMockTokenStub() {
}

private void defineCodeFlowAuthorizationMockEncryptedTokenStub() {
server.stubFor(WireMock.post("/auth/realms/quarkus/encrypted-id-token")
server.stubFor(post("/auth/realms/quarkus/encrypted-id-token")
.withRequestBody(containing("authorization_code"))
.willReturn(WireMock.aResponse()
.willReturn(aResponse()
.withHeader("Content-Type", "application/json")
.withBody("{\n" +
" \"access_token\": \""
Expand Down
Loading