|
| 1 | +/* |
| 2 | + * eXist-db Open Source Native XML Database |
| 3 | + * Copyright (C) 2001 The eXist-db Authors |
| 4 | + * |
| 5 | + * info@exist-db.org |
| 6 | + * http://www.exist-db.org |
| 7 | + * |
| 8 | + * This library is free software; you can redistribute it and/or |
| 9 | + * modify it under the terms of the GNU Lesser General Public |
| 10 | + * License as published by the Free Software Foundation; either |
| 11 | + * version 2.1 of the License, or (at your option) any later version. |
| 12 | + * |
| 13 | + * This library is distributed in the hope that it will be useful, |
| 14 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | + * Lesser General Public License for more details. |
| 17 | + * |
| 18 | + * You should have received a copy of the GNU Lesser General Public |
| 19 | + * License along with this library; if not, write to the Free Software |
| 20 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 21 | + */ |
| 22 | +package org.exist.jetty; |
| 23 | + |
| 24 | +import org.eclipse.jetty.util.resource.PathResource; |
| 25 | +import org.eclipse.jetty.util.resource.Resource; |
| 26 | +import org.eclipse.jetty.util.resource.ResourceFactory; |
| 27 | +import org.junit.Test; |
| 28 | + |
| 29 | +import java.io.File; |
| 30 | +import java.nio.file.Files; |
| 31 | +import java.nio.file.InvalidPathException; |
| 32 | +import java.nio.file.Path; |
| 33 | + |
| 34 | +import static org.junit.Assert.assertNotSame; |
| 35 | +import static org.junit.Assert.assertTrue; |
| 36 | +import static org.junit.Assume.assumeTrue; |
| 37 | + |
| 38 | +/** |
| 39 | + * Windows integration regression test for Jetty 12.1 {@link PathResource#resolve(String)} on |
| 40 | + * drive URIs ({@code /D:/...}). Lives in {@code exist-webdav} so it runs on Windows CI |
| 41 | + * ({@code verify -DskipUnitTests=true}). |
| 42 | + */ |
| 43 | +public class WindowsPathResourceIT { |
| 44 | + |
| 45 | + @Test |
| 46 | + public void resolveWebInfOnWindowsDriveUri() throws Exception { |
| 47 | + assumeTrue("Windows-only PathResource URI regression", File.separatorChar == '\\'); |
| 48 | + |
| 49 | + final ResourceFactory resourceFactory = ResourceFactory.root(); |
| 50 | + final Path webapp = Files.createTempDirectory("webapp"); |
| 51 | + Files.createDirectory(webapp.resolve("WEB-INF")); |
| 52 | + try { |
| 53 | + final Resource resource = resourceFactory.newResource(webapp); |
| 54 | + assumeTrue("Expected PathResource for local webapp directory", resource instanceof PathResource); |
| 55 | + final String uriPath = resource.getURI().getPath(); |
| 56 | + assumeTrue("Expected absolute Windows drive URI path, got: " + uriPath, |
| 57 | + uriPath != null && uriPath.matches("/[A-Za-z]:/.*")); |
| 58 | + |
| 59 | + final PathResource pathResource = (PathResource) resource; |
| 60 | + try { |
| 61 | + pathResource.resolve("WEB-INF/"); |
| 62 | + // Jetty version may already fix resolve; wrapped path must still work. |
| 63 | + } catch (final InvalidPathException e) { |
| 64 | + // Expected on Jetty 12.1.x with /X:/... URI paths. |
| 65 | + } |
| 66 | + |
| 67 | + final Resource wrapped = WindowsPathResource.wrapIfNeeded(pathResource, resourceFactory); |
| 68 | + assertNotSame(pathResource, wrapped); |
| 69 | + |
| 70 | + final Resource webInf = wrapped.resolve("WEB-INF/"); |
| 71 | + assertTrue("WEB-INF should resolve to a directory", webInf.isDirectory()); |
| 72 | + } finally { |
| 73 | + Files.deleteIfExists(webapp.resolve("WEB-INF")); |
| 74 | + Files.deleteIfExists(webapp); |
| 75 | + } |
| 76 | + } |
| 77 | +} |
0 commit comments