Skip to content

Commit

Permalink
Merge pull request #1485 from sberyozkin/fix_oidc_code_flow_tests
Browse files Browse the repository at this point in the history
Fix OIDC web authentication and multi-tenancy quickstarts
  • Loading branch information
rsvoboda authored Jan 3, 2025
2 parents ea20946 + 9a7bd95 commit 9d681f9
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 49 deletions.
14 changes: 2 additions & 12 deletions security-openid-connect-multi-tenancy-quickstart/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<htmlunit.version>2.36.0</htmlunit.version>
<htmlunit.version>4.7.0</htmlunit.version>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -59,20 +59,10 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.sourceforge.htmlunit</groupId>
<groupId>org.htmlunit</groupId>
<artifactId>htmlunit</artifactId>
<version>${htmlunit.version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
</exclusion>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>

</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ quarkus.http.auth.permission.public.policy=permit

quarkus.keycloak.devservices.realm-path=default-tenant-realm.json,tenant-a-realm.json

quarkus.log.category."com.gargoylesoftware.htmlunit".level=ERROR
quarkus.log.category."org.htmlunit".level=ERROR
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

import org.junit.jupiter.api.Test;

import com.gargoylesoftware.htmlunit.SilentCssErrorHandler;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import org.htmlunit.SilentCssErrorHandler;
import org.htmlunit.WebClient;
import org.htmlunit.html.HtmlForm;
import org.htmlunit.html.HtmlPage;

import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.keycloak.client.KeycloakTestClient;
Expand All @@ -34,9 +34,9 @@ public void testLogInDefaultTenant() throws IOException {
loginForm.getInputByName("username").setValueAttribute("alice");
loginForm.getInputByName("password").setValueAttribute("alice");

page = loginForm.getInputByName("login").click();
page = loginForm.getButtonByName("login").click();

assertTrue(page.asText().contains("tenant"));
assertTrue(page.asNormalizedText().contains("tenant"));

webClient.getCookieManager().clearCookies();
}
Expand All @@ -54,9 +54,9 @@ public void testLogInTenantAWebApp() throws IOException {
loginForm.getInputByName("username").setValueAttribute("alice");
loginForm.getInputByName("password").setValueAttribute("alice");

page = loginForm.getInputByName("login").click();
page = loginForm.getButtonByName("login").click();

assertTrue(page.asText().contains("[email protected]"));
assertTrue(page.asNormalizedText().contains("[email protected]"));
webClient.getCookieManager().clearCookies();
}
}
Expand All @@ -83,9 +83,9 @@ public void testReAuthenticateWhenSwitchingTenants() throws IOException {
loginForm.getInputByName("username").setValueAttribute("alice");
loginForm.getInputByName("password").setValueAttribute("alice");

page = loginForm.getInputByName("login").click();
page = loginForm.getButtonByName("login").click();

assertTrue(page.asText().contains("[email protected]"));
assertTrue(page.asNormalizedText().contains("[email protected]"));

page = webClient.getPage("http://localhost:8081/default");

Expand All @@ -96,9 +96,9 @@ public void testReAuthenticateWhenSwitchingTenants() throws IOException {
loginForm.getInputByName("username").setValueAttribute("alice");
loginForm.getInputByName("password").setValueAttribute("alice");

page = loginForm.getInputByName("login").click();
page = loginForm.getButtonByName("login").click();

assertTrue(page.asText().contains("[email protected]"));
assertTrue(page.asNormalizedText().contains("[email protected]"));

webClient.getCookieManager().clearCookies();
}
Expand Down
14 changes: 2 additions & 12 deletions security-openid-connect-web-authentication-quickstart/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<htmlunit.version>2.36.0</htmlunit.version>
<htmlunit.version>4.7.0</htmlunit.version>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -57,20 +57,10 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.sourceforge.htmlunit</groupId>
<groupId>org.htmlunit</groupId>
<artifactId>htmlunit</artifactId>
<version>${htmlunit.version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
</exclusion>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ quarkus.http.auth.permission.authenticated.paths=/*
quarkus.http.auth.permission.authenticated.policy=authenticated
quarkus.http.auth.permission.public.paths=/q*
quarkus.http.auth.permission.public.policy=permit
quarkus.log.category."com.gargoylesoftware.htmlunit".level=ERROR
quarkus.log.category."org.htmlunit".level=ERROR
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@

import org.junit.jupiter.api.Test;

import com.gargoylesoftware.htmlunit.SilentCssErrorHandler;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.util.Cookie;
import org.htmlunit.SilentCssErrorHandler;
import org.htmlunit.WebClient;
import org.htmlunit.html.HtmlForm;
import org.htmlunit.html.HtmlPage;
import org.htmlunit.util.Cookie;

import io.quarkus.test.junit.QuarkusTest;

Expand All @@ -38,7 +38,7 @@ public void testCodeFlowNoConsent() throws IOException {
loginForm.getInputByName("username").setValueAttribute("alice");
loginForm.getInputByName("password").setValueAttribute("alice");

page = loginForm.getInputByName("login").click();
page = loginForm.getButtonByName("login").click();

assertEquals("Welcome to Your Quarkus Application", page.getTitleText());

Expand Down Expand Up @@ -68,7 +68,7 @@ public void testTokenTimeoutLogout() throws IOException, InterruptedException {
loginForm.getInputByName("username").setValueAttribute("alice");
loginForm.getInputByName("password").setValueAttribute("alice");

page = loginForm.getInputByName("login").click();
page = loginForm.getButtonByName("login").click();

assertEquals("Welcome to Your Quarkus Application", page.getTitleText());

Expand Down Expand Up @@ -125,15 +125,16 @@ public void testTokenInjection() throws IOException {
loginForm.getInputByName("username").setValueAttribute("alice");
loginForm.getInputByName("password").setValueAttribute("alice");

page = loginForm.getInputByName("login").click();
page = loginForm.getButtonByName("login").click();

assertEquals("Welcome to Your Quarkus Application", page.getTitleText());

page = webClient.getPage("http://localhost:8081/tokens");

assertTrue(page.getBody().asText().contains("username"));
assertTrue(page.getBody().asText().contains("scopes"));
assertTrue(page.getBody().asText().contains("refresh_token: true"));
String text = page.getBody().asNormalizedText();
assertTrue(text.contains("username"));
assertTrue(text.contains("scopes"));
assertTrue(text.contains("refresh_token: true"));

assertNotNull(getSessionCookie(webClient));
assertNull(getStateCookies(webClient));
Expand Down

0 comments on commit 9d681f9

Please sign in to comment.