Skip to content

Commit

Permalink
Add IT for #5503
Browse files Browse the repository at this point in the history
  • Loading branch information
BalusC committed Sep 13, 2024
1 parent 8810b7f commit 90235e6
Show file tree
Hide file tree
Showing 10 changed files with 329 additions and 0 deletions.
23 changes: 23 additions & 0 deletions test/base/src/main/java/org/eclipse/mojarra/test/base/BaseIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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 + "'; })");
Expand Down
41 changes: 41 additions & 0 deletions test/issue5503/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) Contributors to 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
http://www.eclipse.org/legal/epl-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: GNU General Public License,
version 2 with the GNU Classpath Exception, which is available at
https://www.gnu.org/software/classpath/license.html.
SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.eclipse.mojarra.test</groupId>
<artifactId>pom</artifactId>
<version>4.0.9-SNAPSHOT</version>
</parent>

<artifactId>issue5503</artifactId>
<packaging>war</packaging>

<name>Mojarra ${project.version} - INTEGRATION TESTS - ${project.artifactId}</name>

<dependencies>
<dependency>
<groupId>org.eclipse.mojarra.test</groupId>
<artifactId>base</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -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 {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!DOCTYPE html>
<!--
Copyright (c) Contributors to 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
http://www.eclipse.org/legal/epl-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: GNU General Public License,
version 2 with the GNU Classpath Exception, which is available at
https://www.gnu.org/software/classpath/license.html.
SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
-->
<html lang="en"
xmlns:h="jakarta.faces.html"
xmlns:f="jakarta.faces.core"
xmlns:ui="jakarta.faces.facelets"
>
<h:head>
<title>issue5503 - ProtectedViewException</title>
</h:head>
<h:body>
<h1>issue5503 - ProtectedViewException</h1>
</h:body>
</html>
11 changes: 11 additions & 0 deletions test/issue5503/src/main/webapp/WEB-INF/faces-config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<faces-config
xmlns="https://jakarta.ee/xml/ns/jakartaee"
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-facesconfig_4_0.xsd"
version="4.0"
>
<protected-views>
<url-pattern>/issue5503-protected.xhtml</url-pattern>
</protected-views>
</faces-config>
41 changes: 41 additions & 0 deletions test/issue5503/src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) Contributors to 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
http://www.eclipse.org/legal/epl-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: GNU General Public License,
version 2 with the GNU Classpath Exception, which is available at
https://www.gnu.org/software/classpath/license.html.
SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
-->
<web-app
xmlns="https://jakarta.ee/xml/ns/jakartaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd"
version="5.0"
>
<servlet>
<servlet-name>facesServlet</servlet-name>
<servlet-class>jakarta.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>facesServlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
<url-pattern>*.jsf</url-pattern>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>

<error-page>
<exception-type>jakarta.faces.application.ProtectedViewException</exception-type>
<location>/WEB-INF/errorpages/issue5503-ProtectedViewException.xhtml</location>
</error-page>
</web-app>
32 changes: 32 additions & 0 deletions test/issue5503/src/main/webapp/issue5503-protected.xhtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!DOCTYPE html>
<!--
Copyright (c) Contributors to 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
http://www.eclipse.org/legal/epl-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: GNU General Public License,
version 2 with the GNU Classpath Exception, which is available at
https://www.gnu.org/software/classpath/license.html.
SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
-->
<html lang="en"
xmlns:h="jakarta.faces.html"
xmlns:f="jakarta.faces.core"
xmlns:ui="jakarta.faces.facelets"
>
<h:head>
<title>issue5503 - protected view</title>
</h:head>
<h:body>
<h1>issue5503 - protected view</h1>
<h:link id="unprotectedViewLink" value="unprotected view" outcome="issue5503-unprotected" />
<h:link id="protectedViewLink" value="protected view" outcome="issue5503-protected" />
</h:body>
</html>
32 changes: 32 additions & 0 deletions test/issue5503/src/main/webapp/issue5503-unprotected.xhtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!DOCTYPE html>
<!--
Copyright (c) Contributors to 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
http://www.eclipse.org/legal/epl-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: GNU General Public License,
version 2 with the GNU Classpath Exception, which is available at
https://www.gnu.org/software/classpath/license.html.
SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
-->
<html lang="en"
xmlns:h="jakarta.faces.html"
xmlns:f="jakarta.faces.core"
xmlns:ui="jakarta.faces.facelets"
>
<h:head>
<title>issue5503 - unprotected view</title>
</h:head>
<h:body>
<h1>issue5503 - unprotected view</h1>
<h:link id="unprotectedViewLink" value="unprotected view" outcome="issue5503-unprotected" />
<h:link id="protectedViewLink" value="protected view" outcome="issue5503-protected" />
</h:body>
</html>
Original file line number Diff line number Diff line change
@@ -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='");
}
}
1 change: 1 addition & 0 deletions test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<module>issue5460</module>
<module>issue5464</module>
<module>issue5488</module>
<module>issue5503</module>
</modules>

<properties>
Expand Down

0 comments on commit 90235e6

Please sign in to comment.