From 90235e6451a8176cd45c49489cbd29ea275f9d20 Mon Sep 17 00:00:00 2001 From: Bauke Scholtz Date: Fri, 13 Sep 2024 14:39:22 -0400 Subject: [PATCH] Add IT for #5503 --- .../org/eclipse/mojarra/test/base/BaseIT.java | 23 +++++ test/issue5503/pom.xml | 41 ++++++++ .../mojarra/test/issue5503/Issue5503Bean.java | 25 +++++ .../issue5503-ProtectedViewException.xhtml | 30 ++++++ .../src/main/webapp/WEB-INF/faces-config.xml | 11 +++ .../issue5503/src/main/webapp/WEB-INF/web.xml | 41 ++++++++ .../src/main/webapp/issue5503-protected.xhtml | 32 +++++++ .../main/webapp/issue5503-unprotected.xhtml | 32 +++++++ .../mojarra/test/issue5503/Issue5503IT.java | 93 +++++++++++++++++++ test/pom.xml | 1 + 10 files changed, 329 insertions(+) create mode 100644 test/issue5503/pom.xml create mode 100644 test/issue5503/src/main/java/org/eclipse/mojarra/test/issue5503/Issue5503Bean.java create mode 100644 test/issue5503/src/main/webapp/WEB-INF/errorpages/issue5503-ProtectedViewException.xhtml create mode 100644 test/issue5503/src/main/webapp/WEB-INF/faces-config.xml create mode 100644 test/issue5503/src/main/webapp/WEB-INF/web.xml create mode 100644 test/issue5503/src/main/webapp/issue5503-protected.xhtml create mode 100644 test/issue5503/src/main/webapp/issue5503-unprotected.xhtml create mode 100644 test/issue5503/src/test/java/org/eclipse/mojarra/test/issue5503/Issue5503IT.java diff --git a/test/base/src/main/java/org/eclipse/mojarra/test/base/BaseIT.java b/test/base/src/main/java/org/eclipse/mojarra/test/base/BaseIT.java index a4cc379052..1978a849fd 100644 --- a/test/base/src/main/java/org/eclipse/mojarra/test/base/BaseIT.java +++ b/test/base/src/main/java/org/eclipse/mojarra/test/base/BaseIT.java @@ -24,6 +24,7 @@ import java.util.UUID; import java.util.function.BooleanSupplier; import java.util.logging.Level; +import java.util.regex.Pattern; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit5.ArquillianExtension; @@ -37,6 +38,7 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeOptions; import org.openqa.selenium.support.PageFactory; @@ -88,10 +90,31 @@ protected void open(String resource) { browser.get(baseURL + resource); } + protected String getPageTitle() { + return browser.getTitle(); + } + protected String getPageSource() { return browser.getPageSource(); } + protected String getHrefURI(WebElement link) { + String uri = link.getAttribute("href").substring(baseURL.toExternalForm().length()); + String uriWithoutJsessionId = uri.split(";jsessionid=", 2)[0]; + String[] uriAndQueryString = uri.split(Pattern.quote("?"), 2); + + if (uriAndQueryString.length == 2) { + uriWithoutJsessionId += "?" + uriAndQueryString[1]; + } + + return uriWithoutJsessionId; + } + + protected void guardHttp(Runnable action) { + action.run(); + waitUntil(() -> executeScript("return document.readyState=='complete'")); + } + protected void guardAjax(Runnable action) { String uuid = UUID.randomUUID().toString(); executeScript("window.$ajax = true; faces.ajax.addOnEvent(data => { if (data.status == 'complete') window.$ajax = '" + uuid + "'; })"); diff --git a/test/issue5503/pom.xml b/test/issue5503/pom.xml new file mode 100644 index 0000000000..400074772f --- /dev/null +++ b/test/issue5503/pom.xml @@ -0,0 +1,41 @@ + + + + 4.0.0 + + + org.eclipse.mojarra.test + pom + 4.0.9-SNAPSHOT + + + issue5503 + war + + Mojarra ${project.version} - INTEGRATION TESTS - ${project.artifactId} + + + + org.eclipse.mojarra.test + base + ${project.version} + test + + + diff --git a/test/issue5503/src/main/java/org/eclipse/mojarra/test/issue5503/Issue5503Bean.java b/test/issue5503/src/main/java/org/eclipse/mojarra/test/issue5503/Issue5503Bean.java new file mode 100644 index 0000000000..863b5bf39b --- /dev/null +++ b/test/issue5503/src/main/java/org/eclipse/mojarra/test/issue5503/Issue5503Bean.java @@ -0,0 +1,25 @@ +/* + * Copyright (c) Contributors to the Eclipse Foundation. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 + * which is available at https://www.apache.org/licenses/LICENSE-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the Eclipse + * Public License v. 2.0 are satisfied: GPL-2.0 with Classpath-exception-2.0 which + * is available at https://openjdk.java.net/legal/gplv2+ce.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 or Apache-2.0 + */ +package org.eclipse.mojarra.test.issue5503; + +import jakarta.enterprise.context.RequestScoped; +import jakarta.inject.Named; + +@Named +@RequestScoped +public class Issue5503Bean { + +} diff --git a/test/issue5503/src/main/webapp/WEB-INF/errorpages/issue5503-ProtectedViewException.xhtml b/test/issue5503/src/main/webapp/WEB-INF/errorpages/issue5503-ProtectedViewException.xhtml new file mode 100644 index 0000000000..2729763738 --- /dev/null +++ b/test/issue5503/src/main/webapp/WEB-INF/errorpages/issue5503-ProtectedViewException.xhtml @@ -0,0 +1,30 @@ + + + + + issue5503 - ProtectedViewException + + +

