Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undisable WebAppContextTest.testGetResourcePaths #12502

Merged
merged 2 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions jetty-ee8/jetty-ee8-webapp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@
<directory>${maven.multiModuleProjectDirectory}/jetty-ee9/jetty-ee9-webapp/src/test/webapp-alt-jsp</directory>
<targetPath>webapp-alt-jsp</targetPath>
</resource>
<resource>
<directory>${maven.multiModuleProjectDirectory}/jetty-ee9/jetty-ee9-webapp/src/test/webapp-with-resources</directory>
<targetPath>webapp-with-resources</targetPath>
</resource>
</resources>
</configuration>
</execution>
Expand All @@ -127,6 +131,8 @@
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>@{argLine} ${jetty.surefire.argLine}
--add-exports org.eclipse.jetty.ee8.webapp/org.acme.webapp=org.eclipse.jetty.ee8.servlet
--add-exports org.eclipse.jetty.ee8.webapp/org.acme.webapp=org.eclipse.jetty.ee8.nested
--add-reads org.eclipse.jetty.ee8.webapp=org.eclipse.jetty.logging</argLine>
<useManifestOnlyJar>false</useManifestOnlyJar>
<additionalClasspathElements>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1910,10 +1910,10 @@ public RequestDispatcher getRequestDispatcher(String uriInContext)
@Override
public String getRealPath(String path)
{
// This is an API call from the application which may pass non-canonical paths.
// Thus, we canonicalize here, to avoid the enforcement of canonical paths in
// This is an API call from the application which may pass non-normalized paths.
// Thus, we normalize here, to avoid the enforcement of normalized paths in
// ContextHandler.this.getResource(path).
path = URIUtil.canonicalPath(path);
path = URIUtil.normalizePath(path);
if (path == null)
return null;
if (path.length() == 0)
Expand Down Expand Up @@ -1957,10 +1957,10 @@ else if (path.charAt(0) != '/')
@Override
public URL getResource(String path) throws MalformedURLException
{
// This is an API call from the application which may pass non-canonical paths.
// Thus, we canonicalize here, to avoid the enforcement of canonical paths in
// This is an API call from the application which may pass non-normalized paths.
// Thus, we normalize here, to avoid the enforcement of normalized paths in
// ContextHandler.this.getResource(path).
path = URIUtil.canonicalPath(path);
path = URIUtil.normalizePath(path);
if (path == null)
return null;
Resource resource = ContextHandler.this.getResource(path);
Expand Down Expand Up @@ -1993,10 +1993,10 @@ public InputStream getResourceAsStream(String path)
@Override
public Set<String> getResourcePaths(String path)
{
// This is an API call from the application which may pass non-canonical paths.
// Thus, we canonicalize here, to avoid the enforcement of canonical paths in
// This is an API call from the application which may pass non-normalized paths.
// Thus, we normalize here, to avoid the enforcement of normalized paths in
// ContextHandler.this.getResource(path).
path = URIUtil.canonicalPath(path);
path = URIUtil.normalizePath(path);
if (path == null)
return null;
return ContextHandler.this.getResourcePaths(path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
import org.hamcrest.Matchers;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.parallel.Isolated;
Expand Down Expand Up @@ -117,7 +116,6 @@ public void tearDown()
* @param tempDir the directory into which the war will be generated
* @param name the name of the war
* @return the Path of the generated war
*
* @throws Exception if the war cannot be created
*/
private Path createWar(Path tempDir, String name) throws Exception
Expand Down Expand Up @@ -350,17 +348,17 @@ public void testRealPathDoesNotExist() throws Exception
* @throws Exception on test failure
*/
@Test
@Disabled // No cross context dispatch
public void testContextWhiteList() throws Exception
{
Server server = newServer();
Handler.Sequence handlers = new Handler.Sequence();
WebAppContext contextA = new WebAppContext(".", "/A");
contextA.setCrossContextDispatchSupported(true);

contextA.addServlet(ServletA.class, "/s");
handlers.addHandler(contextA);
WebAppContext contextB = new WebAppContext(".", "/B");

contextB.setCrossContextDispatchSupported(true);
contextB.addServlet(ServletB.class, "/s");
contextB.setContextWhiteList("/doesnotexist", "/B/s");
handlers.addHandler(contextB);
Expand Down Expand Up @@ -456,7 +454,7 @@ public void testProtectedTarget() throws Exception
assertThat(HttpTester.parseResponse(connector.getResponse("GET //WEB-INF/test.xml HTTP/1.1\r\nHost: localhost:8080\r\nConnection: close\r\n\r\n")).getStatus(), is(HttpStatus.NOT_FOUND_404));
assertThat(HttpTester.parseResponse(connector.getResponse("GET /WEB-INF%2ftest.xml HTTP/1.1\r\nHost: localhost:8080\r\nConnection: close\r\n\r\n")).getStatus(), is(HttpStatus.NOT_FOUND_404));
}

@ParameterizedTest
@ValueSource(strings = {
"/WEB-INF",
Expand Down Expand Up @@ -652,14 +650,14 @@ public void testGetResourcePathsWithDirsFromCollection() throws Exception
}

@Test
@Disabled("There is extra decoding of the nested-reserved paths that is getting in the way")
public void testGetResourcePaths() throws Exception
{
Server server = newServer();
LocalConnector connector = new LocalConnector(server);
server.addConnector(connector);

Path warRoot = MavenPaths.findTestResourceDir("webapp-with-resources");

Path warRoot = MavenTestingUtils.getTargetPath("test-classes/webapp-with-resources");
assertTrue(Files.isDirectory(warRoot), "Unable to find directory: " + warRoot);
WebAppContext context = new WebAppContext();
Resource warResource = context.getResourceFactory().newResource(warRoot);
Expand Down Expand Up @@ -697,8 +695,6 @@ public void testGetResourcePaths() throws Exception

assertThat(response1.getStatus(), is(HttpStatus.OK_200));
assertThat(response1.getContent(), containsString("/WEB-INF"));
assertThat(response1.getContent(), containsString("/WEB-INF/lib"));
assertThat(response1.getContent(), containsString("/WEB-INF/lib/odd-resource.jar"));
assertThat(response1.getContent(), containsString("/nested-reserved-!#\\\\$%&()*+,:=?@[]-meta-inf-resource.txt"));

HttpTester.Response response2 = HttpTester.parseResponse(connector.getResponse("""
Expand Down Expand Up @@ -877,8 +873,10 @@ public void testAddServerClasses() throws Exception
assertThat("Should have environment specific test pattern", serverClasses, hasItem(testPattern));
assertThat("Should have pattern from defaults", serverClasses, hasItem("org.eclipse.jetty."));
assertThat("Should have pattern from JaasConfiguration", serverClasses, hasItem("-org.eclipse.jetty.security.jaas."));
for (String defaultServerClass: WebAppClassLoading.DEFAULT_HIDDEN_CLASSES)
for (String defaultServerClass : WebAppClassLoading.DEFAULT_HIDDEN_CLASSES)
{
assertThat("Should have default patterns", serverClasses, hasItem(defaultServerClass));
}
assertThat("deprecated API", serverClasses, hasItem("org.deprecated.api."));
}

Expand Down Expand Up @@ -911,7 +909,9 @@ public void testAddSystemClasses() throws Exception
assertThat("Should have pattern from defaults", systemClasses, hasItem("jakarta."));
assertThat("Should have pattern from JaasConfiguration", systemClasses, hasItem("org.eclipse.jetty.security.jaas."));
for (String defaultSystemClass : WebAppClassLoading.DEFAULT_PROTECTED_CLASSES)
{
assertThat("Should have default patterns", systemClasses, hasItem(defaultSystemClass));
}
assertThat("deprecated API", systemClasses, hasItem("org.deprecated.api."));
}
}
Loading