From 7875facb9b8aff1f142e29e7bcb9bd56c20dcde8 Mon Sep 17 00:00:00 2001 From: Brett Porter Date: Sun, 20 Apr 2008 11:13:55 +0000 Subject: [PATCH] [MRM-780] Access to indexes files with a browser is not possible git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@649910 13f79535-47bb-0310-9956-ffa450edef68 --- .../web/repository/RepositoryServlet.java | 4 ++- .../web/repository/RepositoryServletTest.java | 36 +++++++++++++++++++ .../webdav/ArchivaDavResourceFactory.java | 27 +++++++------- 3 files changed, 54 insertions(+), 13 deletions(-) diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/repository/RepositoryServlet.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/repository/RepositoryServlet.java index 48ba64ba1..18458152c 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/repository/RepositoryServlet.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/repository/RepositoryServlet.java @@ -124,8 +124,10 @@ public class RepositoryServlet final String msg = "Should throw " + UnauthorizedDavException.class.getName(); log.error(msg); webdavResponse.sendError(e.getErrorCode(), msg); + } else if ( e.getCause() != null ) { + webdavResponse.sendError(e.getErrorCode(), e.getCause().getMessage()); } else { - webdavResponse.sendError(e); + webdavResponse.sendError(e.getErrorCode(), e.getMessage()); } } finally { getDavSessionProvider().releaseSession(webdavRequest); diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletTest.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletTest.java index 1c5159849..42c9a6068 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletTest.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletTest.java @@ -23,6 +23,12 @@ import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.Configuration; import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; +import com.meterware.httpunit.GetMethodWebRequest; +import com.meterware.httpunit.HttpNotFoundException; +import com.meterware.httpunit.HttpUnitOptions; +import com.meterware.httpunit.WebRequest; +import com.meterware.httpunit.WebResponse; + import java.io.File; /** @@ -91,4 +97,34 @@ public class RepositoryServletTest // check other is still intact assertRepositoryValid( servlet, REPOID_INTERNAL ); } + + public void testGetRepositoryInvalidPathPassthroughPresent() + throws Exception + { + String path = REQUEST_PATH + ".index/filecontent/segments.gen"; + + populateRepo( repoRootInternal, ".index/filecontent/segments.gen", "index file" ); + + WebRequest request = new GetMethodWebRequest( path ); + WebResponse response = sc.getResponse( request ); + assertResponseOK( response ); + assertEquals( "index file", response.getText() ); + } + + public void testGetRepositoryInvalidPathPassthroughMissing() + throws Exception + { + String path = REQUEST_PATH + ".index/filecontent/foo.bar"; + + WebRequest request = new GetMethodWebRequest( path ); + try + { + sc.getResponse( request ); + fail( "should have been not found" ); + } + catch ( HttpNotFoundException e ) + { + assertEquals( "Error on HTTP request: 404 Invalid path to Artifact: legacy paths should have an expected type ending in [s] in the second part of the path. [http://machine.com/repository/internal/.index/filecontent/foo.bar]", e.getMessage() ); + } + } } diff --git a/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavResourceFactory.java b/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavResourceFactory.java index 82bd6e91f..8ce780898 100644 --- a/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavResourceFactory.java +++ b/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavResourceFactory.java @@ -148,29 +148,32 @@ public class ArchivaDavResourceFactory implements DavResourceFactory, Auditable { // At this point the incoming request can either be in default or // legacy layout format. + boolean fromProxy = fetchContentFromProxies(managedRepository, request, logicalResource ); + + boolean previouslyExisted = resourceFile.exists(); + try { - boolean fromProxy = fetchContentFromProxies(managedRepository, request, logicalResource ); - // Perform an adjustment of the resource to the managed // repository expected path. String localResourcePath = repositoryRequest.toNativePath( logicalResource.getPath(), managedRepository ); resourceFile = new File( managedRepository.getRepoRoot(), localResourcePath ); - - boolean previouslyExisted = resourceFile.exists(); - - // Attempt to fetch the resource from any defined proxy. - if ( fromProxy ) - { - processAuditEvents(request, locator.getWorkspaceName(), logicalResource.getPath(), previouslyExisted, resourceFile, " (proxied)"); - } - resource = new ArchivaDavResource(resourceFile.getAbsolutePath(), logicalResource.getPath(), mimeTypes, locator, this, null); - } catch ( LayoutException e ) { + if ( previouslyExisted ) + { + return resource; + } throw new DavException(HttpServletResponse.SC_NOT_FOUND, e); } + + // Attempt to fetch the resource from any defined proxy. + if ( fromProxy ) + { + processAuditEvents(request, locator.getWorkspaceName(), logicalResource.getPath(), previouslyExisted, resourceFile, " (proxied)"); + } + resource = new ArchivaDavResource(resourceFile.getAbsolutePath(), logicalResource.getPath(), mimeTypes, locator, this, null); } return resource; } -- 2.39.5