issue5503 - ProtectedViewException

+
+ diff --git a/test/issue5503/src/main/webapp/WEB-INF/faces-config.xml b/test/issue5503/src/main/webapp/WEB-INF/faces-config.xml new file mode 100644 index 0000000000..9b3563a11f --- /dev/null +++ b/test/issue5503/src/main/webapp/WEB-INF/faces-config.xml @@ -0,0 +1,11 @@ + + + + /issue5503-protected.xhtml + + diff --git a/test/issue5503/src/main/webapp/WEB-INF/web.xml b/test/issue5503/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000..943813c0a7 --- /dev/null +++ b/test/issue5503/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,41 @@ + + + + + facesServlet + jakarta.faces.webapp.FacesServlet + 1 + + + facesServlet + *.xhtml + *.jsf + /faces/* + + + + jakarta.faces.application.ProtectedViewException + /WEB-INF/errorpages/issue5503-ProtectedViewException.xhtml + + diff --git a/test/issue5503/src/main/webapp/issue5503-protected.xhtml b/test/issue5503/src/main/webapp/issue5503-protected.xhtml new file mode 100644 index 0000000000..f9e328d93a --- /dev/null +++ b/test/issue5503/src/main/webapp/issue5503-protected.xhtml @@ -0,0 +1,32 @@ + + + + + issue5503 - protected view + + +

issue5503 - protected view

+ + +
+ diff --git a/test/issue5503/src/main/webapp/issue5503-unprotected.xhtml b/test/issue5503/src/main/webapp/issue5503-unprotected.xhtml new file mode 100644 index 0000000000..ba739ffd84 --- /dev/null +++ b/test/issue5503/src/main/webapp/issue5503-unprotected.xhtml @@ -0,0 +1,32 @@ + + + + + issue5503 - unprotected view + + +

issue5503 - unprotected view

+ + +
+ diff --git a/test/issue5503/src/test/java/org/eclipse/mojarra/test/issue5503/Issue5503IT.java b/test/issue5503/src/test/java/org/eclipse/mojarra/test/issue5503/Issue5503IT.java new file mode 100644 index 0000000000..6581157a15 --- /dev/null +++ b/test/issue5503/src/test/java/org/eclipse/mojarra/test/issue5503/Issue5503IT.java @@ -0,0 +1,93 @@ +/* + * Copyright (c) Contributors to the Eclipse Foundation. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 + * which is available at https://www.apache.org/licenses/LICENSE-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the Eclipse + * Public License v. 2.0 are satisfied: GPL-2.0 with Classpath-exception-2.0 which + * is available at https://openjdk.java.net/legal/gplv2+ce.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 or Apache-2.0 + */ +package org.eclipse.mojarra.test.issue5503; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.eclipse.mojarra.test.base.BaseIT; +import org.junit.jupiter.api.Test; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.FindBy; + +/** + * https://github.com/eclipse-ee4j/mojarra/issues/5503 + */ +class Issue5503IT extends BaseIT { + + @FindBy(id = "protectedViewLink") + private WebElement protectedViewLink; + + @FindBy(id = "unprotectedViewLink") + private WebElement unprotectedViewLink; + + @Test + void testOpeningProtectedViewWithXhtmlMapping() { + open("issue5503-protected.xhtml"); + assertEquals("issue5503 - ProtectedViewException", getPageTitle()); + } + + @Test + void testOpeningProtectedViewWithJsfMapping() { + open("issue5503-protected.jsf"); + assertEquals("issue5503 - ProtectedViewException", getPageTitle()); + } + + @Test + void testOpeningProtectedViewWithFacesMapping() { + open("faces/issue5503-protected.xhtml"); + assertEquals("issue5503 - ProtectedViewException", getPageTitle()); + } + + @Test + void testLinkingProtectedViewWithXhtmlMapping() { + open("issue5503-unprotected.xhtml"); + assertEquals("issue5503 - unprotected view", getPageTitle()); + assertEquals("issue5503-unprotected.xhtml", getHrefURI(unprotectedViewLink)); + assertTrue(getHrefURI(protectedViewLink).startsWith("issue5503-protected.xhtml?jakarta.faces.Token="), "'" + getHrefURI(protectedViewLink) + "' starts with 'issue5503-protected.xhtml?jakarta.faces.Token='"); + + guardHttp(protectedViewLink::click); + assertEquals("issue5503 - protected view", getPageTitle()); + assertEquals("issue5503-unprotected.xhtml", getHrefURI(unprotectedViewLink)); + assertTrue(getHrefURI(protectedViewLink).startsWith("issue5503-protected.xhtml?jakarta.faces.Token="), "'" + getHrefURI(protectedViewLink) + "' starts with 'issue5503-protected.xhtml?jakarta.faces.Token='"); + } + + @Test + void testLinkingProtectedViewWithJsfMapping() { + open("issue5503-unprotected.jsf"); + assertEquals("issue5503 - unprotected view", getPageTitle()); + assertEquals("issue5503-unprotected.jsf", getHrefURI(unprotectedViewLink)); + assertTrue(getHrefURI(protectedViewLink).startsWith("issue5503-protected.jsf?jakarta.faces.Token="), "'" + getHrefURI(protectedViewLink) + "' starts with 'issue5503-protected.jsf?jakarta.faces.Token='"); + + guardHttp(protectedViewLink::click); + assertEquals("issue5503 - protected view", getPageTitle()); + assertEquals("issue5503-unprotected.jsf", getHrefURI(unprotectedViewLink)); + assertTrue(getHrefURI(protectedViewLink).startsWith("issue5503-protected.jsf?jakarta.faces.Token="), "'" + getHrefURI(protectedViewLink) + "' starts with 'issue5503-protected.jsf?jakarta.faces.Token='"); + } + + @Test + void testLinkingProtectedViewWithFacesMapping() { + open("faces/issue5503-unprotected.xhtml"); + assertEquals("issue5503 - unprotected view", getPageTitle()); + assertEquals("faces/issue5503-unprotected.xhtml", getHrefURI(unprotectedViewLink)); + assertTrue(getHrefURI(protectedViewLink).startsWith("faces/issue5503-protected.xhtml?jakarta.faces.Token="), "'" + getHrefURI(protectedViewLink) + "' starts with 'faces/issue5503-protected.xhtml?jakarta.faces.Token='"); + + guardHttp(protectedViewLink::click); + assertEquals("issue5503 - protected view", getPageTitle()); + assertEquals("faces/issue5503-unprotected.xhtml", getHrefURI(unprotectedViewLink)); + assertTrue(getHrefURI(protectedViewLink).startsWith("faces/issue5503-protected.xhtml?jakarta.faces.Token="), "'" + getHrefURI(protectedViewLink) + "' starts with 'faces/issue5503-protected.xhtml?jakarta.faces.Token='"); + } +} diff --git a/test/pom.xml b/test/pom.xml index 5c4dc262c4..4c7a1133cb 100644 --- a/test/pom.xml +++ b/test/pom.xml @@ -36,6 +36,7 @@ issue5460 issue5464 issue5488 + issue5503