PR #11279 - fixes for AliasCheckerMultipleResourceBasesTest
Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
This commit is contained in:
parent
1398bf930e
commit
03313567e8
|
@ -629,6 +629,8 @@ public class ContextHandler extends Handler.Wrapper implements Attributes, Alias
|
||||||
{
|
{
|
||||||
if (!Resources.isReadable(baseResource))
|
if (!Resources.isReadable(baseResource))
|
||||||
throw new IllegalArgumentException("Base Resource is not valid: " + baseResource);
|
throw new IllegalArgumentException("Base Resource is not valid: " + baseResource);
|
||||||
|
if (baseResource.isAlias())
|
||||||
|
LOG.warn("Base Resource should not be an alias");
|
||||||
}
|
}
|
||||||
|
|
||||||
_availability.set(Availability.STARTING);
|
_availability.set(Availability.STARTING);
|
||||||
|
|
|
@ -38,6 +38,8 @@ import org.eclipse.jetty.util.URIUtil;
|
||||||
import org.eclipse.jetty.util.resource.Resource;
|
import org.eclipse.jetty.util.resource.Resource;
|
||||||
import org.eclipse.jetty.util.resource.ResourceFactory;
|
import org.eclipse.jetty.util.resource.ResourceFactory;
|
||||||
import org.eclipse.jetty.util.resource.Resources;
|
import org.eclipse.jetty.util.resource.Resources;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resource Handler.
|
* Resource Handler.
|
||||||
|
@ -56,6 +58,8 @@ import org.eclipse.jetty.util.resource.Resources;
|
||||||
*/
|
*/
|
||||||
public class ResourceHandler extends Handler.Wrapper
|
public class ResourceHandler extends Handler.Wrapper
|
||||||
{
|
{
|
||||||
|
private static final Logger LOG = LoggerFactory.getLogger(ResourceHandler.class);
|
||||||
|
|
||||||
private final ResourceService _resourceService = newResourceService();
|
private final ResourceService _resourceService = newResourceService();
|
||||||
private ByteBufferPool _byteBufferPool;
|
private ByteBufferPool _byteBufferPool;
|
||||||
private Resource _baseResource;
|
private Resource _baseResource;
|
||||||
|
@ -93,6 +97,10 @@ public class ResourceHandler extends Handler.Wrapper
|
||||||
if (context != null)
|
if (context != null)
|
||||||
_baseResource = context.getBaseResource();
|
_baseResource = context.getBaseResource();
|
||||||
}
|
}
|
||||||
|
else if (_baseResource.isAlias())
|
||||||
|
{
|
||||||
|
LOG.warn("Base Resource should not be an alias");
|
||||||
|
}
|
||||||
|
|
||||||
setMimeTypes(context == null ? MimeTypes.DEFAULTS : context.getMimeTypes());
|
setMimeTypes(context == null ? MimeTypes.DEFAULTS : context.getMimeTypes());
|
||||||
|
|
||||||
|
|
|
@ -46,9 +46,8 @@ public class AliasCheckerMultipleResourceBasesTest
|
||||||
private ServerConnector _connector;
|
private ServerConnector _connector;
|
||||||
private HttpClient _client;
|
private HttpClient _client;
|
||||||
private ContextHandler _context;
|
private ContextHandler _context;
|
||||||
private Path _webRootPath;
|
private Path _baseResource1;
|
||||||
private Path _altDir1Symlink;
|
private Path _baseResource2;
|
||||||
private Path _altDir2Symlink;
|
|
||||||
|
|
||||||
private static Path getResource(String path) throws Exception
|
private static Path getResource(String path) throws Exception
|
||||||
{
|
{
|
||||||
|
@ -59,6 +58,7 @@ public class AliasCheckerMultipleResourceBasesTest
|
||||||
|
|
||||||
private static void delete(Path path)
|
private static void delete(Path path)
|
||||||
{
|
{
|
||||||
|
if (path != null)
|
||||||
IO.delete(path.toFile());
|
IO.delete(path.toFile());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,17 +77,20 @@ public class AliasCheckerMultipleResourceBasesTest
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void before() throws Exception
|
public void before() throws Exception
|
||||||
{
|
{
|
||||||
_webRootPath = getResource("webroot");
|
Path webRootPath = getResource("webroot");
|
||||||
|
|
||||||
_altDir1Symlink = _webRootPath.resolve("../altDir1Symlink");
|
_baseResource1 = webRootPath.resolve("../altDir1").toAbsolutePath();
|
||||||
delete(_altDir1Symlink);
|
delete(_baseResource1);
|
||||||
Path altDir1 = _webRootPath.resolve("../altDir1").toAbsolutePath();
|
Files.createDirectory(_baseResource1);
|
||||||
Files.createSymbolicLink(_altDir1Symlink, altDir1).toFile().deleteOnExit();
|
Path file1Symlink = _baseResource1.resolve("file1");
|
||||||
|
Files.createSymbolicLink(file1Symlink, getResource("file1")).toFile().deleteOnExit();
|
||||||
|
|
||||||
_altDir2Symlink = _webRootPath.resolve("../altDir2Symlink");
|
_baseResource2 = webRootPath.resolve("../altDir2").toAbsolutePath();
|
||||||
delete(_altDir2Symlink);
|
delete(_baseResource2);
|
||||||
Path altDir2 = _webRootPath.resolve("../altDir2").toAbsolutePath();
|
Files.createDirectory(_baseResource2);
|
||||||
Files.createSymbolicLink(_altDir2Symlink, altDir2).toFile().deleteOnExit();
|
Path file2Symlink = _baseResource2.resolve("file2");
|
||||||
|
delete(file2Symlink);
|
||||||
|
Files.createSymbolicLink(file2Symlink, getResource("file2")).toFile().deleteOnExit();
|
||||||
|
|
||||||
// Create and start Server and Client.
|
// Create and start Server and Client.
|
||||||
_server = new Server();
|
_server = new Server();
|
||||||
|
@ -96,7 +99,7 @@ public class AliasCheckerMultipleResourceBasesTest
|
||||||
_context = new ContextHandler();
|
_context = new ContextHandler();
|
||||||
|
|
||||||
_context.setContextPath("/");
|
_context.setContextPath("/");
|
||||||
_context.setBaseResourceAsPath(_webRootPath);
|
_context.setBaseResourceAsPath(webRootPath);
|
||||||
_server.setHandler(_context);
|
_server.setHandler(_context);
|
||||||
_context.clearAliasChecks();
|
_context.clearAliasChecks();
|
||||||
|
|
||||||
|
@ -107,8 +110,8 @@ public class AliasCheckerMultipleResourceBasesTest
|
||||||
@AfterEach
|
@AfterEach
|
||||||
public void after() throws Exception
|
public void after() throws Exception
|
||||||
{
|
{
|
||||||
Files.delete(_altDir1Symlink);
|
delete(_baseResource1);
|
||||||
Files.delete(_altDir2Symlink);
|
delete(_baseResource2);
|
||||||
|
|
||||||
_client.stop();
|
_client.stop();
|
||||||
_server.stop();
|
_server.stop();
|
||||||
|
@ -131,8 +134,8 @@ public class AliasCheckerMultipleResourceBasesTest
|
||||||
public void test() throws Exception
|
public void test() throws Exception
|
||||||
{
|
{
|
||||||
Handler.Sequence handlers = new Handler.Sequence();
|
Handler.Sequence handlers = new Handler.Sequence();
|
||||||
handlers.addHandler(newResourceHandler(_altDir1Symlink));
|
handlers.addHandler(newResourceHandler(_baseResource1));
|
||||||
handlers.addHandler(newResourceHandler(_altDir2Symlink));
|
handlers.addHandler(newResourceHandler(_baseResource2));
|
||||||
_context.setHandler(handlers);
|
_context.setHandler(handlers);
|
||||||
_server.start();
|
_server.start();
|
||||||
|
|
||||||
|
@ -148,8 +151,8 @@ public class AliasCheckerMultipleResourceBasesTest
|
||||||
|
|
||||||
// Set alias checkers to allow content under these alternative resource bases.
|
// Set alias checkers to allow content under these alternative resource bases.
|
||||||
setAliasCheckers(
|
setAliasCheckers(
|
||||||
new SymlinkAllowedResourceAliasChecker(_context, toResource(_altDir1Symlink)),
|
new SymlinkAllowedResourceAliasChecker(_context, toResource(_baseResource1)),
|
||||||
new SymlinkAllowedResourceAliasChecker(_context, toResource(_altDir2Symlink))
|
new SymlinkAllowedResourceAliasChecker(_context, toResource(_baseResource2))
|
||||||
);
|
);
|
||||||
|
|
||||||
// Now we have set alias checkers we can access file 1.
|
// Now we have set alias checkers we can access file 1.
|
||||||
|
|
Loading…
Reference in New Issue