]> source.dussan.org Git - archiva.git/commitdiff
[MRM-780] Access to indexes files with a browser is not possible
authorBrett Porter <brett@apache.org>
Sun, 20 Apr 2008 11:13:55 +0000 (11:13 +0000)
committerBrett Porter <brett@apache.org>
Sun, 20 Apr 2008 11:13:55 +0000 (11:13 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@649910 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/repository/RepositoryServlet.java
archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletTest.java
archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavResourceFactory.java

index 48ba64ba1b714fb151850124162fe1c1a7708a8b..18458152cb66858430210f298041c6887894d0b5 100644 (file)
@@ -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);
index 1c51598490272f89f00871e61d48bc543f83d5b0..42c9a6068d3fb8600382433fec79e6ee98d5f78e 100644 (file)
@@ -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() );
+        }
+    }
 }
index 82bd6e91fe8444dd2d08e0fc3598434d23f8f79d..8ce780898396aaecc5350eaa2935997d49626d11 100644 (file)
@@ -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;
     }