Skip to content

Commit 139b286

Browse files
committed
Fixed: OIDCAuthenticationProviderFactoryIT to work with Keycloak 26.1.4
1 parent 7b413f9 commit 139b286

2 files changed

Lines changed: 11 additions & 16 deletions

File tree

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,7 @@
733733
<dependency>
734734
<groupId>com.github.dasniko</groupId>
735735
<artifactId>testcontainers-keycloak</artifactId>
736-
<version>3.0.0</version>
736+
<version>3.6.0</version>
737737
<scope>test</scope>
738738
</dependency>
739739
<dependency>

src/test/java/edu/harvard/iq/dataverse/authorization/providers/oauth2/oidc/OIDCAuthenticationProviderFactoryIT.java

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@
1919
import org.htmlunit.FailingHttpStatusCodeException;
2020
import org.htmlunit.WebClient;
2121
import org.htmlunit.WebResponse;
22-
import org.htmlunit.html.HtmlForm;
23-
import org.htmlunit.html.HtmlInput;
24-
import org.htmlunit.html.HtmlPage;
25-
import org.htmlunit.html.HtmlSubmitInput;
22+
import org.htmlunit.html.*;
2623
import org.junit.jupiter.api.Tag;
2724
import org.junit.jupiter.api.Test;
2825
import org.junit.jupiter.api.extension.ExtendWith;
@@ -69,7 +66,7 @@ class OIDCAuthenticationProviderFactoryIT {
6966

7067
// The realm JSON resides in conf/keycloak/test-realm.json and gets avail here using <testResources> in pom.xml
7168
@Container
72-
static KeycloakContainer keycloakContainer = new KeycloakContainer("quay.io/keycloak/keycloak:22.0")
69+
static KeycloakContainer keycloakContainer = new KeycloakContainer("quay.io/keycloak/keycloak:26.1.4")
7370
.withRealmImportFile("keycloak/test-realm.json")
7471
.withAdminUsername(adminUser)
7572
.withAdminPassword(adminPassword);
@@ -186,8 +183,7 @@ void testAuthorizationCodeFlowWithPKCE() throws Exception {
186183

187184
OIDCAuthProvider oidcAuthProvider = getProvider();
188185
String authzUrl = oidcAuthProvider.buildAuthzUrl(state, callbackUrl);
189-
//System.out.println(authzUrl);
190-
186+
191187
try (WebClient webClient = new WebClient()) {
192188
webClient.getOptions().setCssEnabled(false);
193189
webClient.getOptions().setJavaScriptEnabled(false);
@@ -200,27 +196,26 @@ void testAuthorizationCodeFlowWithPKCE() throws Exception {
200196
HtmlForm form = loginPage.getForms().get(0);
201197
HtmlInput username = form.getInputByName("username");
202198
HtmlInput password = form.getInputByName("password");
203-
HtmlSubmitInput submit = form.getInputByName("login");
204-
199+
HtmlButton submitButton = (HtmlButton) loginPage.getElementById("kc-login");
200+
205201
username.type(realmAdminUser);
206202
password.type(realmAdminPassword);
207-
208-
FailingHttpStatusCodeException exception = assertThrows(FailingHttpStatusCodeException.class, submit::click);
203+
204+
FailingHttpStatusCodeException exception = assertThrows(FailingHttpStatusCodeException.class, submitButton::click);
209205
assertEquals(302, exception.getStatusCode());
210206

211207
WebResponse response = exception.getResponse();
212208
assertNotNull(response);
213209

214210
String callbackLocation = response.getResponseHeaderValue("Location");
215211
assertTrue(callbackLocation.startsWith(callbackUrl));
216-
//System.out.println(callbackLocation);
217-
212+
218213
String queryPart = callbackLocation.trim().split("\\?")[1];
219214
Map<String,String> parameters = Pattern.compile("\\s*&\\s*")
220215
.splitAsStream(queryPart)
221216
.map(s -> s.split("=", 2))
222217
.collect(Collectors.toMap(a -> a[0], a -> a.length > 1 ? a[1]: ""));
223-
//System.out.println(map);
218+
224219
assertTrue(parameters.containsKey("code"));
225220
assertTrue(parameters.containsKey("state"));
226221

@@ -237,4 +232,4 @@ void testAuthorizationCodeFlowWithPKCE() throws Exception {
237232
throw e;
238233
}
239234
}
240-
}
235+
}

0 commit comments

Comments
 (0)