Skip to content

Commit

Permalink
Remove Jadler.
Browse files Browse the repository at this point in the history
  • Loading branch information
Avarjana committed Jul 16, 2024
1 parent c81e793 commit 6ba78cd
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 45 deletions.
21 changes: 16 additions & 5 deletions io.asgardeo.java.oidc.sdk/pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2020, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
~ Copyright (c) 2020-2024, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
~
~ WSO2 Inc. licenses this file to you under the Apache License,
~ Version 2.0 (the "License"); you may not use this file except
Expand Down Expand Up @@ -97,12 +97,23 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.jadler</groupId>
<artifactId>jadler-core</artifactId>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.jadler</groupId>
<artifactId>jadler-jetty</artifactId>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-util</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
* Copyright (c) 2024-2023, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
Expand All @@ -18,6 +18,8 @@

package io.asgardeo.java.oidc.sdk.validators;

import com.github.tomakehurst.wiremock.WireMockServer;
import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
import com.nimbusds.jose.JOSEException;
import com.nimbusds.jose.JWSAlgorithm;
import com.nimbusds.jose.JWSHeader;
Expand All @@ -39,7 +41,6 @@
import com.nimbusds.openid.connect.sdk.claims.IDTokenClaimsSet;
import io.asgardeo.java.oidc.sdk.config.model.OIDCAgentConfig;
import io.asgardeo.java.oidc.sdk.exception.SSOAgentServerException;
import net.jadler.Jadler;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
Expand All @@ -61,43 +62,56 @@
import java.util.List;
import java.util.Set;

import static net.jadler.Jadler.closeJadler;
import static net.jadler.Jadler.initJadler;
import static net.jadler.Jadler.port;
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
import static com.github.tomakehurst.wiremock.client.WireMock.configureFor;
import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching;
import static com.github.tomakehurst.wiremock.client.WireMock.get;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;

public class IDTokenValidatorTest {

private static int SERVER_PORT = 8099;
private OIDCAgentConfig config;
private RSAKey key;
private WireMockServer wireMockServer;
private JWKSet jwkSet;

@BeforeMethod
public void setUp() throws Exception {

initJadler();

config = new OIDCAgentConfig();
JWKSet jwkSet = generateJWKS();
jwkSet = generateJWKS();
key = (RSAKey) jwkSet.getKeys().get(0);

Issuer issuer = new Issuer("issuer");
ClientID clientID = new ClientID("sampleClientId");
Secret clientSecret = new Secret("sampleClientSecret");
URL jwkSetURL = new URL("http://localhost:" + port() + "/jwksEP");
URL jwkSetURL = new URL("http://localhost:" + SERVER_PORT + "/jwksEP");

config.setIssuer(issuer);
config.setConsumerKey(clientID);
config.setConsumerSecret(clientSecret);
config.setJwksEndpoint(jwkSetURL.toURI());

Jadler.onRequest()
.havingMethodEqualTo("GET")
.havingPathEqualTo("/jwksEP")
.respond()
.withStatus(200)
.withHeader("Content-Type", "application/json")
.withBody(jwkSet.toString(true));
initWireMockServer();
}

private void initWireMockServer() {

if (wireMockServer != null && wireMockServer.isRunning()) {
wireMockServer.stop();
}
wireMockServer = new WireMockServer(WireMockConfiguration.wireMockConfig().port(SERVER_PORT));
wireMockServer.start();
configureFor("localhost", SERVER_PORT);

stubFor(get(urlMatching("/jwksEP"))
.willReturn(aResponse()
.withStatus(200)
.withHeader("Content-Type", "application/json")
.withBody(jwkSet.toString(true))));
}

private JWKSet generateJWKS() throws NoSuchAlgorithmException {
Expand Down Expand Up @@ -248,15 +262,9 @@ public Object[][] algorithmData() throws Exception {
@Test(dataProvider = "AlgorithmData")
public void testJWSAlgorithm(String signatureAlgorithm, JWK key) throws JOSEException, SSOAgentServerException {

JWKSet jwkSet = new JWKSet(Collections.singletonList(key));

Jadler.onRequest()
.havingMethodEqualTo("GET")
.havingPathEqualTo("/jwksEP")
.respond()
.withStatus(200)
.withHeader("Content-Type", "application/json")
.withBody(jwkSet.toString(true));
jwkSet = new JWKSet(Collections.singletonList(key));
// Reinitialize the mock server to add jwkSet.
initWireMockServer();

Nonce nonce = new Nonce();
JWSAlgorithm jwsAlgorithm = new JWSAlgorithm(signatureAlgorithm);
Expand Down Expand Up @@ -287,6 +295,6 @@ public void testJWSAlgorithm(String signatureAlgorithm, JWK key) throws JOSEExce
@AfterMethod
public void tearDown() {

closeJadler();
wireMockServer.stop();
}
}
37 changes: 23 additions & 14 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<!--
~ Copyright (c) 2020, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
~ Copyright (c) 2020-2024, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
~
~ WSO2 Inc. licenses this file to you under the Apache License,
~ Version 2.0 (the "License"); you may not use this file except
Expand Down Expand Up @@ -155,20 +155,28 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.jadler</groupId>
<artifactId>jadler-core</artifactId>
<version>${jadler.version}</version>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock</artifactId>
<version>${wiremock.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.jadler</groupId>
<artifactId>jadler-jetty</artifactId>
<version>${jadler.version}</version>
<exclusions>
<exclusion>
<groupId>net.jadler</groupId>
<artifactId>jetty-server</artifactId>
</exclusion>
</exclusions>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>${eclipse.jetty.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>${eclipse.jetty.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-util</artifactId>
<version>${eclipse.jetty.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>
Expand Down Expand Up @@ -257,7 +265,8 @@
<mockito.version>3.5.13</mockito.version>
<mockito.api.version>2.0.7</mockito.api.version>
<mockserver.version>5.15.0</mockserver.version>
<jadler.version>1.3.1</jadler.version>
<wiremock.version>3.0.1</wiremock.version>
<eclipse.jetty.version>11.0.22</eclipse.jetty.version>
</properties>

<modules>
Expand Down

0 comments on commit 6ba78cd

Please sign in to comment.