]> source.dussan.org Git - archiva.git/commitdiff
[MRM-567] Unable to download plugin SNAPSHOT's from proxy.
authorJoakim Erdfelt <joakime@apache.org>
Thu, 25 Oct 2007 23:39:05 +0000 (23:39 +0000)
committerJoakim Erdfelt <joakime@apache.org>
Thu, 25 Oct 2007 23:39:05 +0000 (23:39 +0000)
Adding unit tests for Artifact downloads via proxied requests.
Splitting RepositoryServlet testcase up to work around PlexusTestCase bug (the configuration within the plexus container consumed the entire java heap, causing an OOM, switching to smaller test cases gets around this bug, but its still not nice bug to hit.)
Reworking MimeTypes to allow for loading of archiva custom configuration. (mainly to get around the .getClassLoader().getResource() differences between command line / ide unit testing)

git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@588391 13f79535-47bb-0310-9956-ffa450edef68

21 files changed:
archiva-web/archiva-webapp/pom.xml
archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/repository/ArchivaMimeTypeLoader.java [new file with mode: 0644]
archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/repository/RepositoryServlet.java
archiva-web/archiva-webapp/src/main/resources/META-INF/plexus/application.xml
archiva-web/archiva-webapp/src/main/resources/archiva-mime-types.txt [new file with mode: 0644]
archiva-web/archiva-webapp/src/main/resources/org/codehaus/plexus/webdav/util/mime-types.txt [deleted file]
archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/AbstractRepositoryServletProxiedTestCase.java [new file with mode: 0644]
archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/AbstractRepositoryServletTestCase.java [new file with mode: 0644]
archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/ArchivaMimeTypeLoaderTest.java [new file with mode: 0644]
archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/BypassSecuritySystem.java [new file with mode: 0644]
archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletBrowseTest.java [new file with mode: 0644]
archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletDeployTest.java [new file with mode: 0644]
archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletNoProxyTest.java [new file with mode: 0644]
archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletProxiedReleasePolicyTest.java [new file with mode: 0644]
archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletProxiedSnapshotPolicyTest.java [new file with mode: 0644]
archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletSecurityTest.java [new file with mode: 0644]
archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletTest.java
archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/UnauthenticatedRepositoryServlet.java
archiva-web/archiva-webapp/src/test/resources/META-INF/plexus/components.xml [new file with mode: 0644]
archiva-web/archiva-webapp/src/test/resources/org/apache/maven/archiva/web/repository/RepositoryServletSecurityTest.xml [new file with mode: 0644]
archiva-web/archiva-webapp/src/test/resources/org/apache/maven/archiva/web/repository/RepositoryServletTest.xml

index 5456b47bb7a603458af6a4c53d2e1e7805d09e34..159a4129455140e891902522326812abee803ef6 100644 (file)
       <groupId>org.codehaus.plexus</groupId>
       <artifactId>plexus-xwork-integration</artifactId>
     </dependency>
+    <!--
     <dependency>
       <groupId>org.codehaus.plexus</groupId>
       <artifactId>plexus-utils</artifactId>
     </dependency>
+     -->
     <dependency>
       <groupId>org.apache.derby</groupId>
       <artifactId>derby</artifactId>
       <artifactId>activation</artifactId>
       <scope>provided</scope>
     </dependency>
+    <!--  Test Scoped -->
+    <dependency>
+      <groupId>org.mortbay.jetty</groupId>
+      <artifactId>jetty</artifactId>
+      <version>6.1.5</version>
+      <scope>test</scope>
+    </dependency>
     <dependency>
       <groupId>httpunit</groupId>
       <artifactId>httpunit</artifactId>
   </dependencies>
   <build>
     <plugins>
+      <!--
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <version>2.2</version>
+        <configuration>
+          <argLine>-agentlib:yjpagent</argLine>
+          <excludes>
+            <exclude>**/Abstract*</exclude>
+            <exclude>**/*TestCase.java</exclude>
+            <exclude>**/*Tests.java</exclude>
+            <exclude>**/*TestSuite.java</exclude>
+          </excludes>
+        </configuration>
+      </plugin>
+       -->
       <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-clean-plugin</artifactId>
diff --git a/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/repository/ArchivaMimeTypeLoader.java b/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/repository/ArchivaMimeTypeLoader.java
new file mode 100644 (file)
index 0000000..2a82184
--- /dev/null
@@ -0,0 +1,72 @@
+package org.apache.maven.archiva.web.repository;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
+import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
+import org.codehaus.plexus.webdav.util.MimeTypes;
+
+import java.io.IOException;
+import java.net.URL;
+
+/**
+ * Custom Archiva MimeTypes loader for plexus-webdav's {@link MimeTypes} 
+ *
+ * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
+ * @version $Id$
+ * @todo Support custom mime types from archiva-configuration.
+ * 
+ * @plexus.component role="org.apache.maven.archiva.web.repository.ArchivaMimeTypeLoader"
+ */
+public class ArchivaMimeTypeLoader
+    implements Initializable
+{
+    /**
+     * @plexus.requirement
+     */
+    private MimeTypes mimeTypes;
+
+    public void initialize()
+        throws InitializationException
+    {
+        // TODO: Make mime types loading configurable.
+        // Load the mime types from archiva location.
+        if ( mimeTypes.getMimeType( "sha1" ) == null )
+        {
+            URL url = this.getClass().getClassLoader().getResource( "/archiva-mime-types.txt" );
+            if ( url == null )
+            {
+                url = this.getClass().getClassLoader().getResource( "archiva-mime-types.txt" );
+            }
+
+            if ( url != null )
+            {
+                try
+                {
+                    mimeTypes.load( url.openStream() );
+                }
+                catch ( IOException e )
+                {
+                    throw new InitializationException( "Unable to load archiva-mime-types.txt : " + e.getMessage(), e );
+                }
+            }
+        }
+    }
+}
index 9bd9596e6b6fcba4d68b26f5aaed7ebbc73bd25d..61919910d913052b57f973494f9315a61f2db3ed 100644 (file)
@@ -68,12 +68,16 @@ public class RepositoryServlet
     private ArchivaConfiguration configuration;
 
     private Map<String, ManagedRepositoryConfiguration> repositoryMap;
+    
+    private ArchivaMimeTypeLoader mimeTypeLoader;
 
     public synchronized void initComponents()
         throws ServletException
     {
         super.initComponents();
-
+        
+        mimeTypeLoader = (ArchivaMimeTypeLoader) lookup( ArchivaMimeTypeLoader.class.getName() );
+        
         securitySystem = (SecuritySystem) lookup( SecuritySystem.ROLE );
         httpAuth = (HttpAuthenticator) lookup( HttpAuthenticator.ROLE, "basic" );
         audit = (AuditLog) lookup( AuditLog.ROLE );
@@ -108,6 +112,53 @@ public class RepositoryServlet
         }
     }
     
+    @Override
+    public void destroy()
+    {
+        try
+        {
+            release( securitySystem );
+        }
+        catch ( ServletException e )
+        {
+            log( "Unable to release SecuritySystem : " + e.getMessage(), e );
+        }
+        try
+        {
+            release( httpAuth );
+        }
+        catch ( ServletException e )
+        {
+            log( "Unable to release HttpAuth : " + e.getMessage(), e );
+        }
+        try
+        {
+            release( audit );
+        }
+        catch ( ServletException e )
+        {
+            log( "Unable to release AuditLog : " + e.getMessage(), e );
+        }
+        try
+        {
+            release( configuration );
+        }
+        catch ( ServletException e )
+        {
+            log( "Unable to release ArchivaConfiguration : " + e.getMessage(), e );
+        }
+        try
+        {
+            release( mimeTypeLoader );
+        }
+        catch ( ServletException e )
+        {
+            log( "Unable to release ArchivaMimeTypeLoader : " + e.getMessage(), e );
+        }
+
+        super.destroy();
+    }
+    
     @Override
     protected void service( HttpServletRequest httpRequest, HttpServletResponse httpResponse )
         throws ServletException, IOException
index c1fe07d137702cd7405ec6e5df266da8cd4c9038..aed45580b4b254a9e4f02460404b32a28f3785d8 100644 (file)
         </otherProperties>
       </configuration>
     </component>
+    
+    <component>
+      <role>org.codehaus.plexus.webdav.util.MimeTypes</role>
+      <implementation>org.codehaus.plexus.webdav.util.MimeTypes</implementation>
+      <description>MimeTypes</description>
+      <configuration>
+        <resource>archiva-mime-types.txt</resource>
+      </configuration>
+    </component>
 
     <!--
      | Logger manager
diff --git a/archiva-web/archiva-webapp/src/main/resources/archiva-mime-types.txt b/archiva-web/archiva-webapp/src/main/resources/archiva-mime-types.txt
new file mode 100644 (file)
index 0000000..42c3d9f
--- /dev/null
@@ -0,0 +1,127 @@
+# This file controls what Internet media types are sent to the client for
+# given file extension(s). Sending the correct media type to the client
+# is important so they know how to handle the content of the file.
+# Extra types can either be added here or by using an AddType directive
+# in your config files. For more information about Internet media types,
+# please read RFC 2045, 2046, 2047, 2048, and 2077. The Internet media type
+# registry is at <http://www.iana.org/assignments/media-types/>.
+
+# MIME type                              Extensions
+
+application/andrew-inset                 ez
+application/atom+xml                     atom
+application/java-archive                 jar
+application/mac-binhex40                 hqx
+application/mac-compactpro               cpt
+application/mathml+xml                   mathml
+application/msword                       doc
+application/octet-stream                 bin dms lha lzh exe class so dll dmg
+application/oda                          oda
+application/ogg                          ogg
+application/pdf                          pdf
+application/pgp-encrypted                               pgp
+application/postscript                   ai eps ps
+application/rdf+xml                      rdf
+application/smil                         smi smil
+application/srgs                         gram
+application/srgs+xml                     grxml
+application/vnd.mif                      mif
+application/vnd.mozilla.xul+xml          xul
+application/vnd.ms-excel                 xls
+application/vnd.ms-powerpoint            ppt
+application/vnd.rn-realmedia             rm
+application/vnd.wap.wbxml                wbxml
+application/vnd.wap.wmlc                 wmlc
+application/vnd.wap.wmlscriptc           wmlsc
+application/voicexml+xml                 vxml
+application/x-bcpio                      bcpio
+application/x-cdlink                     vcd
+application/x-chess-pgn                  pgn
+application/x-cpio                       cpio
+application/x-csh                        csh
+application/x-director                   dcr dir dxr
+application/x-dvi                        dvi
+application/x-futuresplash               spl
+application/x-gtar                       gtar
+application/x-hdf                        hdf
+application/x-java-jnlp-file             jnlp
+application/x-javascript                 js
+application/x-koan                       skp skd skt skm
+application/x-latex                      latex
+application/x-netcdf                     nc cdf
+application/x-sh                         sh
+application/x-shar                       shar
+application/x-shockwave-flash            swf
+application/x-stuffit                    sit
+application/x-sv4cpio                    sv4cpio
+application/x-sv4crc                     sv4crc
+application/x-tar                        tar
+application/x-tcl                        tcl
+application/x-tex                        tex
+application/x-texinfo                    texinfo texi
+application/x-troff                      t tr roff
+application/x-troff-man                  man
+application/x-troff-me                   me
+application/x-troff-ms                   ms
+application/x-ustar                      ustar
+application/x-wais-source                src
+application/xhtml+xml                    xhtml xht
+application/xml                          xml xsl
+application/xml-dtd                      dtd
+application/xslt+xml                     xslt
+application/zip                          zip
+audio/basic                              au snd
+audio/midi                               mid midi kar
+audio/mpeg                               mpga mp2 mp3
+audio/x-aiff                             aif aiff aifc
+audio/x-mpegurl                          m3u
+audio/x-pn-realaudio                     ram ra
+audio/x-wav                              wav
+chemical/x-pdb                           pdb
+chemical/x-xyz                           xyz
+image/bmp                                bmp
+image/cgm                                cgm
+image/gif                                gif
+image/ief                                ief
+image/jp2                                jp2
+image/jpeg                               jpeg jpg jpe
+image/pict                               pict pic pct
+image/png                                png
+image/svg+xml                            svg
+image/tiff                               tiff tif
+image/vnd.djvu                           djvu djv
+image/vnd.wap.wbmp                       wbmp
+image/x-cmu-raster                       ras
+image/x-icon                             ico
+image/x-macpaint                         pntg pnt mac
+image/x-portable-anymap                  pnm
+image/x-portable-bitmap                  pbm
+image/x-portable-graymap                 pgm
+image/x-portable-pixmap                  ppm
+image/x-quicktime                        qtif qti
+image/x-rgb                              rgb
+image/x-xbitmap                          xbm
+image/x-xpixmap                          xpm
+image/x-xwindowdump                      xwd
+model/iges                               igs iges
+model/mesh                               msh mesh silo
+model/vrml                               wrl vrml
+text/calendar                            ics ifb
+text/css                                 css
+text/html                                html htm
+text/plain                               asc txt sha1 md5
+text/richtext                            rtx
+text/rtf                                 rtf
+text/sgml                                sgml sgm
+text/tab-separated-values                tsv
+text/vnd.wap.wml                         wml
+text/vnd.wap.wmlscript                   wmls
+text/x-setext                            etx
+video/mp4                                mp4
+video/mpeg                               mpeg mpg mpe
+video/quicktime                          qt mov
+video/vnd.mpegurl                        mxu m4u
+video/x-dv                               dv dif
+video/x-msvideo                          avi
+video/x-sgi-movie                        movie
+x-conference/x-cooltalk                  ice
diff --git a/archiva-web/archiva-webapp/src/main/resources/org/codehaus/plexus/webdav/util/mime-types.txt b/archiva-web/archiva-webapp/src/main/resources/org/codehaus/plexus/webdav/util/mime-types.txt
deleted file mode 100644 (file)
index 90034d4..0000000
+++ /dev/null
@@ -1,129 +0,0 @@
-# This is a comment. I love comments.
-
-# This file controls what Internet media types are sent to the client for
-# given file extension(s). Sending the correct media type to the client
-# is important so they know how to handle the content of the file.
-# Extra types can either be added here or by using an AddType directive
-# in your config files. For more information about Internet media types,
-# please read RFC 2045, 2046, 2047, 2048, and 2077. The Internet media type
-# registry is at <http://www.iana.org/assignments/media-types/>.
-
-# MIME type                              Extensions
-
-application/andrew-inset                 ez
-application/atom+xml                     atom
-application/java-archive                 jar
-application/mac-binhex40                 hqx
-application/mac-compactpro               cpt
-application/mathml+xml                   mathml
-application/msword                       doc
-application/octet-stream                 bin dms lha lzh exe class so dll dmg
-application/oda                          oda
-application/ogg                          ogg
-application/pdf                          pdf
-application/pgp-encrypted                               pgp
-application/postscript                   ai eps ps
-application/rdf+xml                      rdf
-application/smil                         smi smil
-application/srgs                         gram
-application/srgs+xml                     grxml
-application/vnd.mif                      mif
-application/vnd.mozilla.xul+xml          xul
-application/vnd.ms-excel                 xls
-application/vnd.ms-powerpoint            ppt
-application/vnd.rn-realmedia             rm
-application/vnd.wap.wbxml                wbxml
-application/vnd.wap.wmlc                 wmlc
-application/vnd.wap.wmlscriptc           wmlsc
-application/voicexml+xml                 vxml
-application/x-bcpio                      bcpio
-application/x-cdlink                     vcd
-application/x-chess-pgn                  pgn
-application/x-cpio                       cpio
-application/x-csh                        csh
-application/x-director                   dcr dir dxr
-application/x-dvi                        dvi
-application/x-futuresplash               spl
-application/x-gtar                       gtar
-application/x-hdf                        hdf
-application/x-java-jnlp-file             jnlp
-application/x-javascript                 js
-application/x-koan                       skp skd skt skm
-application/x-latex                      latex
-application/x-netcdf                     nc cdf
-application/x-sh                         sh
-application/x-shar                       shar
-application/x-shockwave-flash            swf
-application/x-stuffit                    sit
-application/x-sv4cpio                    sv4cpio
-application/x-sv4crc                     sv4crc
-application/x-tar                        tar
-application/x-tcl                        tcl
-application/x-tex                        tex
-application/x-texinfo                    texinfo texi
-application/x-troff                      t tr roff
-application/x-troff-man                  man
-application/x-troff-me                   me
-application/x-troff-ms                   ms
-application/x-ustar                      ustar
-application/x-wais-source                src
-application/xhtml+xml                    xhtml xht
-application/xml                          xml xsl
-application/xml-dtd                      dtd
-application/xslt+xml                     xslt
-application/zip                          zip
-audio/basic                              au snd
-audio/midi                               mid midi kar
-audio/mpeg                               mpga mp2 mp3
-audio/x-aiff                             aif aiff aifc
-audio/x-mpegurl                          m3u
-audio/x-pn-realaudio                     ram ra
-audio/x-wav                              wav
-chemical/x-pdb                           pdb
-chemical/x-xyz                           xyz
-image/bmp                                bmp
-image/cgm                                cgm
-image/gif                                gif
-image/ief                                ief
-image/jp2                                jp2
-image/jpeg                               jpeg jpg jpe
-image/pict                               pict pic pct
-image/png                                png
-image/svg+xml                            svg
-image/tiff                               tiff tif
-image/vnd.djvu                           djvu djv
-image/vnd.wap.wbmp                       wbmp
-image/x-cmu-raster                       ras
-image/x-icon                             ico
-image/x-macpaint                         pntg pnt mac
-image/x-portable-anymap                  pnm
-image/x-portable-bitmap                  pbm
-image/x-portable-graymap                 pgm
-image/x-portable-pixmap                  ppm
-image/x-quicktime                        qtif qti
-image/x-rgb                              rgb
-image/x-xbitmap                          xbm
-image/x-xpixmap                          xpm
-image/x-xwindowdump                      xwd
-model/iges                               igs iges
-model/mesh                               msh mesh silo
-model/vrml                               wrl vrml
-text/calendar                            ics ifb
-text/css                                 css
-text/html                                html htm
-text/plain                               asc txt sha1 md5
-text/richtext                            rtx
-text/rtf                                 rtf
-text/sgml                                sgml sgm
-text/tab-separated-values                tsv
-text/vnd.wap.wml                         wml
-text/vnd.wap.wmlscript                   wmls
-text/x-setext                            etx
-video/mp4                                mp4
-video/mpeg                               mpeg mpg mpe
-video/quicktime                          qt mov
-video/vnd.mpegurl                        mxu m4u
-video/x-dv                               dv dif
-video/x-msvideo                          avi
-video/x-sgi-movie                        movie
-x-conference/x-cooltalk                  ice
diff --git a/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/AbstractRepositoryServletProxiedTestCase.java b/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/AbstractRepositoryServletProxiedTestCase.java
new file mode 100644 (file)
index 0000000..af811ed
--- /dev/null
@@ -0,0 +1,301 @@
+package org.apache.maven.archiva.web.repository;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import com.meterware.httpunit.WebConversation;
+import com.meterware.httpunit.WebResponse;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration;
+import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration;
+import org.apache.maven.archiva.policies.CachedFailuresPolicy;
+import org.apache.maven.archiva.policies.ChecksumPolicy;
+import org.apache.maven.archiva.policies.ReleasesPolicy;
+import org.apache.maven.archiva.policies.SnapshotsPolicy;
+import org.mortbay.jetty.Connector;
+import org.mortbay.jetty.Server;
+import org.mortbay.jetty.bio.SocketConnector;
+import org.mortbay.jetty.handler.ContextHandler;
+import org.mortbay.jetty.handler.ContextHandlerCollection;
+import org.mortbay.jetty.servlet.DefaultServlet;
+import org.mortbay.jetty.servlet.ServletHandler;
+
+import java.io.File;
+
+/**
+ * AbstractRepositoryServletProxiedTestCase 
+ *
+ * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public abstract class AbstractRepositoryServletProxiedTestCase
+    extends AbstractRepositoryServletTestCase
+{
+    class RemoteRepoInfo
+    {
+        public String id;
+
+        public String url;
+
+        public String context;
+
+        public Server server;
+
+        public File root;
+
+        public RemoteRepositoryConfiguration config;
+    }
+
+    protected static final long ONE_SECOND = ( 1000 * 60 );
+
+    protected static final long ONE_MINUTE = ( ONE_SECOND * 60 );
+
+    protected static final long ONE_HOUR = ( ONE_MINUTE * 60 );
+
+    protected static final long ONE_DAY = ( ONE_HOUR * 24 );
+
+    protected static final long OVER_ONE_HOUR = ( ONE_HOUR + ONE_MINUTE );
+
+    protected static final long OVER_ONE_DAY = ( ONE_DAY + ONE_HOUR );
+
+    protected static final long OLDER = ( -1 );
+
+    protected static final long NEWER = 0;
+
+    protected static final int EXPECT_MANAGED_CONTENTS = 1;
+
+    protected static final int EXPECT_REMOTE_CONTENTS = 2;
+
+    protected static final int EXPECT_NOT_FOUND = 3;
+
+    protected static final boolean HAS_MANAGED_COPY = true;
+
+    protected static final boolean NO_MANAGED_COPY = false;
+
+    protected RemoteRepoInfo remoteCentral;
+
+    protected RemoteRepoInfo remoteSnapshots;
+    
+    @Override
+    protected void setUp()
+        throws Exception
+    {
+        super.setUp();
+    }
+
+    public RemoteRepoInfo createSnapshotsRepo()
+        throws Exception
+    {
+        RemoteRepoInfo snapshots = new RemoteRepoInfo();
+        snapshots.id = "snapshots";
+        snapshots.context = "/snapshots";
+        snapshots.root = getTestFile( "target/remote-repos/snapshots/" );
+
+        // Remove exising root contents.
+        if ( snapshots.root.exists() )
+        {
+            FileUtils.deleteDirectory( snapshots.root );
+        }
+
+        // Establish root directory.
+        if ( !snapshots.root.exists() )
+        {
+            snapshots.root.mkdirs();
+        }
+
+        snapshots.server = new Server();
+        ContextHandlerCollection contexts = new ContextHandlerCollection();
+        snapshots.server.setHandler( contexts );
+
+        SocketConnector connector = new SocketConnector();
+        connector.setPort( 0 ); // 0 means, choose and empty port. (we'll find out which, later)
+
+        snapshots.server.setConnectors( new Connector[] { connector } );
+
+        ContextHandler context = new ContextHandler();
+        context.setContextPath( snapshots.context );
+        context.setAttribute( "dirAllowed", true );
+        context.setAttribute( "maxCacheSize", 0 );
+        context.setResourceBase( snapshots.root.getAbsolutePath() );
+        ServletHandler servlet = new ServletHandler();
+        servlet.addServletWithMapping( DefaultServlet.class.getName(), "/" );
+        context.setHandler( servlet );
+        contexts.addHandler( context );
+
+        snapshots.server.start();
+
+        int port = connector.getLocalPort();
+        snapshots.url = "http://localhost:" + port + snapshots.context;
+        System.out.println( "Snapshot HTTP Server started on " + snapshots.url );
+
+        snapshots.config = createRemoteRepository( snapshots.id, "Testable [" + snapshots.id + "] Remote Repo",
+                                                   snapshots.url );
+
+        return snapshots;
+    }
+
+    private void assertServerSetupCorrectly( RemoteRepoInfo remoteRepo )
+        throws Exception
+    {
+        WebConversation wc = new WebConversation();
+        WebResponse response = wc.getResponse( remoteRepo.url );
+        assertResponseOK( response );
+    }
+
+    private RemoteRepoInfo createCentralRepo()
+        throws Exception
+    {
+        RemoteRepoInfo central = new RemoteRepoInfo();
+        central.id = "central";
+        central.context = "/central";
+        central.root = getTestFile( "target/remote-repos/central/" );
+
+        // Remove exising root contents.
+        if ( central.root.exists() )
+        {
+            FileUtils.deleteDirectory( central.root );
+        }
+
+        // Establish root directory.
+        if ( !central.root.exists() )
+        {
+            central.root.mkdirs();
+        }
+
+        central.server = new Server();
+        ContextHandlerCollection contexts = new ContextHandlerCollection();
+        central.server.setHandler( contexts );
+
+        SocketConnector connector = new SocketConnector();
+        connector.setPort( 0 ); // 0 means, choose and empty port. (we'll find out which, later)
+
+        central.server.setConnectors( new Connector[] { connector } );
+
+        ContextHandler context = new ContextHandler();
+        context.setContextPath( central.context );
+        context.setResourceBase( central.root.getAbsolutePath() );
+        context.setAttribute( "dirAllowed", true );
+        context.setAttribute( "maxCacheSize", 0 );
+        ServletHandler servlet = new ServletHandler();
+        servlet.addServletWithMapping( DefaultServlet.class.getName(), "/" );
+        context.setHandler( servlet );
+        contexts.addHandler( context );
+
+        central.server.start();
+
+        int port = connector.getLocalPort();
+        central.url = "http://localhost:" + port + central.context;
+        System.out.println( "Central HTTP Server started on " + central.url );
+
+        central.config = createRemoteRepository( central.id, "Testable [" + central.id + "] Remote Repo", central.url );
+
+        return central;
+    }
+
+    private void setupConnector( String repoId, RemoteRepoInfo remoteRepo, String releasesPolicy, String snapshotsPolicy )
+    {
+        ProxyConnectorConfiguration connector = new ProxyConnectorConfiguration();
+        connector.setSourceRepoId( repoId );
+        connector.setTargetRepoId( remoteRepo.id );
+        connector.addPolicy( ProxyConnectorConfiguration.POLICY_RELEASES, releasesPolicy );
+        connector.addPolicy( ProxyConnectorConfiguration.POLICY_SNAPSHOTS, snapshotsPolicy );
+        connector.addPolicy( ProxyConnectorConfiguration.POLICY_CHECKSUM, ChecksumPolicy.IGNORED );
+        connector.addPolicy( ProxyConnectorConfiguration.POLICY_CACHE_FAILURES, CachedFailuresPolicy.IGNORED );
+
+        archivaConfiguration.getConfiguration().addProxyConnector( connector );
+    }
+
+    private void shutdownServer( RemoteRepoInfo remoteRepo )
+    {
+        if ( remoteRepo != null )
+        {
+            if ( remoteRepo.server != null )
+            {
+                if ( remoteRepo.server.isRunning() )
+                {
+                    try
+                    {
+                        remoteRepo.server.stop();
+                        // int graceful = remoteRepo.server.getGracefulShutdown();
+                        // System.out.println( "server set to graceful shutdown: " + graceful );
+                        // remoteRepo = null;
+                    }
+                    catch ( Exception e )
+                    {
+                        e.printStackTrace( System.err );
+                    }
+                }
+            }
+        }
+    }
+
+    protected File populateRepo( RemoteRepoInfo remoteRepo, String path, String contents )
+        throws Exception
+    {
+        File destFile = new File( remoteRepo.root, path );
+        destFile.getParentFile().mkdirs();
+        FileUtils.writeStringToFile( destFile, contents, null );
+        return destFile;
+    }
+
+    protected void setupCentralRemoteRepo()
+        throws Exception
+    {
+        remoteCentral = createCentralRepo();
+
+        assertServerSetupCorrectly( remoteCentral );
+        archivaConfiguration.getConfiguration().addRemoteRepository( remoteCentral.config );
+        setupCleanRepo( remoteCentral.root );
+    }
+
+    protected void setupConnector( String repoId, RemoteRepoInfo remoteRepo )
+    {
+        setupConnector( repoId, remoteRepo, ReleasesPolicy.IGNORED, SnapshotsPolicy.IGNORED );
+    }
+
+    protected void setupReleaseConnector( String managedRepoId, RemoteRepoInfo remoteRepo, String releasePolicy )
+    {
+        setupConnector( managedRepoId, remoteRepo, releasePolicy, SnapshotsPolicy.IGNORED );
+    }
+
+    protected void setupSnapshotConnector( String managedRepoId, RemoteRepoInfo remoteRepo, String snapshotsPolicy )
+    {
+        setupConnector( managedRepoId, remoteRepo, ReleasesPolicy.IGNORED, snapshotsPolicy );
+    }
+
+    protected void setupSnapshotsRemoteRepo()
+        throws Exception
+    {
+        remoteSnapshots = createSnapshotsRepo();
+
+        assertServerSetupCorrectly( remoteSnapshots );
+        archivaConfiguration.getConfiguration().addRemoteRepository( remoteSnapshots.config );
+        setupCleanRepo( remoteSnapshots.root );
+    }
+
+    @Override
+    protected void tearDown()
+        throws Exception
+    {
+        shutdownServer( remoteCentral );
+        shutdownServer( remoteSnapshots );
+        super.tearDown();
+    }
+}
diff --git a/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/AbstractRepositoryServletTestCase.java b/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/AbstractRepositoryServletTestCase.java
new file mode 100644 (file)
index 0000000..7b79e79
--- /dev/null
@@ -0,0 +1,226 @@
+package org.apache.maven.archiva.web.repository;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import com.meterware.httpunit.WebResponse;
+import com.meterware.servletunit.ServletRunner;
+import com.meterware.servletunit.ServletUnitClient;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.maven.archiva.configuration.ArchivaConfiguration;
+import org.apache.maven.archiva.configuration.Configuration;
+import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
+import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration;
+import org.codehaus.plexus.PlexusConstants;
+import org.codehaus.plexus.PlexusTestCase;
+
+import java.io.File;
+import java.io.IOException;
+
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+
+/**
+ * AbstractRepositoryServletTestCase 
+ *
+ * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public abstract class AbstractRepositoryServletTestCase
+    extends PlexusTestCase
+{
+    protected static final String REPOID_INTERNAL = "internal";
+
+    protected ServletUnitClient sc;
+
+    protected ArchivaConfiguration archivaConfiguration;
+
+    protected File repoRootInternal;
+    
+    private ServletRunner sr;
+
+    protected void assertFileContents( String expectedContents, File repoRoot, String path )
+        throws IOException
+    {
+        File actualFile = new File( repoRoot, path );
+        assertTrue( "File <" + actualFile.getAbsolutePath() + "> should exist.", actualFile.exists() );
+        assertTrue( "File <" + actualFile.getAbsolutePath() + "> should be a file (not a dir/link/device/etc).",
+                    actualFile.isFile() );
+    
+        String actualContents = FileUtils.readFileToString( actualFile, null );
+        assertEquals( "File Contents of <" + actualFile.getAbsolutePath() + ">", expectedContents, actualContents );
+    }
+
+    protected void assertRepositoryValid( RepositoryServlet servlet, String repoId )
+    {
+        ManagedRepositoryConfiguration repository = servlet.getRepository( repoId );
+        assertNotNull( "Archiva Managed Repository id:<" + repoId + "> should exist.", repository );
+        File repoRoot = new File( repository.getLocation() );
+        assertTrue( "Archiva Managed Repository id:<" + repoId + "> should have a valid location on disk.", repoRoot
+            .exists()
+            && repoRoot.isDirectory() );
+    }
+
+    protected void assertResponseOK( WebResponse response )
+    {
+        assertNotNull( "Should have recieved a response", response );
+        assertEquals( "Should have been an OK response code.", HttpServletResponse.SC_OK, response.getResponseCode() );
+    }
+    
+    protected void assertResponseNotFound( WebResponse response )
+    {
+        assertNotNull( "Should have recieved a response", response );
+        assertEquals( "Should have been an 404/Not Found response code.", HttpServletResponse.SC_NOT_FOUND, response
+            .getResponseCode() );
+    }
+
+    protected ManagedRepositoryConfiguration createManagedRepository( String id, String name, File location )
+    {
+        ManagedRepositoryConfiguration repo = new ManagedRepositoryConfiguration();
+        repo.setId( id );
+        repo.setName( name );
+        repo.setLocation( location.getAbsolutePath() );
+        return repo;
+    }
+
+    protected RemoteRepositoryConfiguration createRemoteRepository( String id, String name, String url )
+    {
+        RemoteRepositoryConfiguration repo = new RemoteRepositoryConfiguration();
+        repo.setId( id );
+        repo.setName( name );
+        repo.setUrl( url );
+        return repo;
+    }
+
+    protected void dumpResponse( WebResponse response )
+    {
+        System.out.println( "---(response)---" );
+        System.out.println( "" + response.getResponseCode() + " " + response.getResponseMessage() );
+    
+        String headerNames[] = response.getHeaderFieldNames();
+        for ( String headerName : headerNames )
+        {
+            System.out.println( "[header] " + headerName + ": " + response.getHeaderField( headerName ) );
+        }
+    
+        System.out.println( "---(text)---" );
+        try
+        {
+            System.out.println( response.getText() );
+        }
+        catch ( IOException e )
+        {
+            System.err.print( "[Exception] : " );
+            e.printStackTrace( System.err );
+        }
+    }
+
+    protected void saveConfiguration()
+        throws Exception
+    {
+        archivaConfiguration.save( archivaConfiguration.getConfiguration() );
+    }
+
+    protected void setUp()
+        throws Exception
+    {
+        super.setUp();
+        
+        String appserverBase = getTestFile( "target/appserver-base" ).getAbsolutePath();
+        System.setProperty( "appserver.base", appserverBase );
+
+        File testConf = getTestFile( "src/test/resources/repository-archiva.xml" );
+        File testConfDest = new File( appserverBase, "conf/archiva.xml" );
+        FileUtils.copyFile( testConf, testConfDest );
+
+        archivaConfiguration = (ArchivaConfiguration) lookup( ArchivaConfiguration.class );
+        repoRootInternal = new File( appserverBase, "data/repositories/internal" );
+        Configuration config = archivaConfiguration.getConfiguration();
+
+        config.addManagedRepository( createManagedRepository( REPOID_INTERNAL, "Internal Test Repo", repoRootInternal ) );
+        saveConfiguration();
+
+        sr = new ServletRunner();
+        sr.registerServlet( "/repository/*", UnauthenticatedRepositoryServlet.class.getName() );
+        sc = sr.newClient();
+        HttpSession session = sc.getSession( true );
+        ServletContext servletContext = session.getServletContext();
+        servletContext.setAttribute( PlexusConstants.PLEXUS_KEY, getContainer() );
+    }
+    
+    @Override
+    protected String getConfigurationName( String subname )
+        throws Exception
+    {
+        return "org/apache/maven/archiva/web/repository/RepositoryServletTest.xml";
+    }
+    
+    @Override
+    protected void tearDown()
+        throws Exception
+    {
+        release( archivaConfiguration );
+        
+        if ( sc != null )
+        {
+            sc.clearContents();
+        }
+
+        if ( sr != null )
+        {
+            sr.shutDown();
+        }
+        
+        super.tearDown();
+    }
+
+    protected void setupCleanRepo( File repoRootDir )
+        throws IOException
+    {
+        FileUtils.deleteDirectory( repoRootDir );
+        if ( !repoRootDir.exists() )
+        {
+            repoRootDir.mkdirs();
+        }
+    }
+
+    protected void assertManagedFileNotExists( File repoRootInternal, String resourcePath )
+    {
+        File repoFile = new File( repoRootInternal, resourcePath );
+        assertFalse( "Managed Repository File <" + repoFile.getAbsolutePath() + "> should not exist.", repoFile
+            .exists() );
+    }
+
+    protected void setupCleanInternalRepo()
+        throws Exception
+    {
+        setupCleanRepo( repoRootInternal );
+    }
+
+    protected File populateRepo( File repoRootManaged, String path, String contents )
+        throws Exception
+    {
+        File destFile = new File( repoRootManaged, path );
+        destFile.getParentFile().mkdirs();
+        FileUtils.writeStringToFile( destFile, contents, null );
+        return destFile;
+    }
+}
diff --git a/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/ArchivaMimeTypeLoaderTest.java b/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/ArchivaMimeTypeLoaderTest.java
new file mode 100644 (file)
index 0000000..5d634e9
--- /dev/null
@@ -0,0 +1,47 @@
+package org.apache.maven.archiva.web.repository;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.codehaus.plexus.PlexusTestCase;
+import org.codehaus.plexus.webdav.util.MimeTypes;
+
+/**
+ * ArchivaMimeTypesTest 
+ *
+ * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class ArchivaMimeTypeLoaderTest
+    extends PlexusTestCase
+{
+    public void testArchivaTypes()
+        throws Exception
+    {
+        lookup( ArchivaMimeTypeLoader.class );
+        MimeTypes mimeTypes = (MimeTypes) lookup( MimeTypes.class );
+        assertNotNull( mimeTypes );
+
+        // Test for some added types.
+        assertEquals( "sha1", "text/plain", mimeTypes.getMimeType( "foo.sha1" ) );
+        assertEquals( "md5", "text/plain", mimeTypes.getMimeType( "foo.md5" ) );
+        assertEquals( "pgp", "application/pgp-encrypted", mimeTypes.getMimeType( "foo.pgp" ) );
+        assertEquals( "jar", "application/java-archive", mimeTypes.getMimeType( "foo.jar" ) );
+    }
+}
diff --git a/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/BypassSecuritySystem.java b/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/BypassSecuritySystem.java
new file mode 100644 (file)
index 0000000..e99d7b4
--- /dev/null
@@ -0,0 +1,134 @@
+package org.apache.maven.archiva.web.repository;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.codehaus.plexus.redback.authentication.AuthenticationDataSource;
+import org.codehaus.plexus.redback.authentication.AuthenticationException;
+import org.codehaus.plexus.redback.authentication.AuthenticationResult;
+import org.codehaus.plexus.redback.authorization.AuthorizationException;
+import org.codehaus.plexus.redback.authorization.AuthorizationResult;
+import org.codehaus.plexus.redback.keys.KeyManager;
+import org.codehaus.plexus.redback.keys.memory.MemoryKeyManager;
+import org.codehaus.plexus.redback.policy.AccountLockedException;
+import org.codehaus.plexus.redback.policy.DefaultUserSecurityPolicy;
+import org.codehaus.plexus.redback.policy.UserSecurityPolicy;
+import org.codehaus.plexus.redback.system.DefaultSecuritySession;
+import org.codehaus.plexus.redback.system.DefaultSecuritySystem;
+import org.codehaus.plexus.redback.system.SecuritySession;
+import org.codehaus.plexus.redback.system.SecuritySystem;
+import org.codehaus.plexus.redback.users.UserManager;
+import org.codehaus.plexus.redback.users.UserNotFoundException;
+import org.codehaus.plexus.redback.users.memory.MemoryUserManager;
+
+/**
+ * BypassSecuritySystem - used to bypass the security system for testing reasons and allow
+ * for every request to respond as success / true. 
+ *
+ * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
+ * @version $Id$
+ * 
+ * @plexus.component 
+ *      role="org.codehaus.plexus.redback.system.SecuritySystem"
+ */
+public class BypassSecuritySystem
+    extends DefaultSecuritySystem
+    implements SecuritySystem
+{
+    private KeyManager bypassKeyManager;
+    private UserSecurityPolicy bypassPolicy;
+    private UserManager bypassUserManager;
+    
+    public BypassSecuritySystem()
+    {
+        bypassKeyManager = new MemoryKeyManager();
+        bypassPolicy = new DefaultUserSecurityPolicy();
+        bypassUserManager = new MemoryUserManager();
+    }
+    
+    public SecuritySession authenticate( AuthenticationDataSource source )
+        throws AuthenticationException, UserNotFoundException, AccountLockedException
+    {
+        AuthenticationResult result = new AuthenticationResult( true, source.getPrincipal(), null );
+        return new DefaultSecuritySession( result );
+    }
+
+    public AuthorizationResult authorize( SecuritySession session, Object permission )
+        throws AuthorizationException
+    {
+        return new AuthorizationResult( true, session.getUser(), null );
+    }
+
+    public AuthorizationResult authorize( SecuritySession session, Object permission, Object resource )
+        throws AuthorizationException
+    {
+        return new AuthorizationResult( true, session.getUser(), null );
+    }
+
+    public String getAuthenticatorId()
+    {
+        return "bypass-authenticator";
+    }
+
+    public String getAuthorizerId()
+    {
+        return "bypass-authorizer";
+    }
+
+    public KeyManager getKeyManager()
+    {
+        return bypassKeyManager;
+    }
+
+    public UserSecurityPolicy getPolicy()
+    {
+        return bypassPolicy;
+    }
+
+    public String getUserManagementId()
+    {
+        return "bypass-managementid";
+    }
+
+    public UserManager getUserManager()
+    {
+        return bypassUserManager;
+    }
+
+    public boolean isAuthenticated( AuthenticationDataSource source )
+        throws AuthenticationException, UserNotFoundException, AccountLockedException
+    {
+        // Always true
+        return true;
+    }
+
+    public boolean isAuthorized( SecuritySession session, Object permission )
+        throws AuthorizationException
+    {
+        // Always true
+        return true;
+    }
+
+    public boolean isAuthorized( SecuritySession session, Object permission, Object resource )
+        throws AuthorizationException
+    {
+        // Always true
+        return true;
+    }
+}
diff --git a/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletBrowseTest.java b/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletBrowseTest.java
new file mode 100644 (file)
index 0000000..63e1234
--- /dev/null
@@ -0,0 +1,62 @@
+package org.apache.maven.archiva.web.repository;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import com.meterware.httpunit.GetMethodWebRequest;
+import com.meterware.httpunit.WebLink;
+import com.meterware.httpunit.WebRequest;
+import com.meterware.httpunit.WebResponse;
+
+import java.io.File;
+
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * RepositoryServletBrowseTest 
+ *
+ * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class RepositoryServletBrowseTest
+    extends AbstractRepositoryServletTestCase
+{
+    public void testBrowse()
+        throws Exception
+    {
+        new File( repoRootInternal, "org/apache/archiva" ).mkdirs();
+        new File( repoRootInternal, "net/sourceforge" ).mkdirs();
+        new File( repoRootInternal, "commons-lang" ).mkdirs();
+
+        WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" );
+        WebResponse response = sc.getResponse( request );
+        assertEquals( "Response", HttpServletResponse.SC_OK, response.getResponseCode() );
+
+        // dumpResponse( response );
+
+        WebLink links[] = response.getLinks();
+        String expectedLinks[] = new String[] { "./commons-lang/", "./net/", "./org/" };
+
+        assertEquals( "Links.length", expectedLinks.length, links.length );
+        for ( int i = 0; i < links.length; i++ )
+        {
+            assertEquals( "Link[" + i + "]", expectedLinks[i], links[i].getURLString() );
+        }
+    }
+}
diff --git a/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletDeployTest.java b/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletDeployTest.java
new file mode 100644 (file)
index 0000000..ec53e80
--- /dev/null
@@ -0,0 +1,62 @@
+package org.apache.maven.archiva.web.repository;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import com.meterware.httpunit.PutMethodWebRequest;
+import com.meterware.httpunit.WebRequest;
+import com.meterware.httpunit.WebResponse;
+
+import java.io.InputStream;
+
+import javax.servlet.http.HttpServletResponse;
+
+
+/**
+ * Deploy / Put Test cases for RepositoryServlet.  
+ *
+ * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class RepositoryServletDeployTest
+    extends AbstractRepositoryServletTestCase
+{
+    public void testPutWithMissingParentCollection()
+        throws Exception
+    {
+        setupCleanRepo( repoRootInternal );
+
+        String putUrl = "http://machine.com/repository/internal/path/to/artifact.jar";
+        InputStream is = getClass().getResourceAsStream( "/artifact.jar" );
+        assertNotNull( "artifact.jar inputstream", is );
+
+        WebRequest request = new PutMethodWebRequest( putUrl, is, "application/octet-stream" );
+
+        WebResponse response = sc.getResponse( request );
+        assertResponseCreated( response );
+        assertFileContents( "artifact.jar\n", repoRootInternal, "path/to/artifact.jar" );
+    }
+    
+    protected void assertResponseCreated( WebResponse response )
+    {
+        assertNotNull( "Should have recieved a response", response );
+        assertEquals( "Should have been a 201/CREATED response code.", HttpServletResponse.SC_CREATED, response
+            .getResponseCode() );
+    }
+}
diff --git a/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletNoProxyTest.java b/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletNoProxyTest.java
new file mode 100644 (file)
index 0000000..3c5b9ca
--- /dev/null
@@ -0,0 +1,220 @@
+package org.apache.maven.archiva.web.repository;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import com.meterware.httpunit.GetMethodWebRequest;
+import com.meterware.httpunit.WebRequest;
+import com.meterware.httpunit.WebResponse;
+
+import org.apache.commons.io.FileUtils;
+
+import java.io.File;
+
+/**
+ * RepositoryServletTest 
+ *
+ * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class RepositoryServletNoProxyTest
+    extends AbstractRepositoryServletTestCase
+{
+    public void testGetNoProxyChecksumDefaultLayout()
+        throws Exception
+    {
+        String commonsLangSha1 = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar.sha1";
+
+        File checksumFile = new File( repoRootInternal, commonsLangSha1 );
+        checksumFile.getParentFile().mkdirs();
+
+        FileUtils.writeStringToFile( checksumFile, "dummy-checksum", null );
+
+        WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangSha1 );
+        WebResponse response = sc.getResponse( request );
+        assertResponseOK( response );
+
+        assertEquals( "Expected file contents", "dummy-checksum", response.getText() );
+    }
+
+    public void testGetNoProxyChecksumLegacyLayout()
+        throws Exception
+    {
+        String commonsLangSha1 = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar.sha1";
+
+        File checksumFile = new File( repoRootInternal, commonsLangSha1 );
+        checksumFile.getParentFile().mkdirs();
+
+        FileUtils.writeStringToFile( checksumFile, "dummy-checksum", null );
+
+        WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/"
+            + "commons-lang/jars/commons-lang-2.1.jar.sha1" );
+        WebResponse response = sc.getResponse( request );
+        assertResponseOK( response );
+
+        assertEquals( "Expected file contents", "dummy-checksum", response.getText() );
+    }
+
+    public void testGetNoProxyVersionedMetadataDefaultLayout()
+        throws Exception
+    {
+        String commonsLangMetadata = "commons-lang/commons-lang/2.1/maven-metadata.xml";
+        String expectedMetadataContents = "dummy-versioned-metadata";
+
+        File metadataFile = new File( repoRootInternal, commonsLangMetadata );
+        metadataFile.getParentFile().mkdirs();
+
+        FileUtils.writeStringToFile( metadataFile, expectedMetadataContents, null );
+
+        WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangMetadata );
+        WebResponse response = sc.getResponse( request );
+        assertResponseOK( response );
+
+        assertEquals( "Expected file contents", expectedMetadataContents, response.getText() );
+    }
+
+    public void testGetNoProxyProjectMetadataDefaultLayout()
+        throws Exception
+    {
+        String commonsLangMetadata = "commons-lang/commons-lang/maven-metadata.xml";
+        String expectedMetadataContents = "dummy-project-metadata";
+
+        File metadataFile = new File( repoRootInternal, commonsLangMetadata );
+        metadataFile.getParentFile().mkdirs();
+
+        FileUtils.writeStringToFile( metadataFile, expectedMetadataContents, null );
+
+        WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangMetadata );
+        WebResponse response = sc.getResponse( request );
+        assertResponseOK( response );
+
+        assertEquals( "Expected file contents", expectedMetadataContents, response.getText() );
+    }
+
+    public void testGetNoProxyArtifactDefaultLayout()
+        throws Exception
+    {
+        String commonsLangJar = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar";
+        String expectedArtifactContents = "dummy-commons-lang-artifact";
+
+        File artifactFile = new File( repoRootInternal, commonsLangJar );
+        artifactFile.getParentFile().mkdirs();
+
+        FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null );
+
+        WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangJar );
+        WebResponse response = sc.getResponse( request );
+        assertResponseOK( response );
+
+        assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
+    }
+
+    public void testGetNoProxyArtifactLegacyLayout()
+        throws Exception
+    {
+        String commonsLangJar = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar";
+        String expectedArtifactContents = "dummy-commons-lang-artifact";
+
+        File artifactFile = new File( repoRootInternal, commonsLangJar );
+        artifactFile.getParentFile().mkdirs();
+
+        FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null );
+
+        WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/"
+            + "commons-lang/jars/commons-lang-2.1.jar" );
+        WebResponse response = sc.getResponse( request );
+        assertResponseOK( response );
+
+        assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
+    }
+
+    public void testGetNoProxySnapshotArtifactDefaultLayout()
+        throws Exception
+    {
+        String commonsLangJar = "commons-lang/commons-lang/2.1-SNAPSHOT/commons-lang-2.1-SNAPSHOT.jar";
+        String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
+
+        File artifactFile = new File( repoRootInternal, commonsLangJar );
+        artifactFile.getParentFile().mkdirs();
+
+        FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null );
+
+        WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangJar );
+        WebResponse response = sc.getResponse( request );
+        assertResponseOK( response );
+
+        assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
+    }
+
+    public void testGetNoProxySnapshotArtifactLegacyLayout()
+        throws Exception
+    {
+        String commonsLangJar = "commons-lang/commons-lang/2.1-SNAPSHOT/commons-lang-2.1-SNAPSHOT.jar";
+        String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
+
+        File artifactFile = new File( repoRootInternal, commonsLangJar );
+        artifactFile.getParentFile().mkdirs();
+
+        FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null );
+
+        WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/"
+            + "commons-lang/jars/commons-lang-2.1-SNAPSHOT.jar" );
+        WebResponse response = sc.getResponse( request );
+        assertResponseOK( response );
+
+        assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
+    }
+
+    public void testGetNoProxyTimestampedSnapshotArtifactDefaultLayout()
+        throws Exception
+    {
+        String commonsLangJar = "commons-lang/commons-lang/2.1-SNAPSHOT/commons-lang-2.1-20050821.023400-1.jar";
+        String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
+
+        File artifactFile = new File( repoRootInternal, commonsLangJar );
+        artifactFile.getParentFile().mkdirs();
+
+        FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null );
+
+        WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangJar );
+        WebResponse response = sc.getResponse( request );
+        assertResponseOK( response );
+
+        assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
+    }
+
+    public void testGetNoProxyTimestampedSnapshotArtifactLegacyLayout()
+        throws Exception
+    {
+        String commonsLangJar = "commons-lang/commons-lang/2.1-SNAPSHOT/commons-lang-2.1-20050821.023400-1.jar";
+        String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
+
+        File artifactFile = new File( repoRootInternal, commonsLangJar );
+        artifactFile.getParentFile().mkdirs();
+
+        FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null );
+
+        WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/"
+            + "commons-lang/jars/commons-lang-2.1-20050821.023400-1.jar" );
+        WebResponse response = sc.getResponse( request );
+        assertResponseOK( response );
+
+        assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
+    }
+}
diff --git a/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletProxiedReleasePolicyTest.java b/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletProxiedReleasePolicyTest.java
new file mode 100644 (file)
index 0000000..2e985e9
--- /dev/null
@@ -0,0 +1,193 @@
+package org.apache.maven.archiva.web.repository;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import com.meterware.httpunit.GetMethodWebRequest;
+import com.meterware.httpunit.HttpUnitOptions;
+import com.meterware.httpunit.WebRequest;
+import com.meterware.httpunit.WebResponse;
+
+import org.apache.maven.archiva.policies.ReleasesPolicy;
+
+import java.io.File;
+
+/**
+ * RepositoryServlet Tests, Proxied, Get of Release Artifacts, with varying policy settings. 
+ *
+ * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class RepositoryServletProxiedReleasePolicyTest
+    extends AbstractRepositoryServletProxiedTestCase
+{
+    public void testGetProxiedReleaseArtifactPolicyAlwaysManagedNewer()
+        throws Exception
+    {
+        assertGetProxiedReleaseArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, ReleasesPolicy.IGNORED, HAS_MANAGED_COPY,
+                                                   ( NEWER * OVER_ONE_DAY ) );
+    }
+
+    public void testGetProxiedReleaseArtifactPolicyAlwaysManagedOlder()
+        throws Exception
+    {
+        assertGetProxiedReleaseArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, ReleasesPolicy.IGNORED, HAS_MANAGED_COPY,
+                                                   ( OLDER * OVER_ONE_DAY ) );
+    }
+
+    public void testGetProxiedReleaseArtifactPolicyAlwaysNoManagedContent()
+        throws Exception
+    {
+        assertGetProxiedReleaseArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, ReleasesPolicy.IGNORED, NO_MANAGED_COPY );
+    }
+
+    public void testGetProxiedReleaseArtifactPolicyDailyFail()
+        throws Exception
+    {
+        assertGetProxiedReleaseArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, ReleasesPolicy.DAILY, HAS_MANAGED_COPY,
+                                                   ( NEWER * ONE_MINUTE ) );
+    }
+
+    public void testGetProxiedReleaseArtifactPolicyDailyNoManagedContent()
+        throws Exception
+    {
+        assertGetProxiedReleaseArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, ReleasesPolicy.DAILY, NO_MANAGED_COPY );
+    }
+
+    public void testGetProxiedReleaseArtifactPolicyDailyPass()
+        throws Exception
+    {
+        assertGetProxiedReleaseArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, ReleasesPolicy.DAILY, HAS_MANAGED_COPY,
+                                                   ( OLDER * OVER_ONE_DAY ) );
+    }
+
+    public void testGetProxiedReleaseArtifactPolicyDisabledFail()
+        throws Exception
+    {
+        assertGetProxiedReleaseArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, ReleasesPolicy.DISABLED, HAS_MANAGED_COPY );
+    }
+
+    public void testGetProxiedReleaseArtifactPolicyDisabledNoManagedContentFail()
+        throws Exception
+    {
+        assertGetProxiedReleaseArtifactWithPolicy( EXPECT_NOT_FOUND, ReleasesPolicy.DISABLED, NO_MANAGED_COPY );
+    }
+
+    public void testGetProxiedReleaseArtifactPolicyDisabledPass()
+        throws Exception
+    {
+        assertGetProxiedReleaseArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, ReleasesPolicy.DISABLED, HAS_MANAGED_COPY );
+    }
+
+    public void testGetProxiedReleaseArtifactPolicyHourlyFail()
+        throws Exception
+    {
+        assertGetProxiedReleaseArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, ReleasesPolicy.HOURLY, HAS_MANAGED_COPY,
+                                                   ( NEWER * ONE_MINUTE ) );
+    }
+
+    public void testGetProxiedReleaseArtifactPolicyHourlyNoManagedContent()
+        throws Exception
+    {
+        assertGetProxiedReleaseArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, ReleasesPolicy.HOURLY, NO_MANAGED_COPY );
+    }
+
+    public void testGetProxiedReleaseArtifactPolicyHourlyPass()
+        throws Exception
+    {
+        assertGetProxiedReleaseArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, ReleasesPolicy.HOURLY, HAS_MANAGED_COPY,
+                                                   ( OLDER * OVER_ONE_HOUR ) );
+    }
+
+    public void testGetProxiedReleaseArtifactPolicyOnceFail()
+        throws Exception
+    {
+        assertGetProxiedReleaseArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, ReleasesPolicy.ONCE, HAS_MANAGED_COPY );
+    }
+
+    public void testGetProxiedReleaseArtifactPolicyOnceNoManagedContent()
+        throws Exception
+    {
+        assertGetProxiedReleaseArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, ReleasesPolicy.ONCE, NO_MANAGED_COPY );
+    }
+
+    public void testGetProxiedReleaseArtifactPolicyOncePass()
+        throws Exception
+    {
+        assertGetProxiedReleaseArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, ReleasesPolicy.ONCE, NO_MANAGED_COPY );
+    }
+
+    private void assertGetProxiedReleaseArtifactWithPolicy( int expectation, String releasePolicy,
+                                                            boolean hasManagedCopy )
+        throws Exception
+    {
+        assertGetProxiedReleaseArtifactWithPolicy( expectation, releasePolicy, hasManagedCopy, 0 );
+    }
+
+    private void assertGetProxiedReleaseArtifactWithPolicy( int expectation, String releasePolicy,
+                                                            boolean hasManagedCopy, long deltaManagedToRemoteTimestamp )
+        throws Exception
+    {
+        // --- Setup
+        setupCentralRemoteRepo();
+        setupCleanInternalRepo();
+
+        String resourcePath = "org/apache/archiva/test/1.0/test-1.0.jar";
+        String expectedRemoteContents = "archiva-test-1.0|jar-remote-contents";
+        String expectedManagedContents = null;
+        File remoteFile = populateRepo( remoteCentral, resourcePath, expectedRemoteContents );
+
+        if ( hasManagedCopy )
+        {
+            expectedManagedContents = "archiva-test-1.0|jar-managed-contents";
+            File managedFile = populateRepo( repoRootInternal, resourcePath, expectedManagedContents );
+            managedFile.setLastModified( remoteFile.lastModified() + deltaManagedToRemoteTimestamp );
+        }
+
+        setupReleaseConnector( REPOID_INTERNAL, remoteCentral, releasePolicy );
+        saveConfiguration();
+
+        // --- Execution
+        // process the response code later, not via an exception.
+        HttpUnitOptions.setExceptionsThrownOnErrorStatus( false );
+
+        WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + resourcePath );
+        WebResponse response = sc.getResponse( request );
+
+        // --- Verification
+
+        switch ( expectation )
+        {
+            case EXPECT_MANAGED_CONTENTS:
+                assertResponseOK( response );
+                assertTrue( "Invalid Test Case: Can't expect managed contents with "
+                    + "test that doesn't have a managed copy in the first place.", hasManagedCopy );
+                assertEquals( "Expected managed file contents", expectedManagedContents, response.getText() );
+                break;
+            case EXPECT_REMOTE_CONTENTS:
+                assertResponseOK( response );
+                assertEquals( "Expected remote file contents", expectedRemoteContents, response.getText() );
+                break;
+            case EXPECT_NOT_FOUND:
+                assertResponseNotFound( response );
+                assertManagedFileNotExists( repoRootInternal, resourcePath );
+                break;
+        }
+    }
+}
diff --git a/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletProxiedSnapshotPolicyTest.java b/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletProxiedSnapshotPolicyTest.java
new file mode 100644 (file)
index 0000000..2167955
--- /dev/null
@@ -0,0 +1,195 @@
+package org.apache.maven.archiva.web.repository;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import com.meterware.httpunit.GetMethodWebRequest;
+import com.meterware.httpunit.HttpUnitOptions;
+import com.meterware.httpunit.WebRequest;
+import com.meterware.httpunit.WebResponse;
+
+import org.apache.maven.archiva.policies.SnapshotsPolicy;
+
+import java.io.File;
+
+/**
+ * RepositoryServlet Tests, Proxied, Get of Snapshot Artifacts, with varying policy settings. 
+ *
+ * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class RepositoryServletProxiedSnapshotPolicyTest
+    extends AbstractRepositoryServletProxiedTestCase
+{
+    public void testGetProxiedSnapshotsArtifactPolicyAlwaysManagedNewer()
+        throws Exception
+    {
+        assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, SnapshotsPolicy.IGNORED,
+                                                     HAS_MANAGED_COPY, ( NEWER * OVER_ONE_DAY ) );
+    }
+
+    public void testGetProxiedSnapshotsArtifactPolicyAlwaysManagedOlder()
+        throws Exception
+    {
+        assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.IGNORED, HAS_MANAGED_COPY,
+                                                     ( OLDER * OVER_ONE_DAY ) );
+    }
+
+    public void testGetProxiedSnapshotsArtifactPolicyAlwaysNoManagedContent()
+        throws Exception
+    {
+        assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.IGNORED, NO_MANAGED_COPY );
+    }
+
+    public void testGetProxiedSnapshotsArtifactPolicyDailyFail()
+        throws Exception
+    {
+        assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, SnapshotsPolicy.DAILY, HAS_MANAGED_COPY,
+                                                     ( NEWER * ONE_MINUTE ) );
+    }
+
+    public void testGetProxiedSnapshotsArtifactPolicyDailyNoManagedContent()
+        throws Exception
+    {
+        assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.DAILY, NO_MANAGED_COPY );
+    }
+
+    public void testGetProxiedSnapshotsArtifactPolicyDailyPass()
+        throws Exception
+    {
+        assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.DAILY, HAS_MANAGED_COPY,
+                                                     ( OLDER * OVER_ONE_DAY ) );
+    }
+
+    public void testGetProxiedSnapshotsArtifactPolicyDisabledFail()
+        throws Exception
+    {
+        assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, SnapshotsPolicy.DISABLED,
+                                                     HAS_MANAGED_COPY );
+    }
+
+    public void testGetProxiedSnapshotsArtifactPolicyDisabledNoManagedContentFail()
+        throws Exception
+    {
+        assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_NOT_FOUND, SnapshotsPolicy.DISABLED, NO_MANAGED_COPY );
+    }
+
+    public void testGetProxiedSnapshotsArtifactPolicyDisabledPass()
+        throws Exception
+    {
+        assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, SnapshotsPolicy.DISABLED,
+                                                     HAS_MANAGED_COPY );
+    }
+
+    public void testGetProxiedSnapshotsArtifactPolicyHourlyFail()
+        throws Exception
+    {
+        assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, SnapshotsPolicy.HOURLY, HAS_MANAGED_COPY,
+                                                     ( NEWER * ONE_MINUTE ) );
+    }
+
+    public void testGetProxiedSnapshotsArtifactPolicyHourlyNoManagedContent()
+        throws Exception
+    {
+        assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.HOURLY, NO_MANAGED_COPY );
+    }
+
+    public void testGetProxiedSnapshotsArtifactPolicyHourlyPass()
+        throws Exception
+    {
+        assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.HOURLY, HAS_MANAGED_COPY,
+                                                     ( OLDER * OVER_ONE_HOUR ) );
+    }
+
+    public void testGetProxiedSnapshotsArtifactPolicyOnceFail()
+        throws Exception
+    {
+        assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, SnapshotsPolicy.ONCE, HAS_MANAGED_COPY );
+    }
+
+    public void testGetProxiedSnapshotsArtifactPolicyOnceNoManagedContent()
+        throws Exception
+    {
+        assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.ONCE, NO_MANAGED_COPY );
+    }
+
+    public void testGetProxiedSnapshotsArtifactPolicyOncePass()
+        throws Exception
+    {
+        assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.ONCE, NO_MANAGED_COPY );
+    }
+
+    private void assertGetProxiedSnapshotsArtifactWithPolicy( int expectation, String snapshotsPolicy,
+                                                              boolean hasManagedCopy )
+        throws Exception
+    {
+        assertGetProxiedSnapshotsArtifactWithPolicy( expectation, snapshotsPolicy, hasManagedCopy, 0 );
+    }
+
+    private void assertGetProxiedSnapshotsArtifactWithPolicy( int expectation, String snapshotsPolicy,
+                                                              boolean hasManagedCopy, long deltaManagedToRemoteTimestamp )
+        throws Exception
+    {
+        // --- Setup
+        setupSnapshotsRemoteRepo();
+        setupCleanInternalRepo();
+
+        String resourcePath = "org/apache/archiva/test/2.0-SNAPSHOT/test-2.0-SNAPSHOT.jar";
+        String expectedRemoteContents = "archiva-test-2.0-SNAPSHOT|jar-remote-contents";
+        String expectedManagedContents = null;
+        File remoteFile = populateRepo( remoteSnapshots, resourcePath, expectedRemoteContents );
+
+        if ( hasManagedCopy )
+        {
+            expectedManagedContents = "archiva-test-2.0-SNAPSHOT|jar-managed-contents";
+            File managedFile = populateRepo( repoRootInternal, resourcePath, expectedManagedContents );
+            managedFile.setLastModified( remoteFile.lastModified() + deltaManagedToRemoteTimestamp );
+        }
+
+        setupSnapshotConnector( REPOID_INTERNAL, remoteSnapshots, snapshotsPolicy );
+        saveConfiguration();
+
+        // --- Execution
+        // process the response code later, not via an exception.
+        HttpUnitOptions.setExceptionsThrownOnErrorStatus( false );
+
+        WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + resourcePath );
+        WebResponse response = sc.getResponse( request );
+
+        // --- Verification
+
+        switch ( expectation )
+        {
+            case EXPECT_MANAGED_CONTENTS:
+                assertResponseOK( response );
+                assertTrue( "Invalid Test Case: Can't expect managed contents with "
+                    + "test that doesn't have a managed copy in the first place.", hasManagedCopy );
+                assertEquals( "Expected managed file contents", expectedManagedContents, response.getText() );
+                break;
+            case EXPECT_REMOTE_CONTENTS:
+                assertResponseOK( response );
+                assertEquals( "Expected remote file contents", expectedRemoteContents, response.getText() );
+                break;
+            case EXPECT_NOT_FOUND:
+                assertResponseNotFound( response );
+                assertManagedFileNotExists( repoRootInternal, resourcePath );
+                break;
+        }
+    }
+}
diff --git a/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletSecurityTest.java b/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletSecurityTest.java
new file mode 100644 (file)
index 0000000..f87cdb2
--- /dev/null
@@ -0,0 +1,21 @@
+package org.apache.maven.archiva.web.repository;
+
+/**
+ * RepositoryServletSecurityTest 
+ *
+ * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class RepositoryServletSecurityTest
+    extends AbstractRepositoryServletTestCase
+{
+    public void testSecuredGet()
+    {
+        
+    }
+    
+    public void testSecuredBrowse()
+    {
+        
+    }
+}
index f78ab2847ec2d50e58679763d53f4de0fb880512..71ff228b02c92b360935435edfffe5d6688ce5bf 100644 (file)
@@ -19,29 +19,10 @@ package org.apache.maven.archiva.web.repository;
  * under the License.
  */
 
-import com.meterware.httpunit.GetMethodWebRequest;
-import com.meterware.httpunit.PutMethodWebRequest;
-import com.meterware.httpunit.WebLink;
-import com.meterware.httpunit.WebRequest;
-import com.meterware.httpunit.WebResponse;
-import com.meterware.servletunit.ServletRunner;
-import com.meterware.servletunit.ServletUnitClient;
-
-import org.apache.commons.io.FileUtils;
-import org.apache.maven.archiva.configuration.ArchivaConfiguration;
 import org.apache.maven.archiva.configuration.Configuration;
 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
-import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration;
-import org.codehaus.plexus.PlexusConstants;
-import org.codehaus.plexus.PlexusTestCase;
-import org.codehaus.plexus.webdav.util.MimeTypes;
 
 import java.io.File;
-import java.io.IOException;
-
-import javax.servlet.ServletContext;
-import javax.servlet.http.HttpServletResponse;
-import javax.servlet.http.HttpSession;
 
 /**
  * RepositoryServletTest 
@@ -50,69 +31,21 @@ import javax.servlet.http.HttpSession;
  * @version $Id$
  */
 public class RepositoryServletTest
-    extends PlexusTestCase
+    extends AbstractRepositoryServletTestCase
 {
-    private ServletUnitClient sc;
-
-    private static final String REQUEST_PATH = "http://localhost/repository/internal/path/to/artifact.jar";
-
-    private File repositoryLocation;
-
-    private ArchivaConfiguration configuration;
-
-    private static final String REPOSITORY_ID = "internal";
+    private static final String REQUEST_PATH = "http://machine.com/repository/internal/";
 
     private static final String NEW_REPOSITORY_ID = "new-id";
 
     private static final String NEW_REPOSITORY_NAME = "New Repository";
 
-    protected void setUp()
-        throws Exception
-    {
-        super.setUp();
-
-        String appserverBase = getTestFile( "target/appserver-base" ).getAbsolutePath();
-        System.setProperty( "appserver.base", appserverBase );
-
-        File testConf = getTestFile( "src/test/resources/repository-archiva.xml" );
-        File testConfDest = new File( appserverBase, "conf/archiva.xml" );
-        FileUtils.copyFile( testConf, testConfDest );
-
-        configuration = (ArchivaConfiguration) lookup( ArchivaConfiguration.ROLE );
-        repositoryLocation = new File( appserverBase, "data/repositories/internal" );
-        Configuration config = configuration.getConfiguration();
-
-        config.addManagedRepository( createManagedRepository( "internal", "Internal Test Repo", repositoryLocation ) );
-        saveConfiguration();
-
-        ServletRunner sr = new ServletRunner();
-        sr.registerServlet( "/repository/*", UnauthenticatedRepositoryServlet.class.getName() );
-        sc = sr.newClient();
-        HttpSession session = sc.getSession( true );
-        ServletContext servletContext = session.getServletContext();
-        servletContext.setAttribute( PlexusConstants.PLEXUS_KEY, getContainer() );
-    }
-
-    public void testPutWithMissingParentCollection()
-        throws Exception
-    {
-        FileUtils.deleteDirectory( repositoryLocation );
-
-        WebRequest request = new PutMethodWebRequest( REQUEST_PATH, getClass().getResourceAsStream( "/artifact.jar" ),
-                                                      "application/octet-stream" );
-        WebResponse response = sc.getResponse( request );
-        assertNotNull( "Should have received response", response );
-        assertEquals( "file contents", "artifact.jar\n", FileUtils
-            .readFileToString( new File( repositoryLocation, "path/to/artifact.jar" ), null ) );
-    }
-
     public void testGetRepository()
         throws Exception
     {
         RepositoryServlet servlet = (RepositoryServlet) sc.newInvocation( REQUEST_PATH ).getServlet();
         assertNotNull( servlet );
 
-        assertRepositoryValid( servlet, REPOSITORY_ID );
+        assertRepositoryValid( servlet, REPOID_INTERNAL );
     }
 
     public void testGetRepositoryAfterDelete()
@@ -121,11 +54,11 @@ public class RepositoryServletTest
         RepositoryServlet servlet = (RepositoryServlet) sc.newInvocation( REQUEST_PATH ).getServlet();
         assertNotNull( servlet );
 
-        Configuration c = configuration.getConfiguration();
-        c.removeManagedRepository( c.findManagedRepositoryById( REPOSITORY_ID ) );
+        Configuration c = archivaConfiguration.getConfiguration();
+        c.removeManagedRepository( c.findManagedRepositoryById( REPOID_INTERNAL ) );
         saveConfiguration();
 
-        ManagedRepositoryConfiguration repository = servlet.getRepository( REPOSITORY_ID );
+        ManagedRepositoryConfiguration repository = servlet.getRepository( REPOID_INTERNAL );
         assertNull( repository );
     }
 
@@ -135,7 +68,7 @@ public class RepositoryServletTest
         RepositoryServlet servlet = (RepositoryServlet) sc.newInvocation( REQUEST_PATH ).getServlet();
         assertNotNull( servlet );
 
-        Configuration c = configuration.getConfiguration();
+        Configuration c = archivaConfiguration.getConfiguration();
         ManagedRepositoryConfiguration repo = new ManagedRepositoryConfiguration();
         repo.setId( NEW_REPOSITORY_ID );
         repo.setName( NEW_REPOSITORY_NAME );
@@ -153,324 +86,6 @@ public class RepositoryServletTest
         assertEquals( NEW_REPOSITORY_NAME, repository.getName() );
 
         // check other is still intact
-        assertRepositoryValid( servlet, REPOSITORY_ID );
-    }
-
-    public void testBrowse()
-        throws Exception
-    {
-        RepositoryServlet servlet = (RepositoryServlet) sc.newInvocation( REQUEST_PATH ).getServlet();
-        assertNotNull( servlet );
-        assertRepositoryValid( servlet, REPOSITORY_ID );
-
-        new File( repositoryLocation, "org/apache/archiva" ).mkdirs();
-        new File( repositoryLocation, "net/sourceforge" ).mkdirs();
-        new File( repositoryLocation, "commons-lang" ).mkdirs();
-
-        WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" );
-        WebResponse response = sc.getResponse( request );
-        assertEquals( "Response", HttpServletResponse.SC_OK, response.getResponseCode() );
-
-        // dumpResponse( response );
-
-        WebLink links[] = response.getLinks();
-        String expectedLinks[] = new String[] { "./commons-lang/", "./net/", "./org/", "./path/" };
-
-        assertEquals( "Links.length", expectedLinks.length, links.length );
-        for ( int i = 0; i < links.length; i++ )
-        {
-            assertEquals( "Link[" + i + "]", expectedLinks[i], links[i].getURLString() );
-        }
-    }
-
-    public void testGetNoProxyChecksumDefaultLayout()
-        throws Exception
-    {
-        RepositoryServlet servlet = (RepositoryServlet) sc.newInvocation( REQUEST_PATH ).getServlet();
-        assertNotNull( servlet );
-        assertRepositoryValid( servlet, REPOSITORY_ID );
-
-        String commonsLangSha1 = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar.sha1";
-
-        File checksumFile = new File( repositoryLocation, commonsLangSha1 );
-        checksumFile.getParentFile().mkdirs();
-
-        FileUtils.writeStringToFile( checksumFile, "dummy-checksum", null );
-        
-        WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangSha1 );
-        WebResponse response = sc.getResponse( request );
-        assertEquals( "Response OK", HttpServletResponse.SC_OK, response.getResponseCode() );
-
-        assertEquals( "Expected file contents", "dummy-checksum", response.getText() );
-    }
-    
-    public void testGetNoProxyChecksumLegacyLayout()
-        throws Exception
-    {
-        RepositoryServlet servlet = (RepositoryServlet) sc.newInvocation( REQUEST_PATH ).getServlet();
-        assertNotNull( servlet );
-        assertRepositoryValid( servlet, REPOSITORY_ID );
-
-        String commonsLangSha1 = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar.sha1";
-
-        File checksumFile = new File( repositoryLocation, commonsLangSha1 );
-        checksumFile.getParentFile().mkdirs();
-
-        FileUtils.writeStringToFile( checksumFile, "dummy-checksum", null );
-
-        WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + 
-                                                      "commons-lang/jars/commons-lang-2.1.jar.sha1" );
-        WebResponse response = sc.getResponse( request );
-        assertEquals( "Response OK", HttpServletResponse.SC_OK, response.getResponseCode() );
-
-        assertEquals( "Expected file contents", "dummy-checksum", response.getText() );
-    }
-    
-    public void testGetNoProxyVersionedMetadataDefaultLayout()
-        throws Exception
-    {
-        RepositoryServlet servlet = (RepositoryServlet) sc.newInvocation( REQUEST_PATH ).getServlet();
-        assertNotNull( servlet );
-        assertRepositoryValid( servlet, REPOSITORY_ID );
-
-        String commonsLangMetadata = "commons-lang/commons-lang/2.1/maven-metadata.xml";
-        String expectedMetadataContents = "dummy-versioned-metadata";
-
-        File metadataFile = new File( repositoryLocation, commonsLangMetadata );
-        metadataFile.getParentFile().mkdirs();
-
-        FileUtils.writeStringToFile( metadataFile, expectedMetadataContents, null );
-
-        WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangMetadata );
-        WebResponse response = sc.getResponse( request );
-        assertEquals( "Response OK", HttpServletResponse.SC_OK, response.getResponseCode() );
-
-        assertEquals( "Expected file contents", expectedMetadataContents, response.getText() );
-    }
-    
-    public void testGetNoProxyProjectMetadataDefaultLayout()
-        throws Exception
-    {
-        RepositoryServlet servlet = (RepositoryServlet) sc.newInvocation( REQUEST_PATH ).getServlet();
-        assertNotNull( servlet );
-        assertRepositoryValid( servlet, REPOSITORY_ID );
-
-        String commonsLangMetadata = "commons-lang/commons-lang/maven-metadata.xml";
-        String expectedMetadataContents = "dummy-project-metadata";
-
-        File metadataFile = new File( repositoryLocation, commonsLangMetadata );
-        metadataFile.getParentFile().mkdirs();
-
-        FileUtils.writeStringToFile( metadataFile, expectedMetadataContents, null );
-
-        WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangMetadata );
-        WebResponse response = sc.getResponse( request );
-        assertEquals( "Response OK", HttpServletResponse.SC_OK, response.getResponseCode() );
-
-        assertEquals( "Expected file contents", expectedMetadataContents, response.getText() );
-    }
-    
-    public void testGetNoProxyArtifactDefaultLayout()
-        throws Exception
-    {
-        RepositoryServlet servlet = (RepositoryServlet) sc.newInvocation( REQUEST_PATH ).getServlet();
-        assertNotNull( servlet );
-        assertRepositoryValid( servlet, REPOSITORY_ID );
-
-        String commonsLangJar = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar";
-        String expectedArtifactContents = "dummy-commons-lang-artifact";
-
-        File artifactFile = new File( repositoryLocation, commonsLangJar );
-        artifactFile.getParentFile().mkdirs();
-
-        FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null );
-
-        WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangJar );
-        WebResponse response = sc.getResponse( request );
-        assertEquals( "Response OK", HttpServletResponse.SC_OK, response.getResponseCode() );
-
-        assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
-    }
-    
-    public void testGetNoProxyArtifactLegacyLayout()
-        throws Exception
-    {
-        RepositoryServlet servlet = (RepositoryServlet) sc.newInvocation( REQUEST_PATH ).getServlet();
-        assertNotNull( servlet );
-        assertRepositoryValid( servlet, REPOSITORY_ID );
-
-        String commonsLangJar = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar";
-        String expectedArtifactContents = "dummy-commons-lang-artifact";
-
-        File artifactFile = new File( repositoryLocation, commonsLangJar );
-        artifactFile.getParentFile().mkdirs();
-
-        FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null );
-
-        WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + 
-                                                      "commons-lang/jars/commons-lang-2.1.jar" );
-        WebResponse response = sc.getResponse( request );
-        assertEquals( "Response OK", HttpServletResponse.SC_OK, response.getResponseCode() );
-
-        assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
-    }
-    
-    public void testGetNoProxySnapshotArtifactDefaultLayout()
-        throws Exception
-    {
-        RepositoryServlet servlet = (RepositoryServlet) sc.newInvocation( REQUEST_PATH ).getServlet();
-        assertNotNull( servlet );
-        assertRepositoryValid( servlet, REPOSITORY_ID );
-
-        String commonsLangJar = "commons-lang/commons-lang/2.1-SNAPSHOT/commons-lang-2.1-SNAPSHOT.jar";
-        String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
-
-        File artifactFile = new File( repositoryLocation, commonsLangJar );
-        artifactFile.getParentFile().mkdirs();
-
-        FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null );
-
-        WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangJar );
-        WebResponse response = sc.getResponse( request );
-        assertEquals( "Response OK", HttpServletResponse.SC_OK, response.getResponseCode() );
-
-        assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
-    }
-    
-    public void testGetNoProxySnapshotArtifactLegacyLayout()
-        throws Exception
-    {
-        RepositoryServlet servlet = (RepositoryServlet) sc.newInvocation( REQUEST_PATH ).getServlet();
-        assertNotNull( servlet );
-        assertRepositoryValid( servlet, REPOSITORY_ID );
-
-        String commonsLangJar = "commons-lang/commons-lang/2.1-SNAPSHOT/commons-lang-2.1-SNAPSHOT.jar";
-        String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
-
-        File artifactFile = new File( repositoryLocation, commonsLangJar );
-        artifactFile.getParentFile().mkdirs();
-
-        FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null );
-
-        WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + 
-                                                      "commons-lang/jars/commons-lang-2.1-SNAPSHOT.jar" );
-        WebResponse response = sc.getResponse( request );
-        assertEquals( "Response OK", HttpServletResponse.SC_OK, response.getResponseCode() );
-
-        assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
-    }
-    
-    public void testGetNoProxyTimestampedSnapshotArtifactDefaultLayout()
-        throws Exception
-    {
-        RepositoryServlet servlet = (RepositoryServlet) sc.newInvocation( REQUEST_PATH ).getServlet();
-        assertNotNull( servlet );
-        assertRepositoryValid( servlet, REPOSITORY_ID );
-
-        String commonsLangJar = "commons-lang/commons-lang/2.1-SNAPSHOT/commons-lang-2.1-20050821.023400-1.jar";
-        String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
-
-        File artifactFile = new File( repositoryLocation, commonsLangJar );
-        artifactFile.getParentFile().mkdirs();
-
-        FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null );
-
-        WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangJar );
-        WebResponse response = sc.getResponse( request );
-        assertEquals( "Response OK", HttpServletResponse.SC_OK, response.getResponseCode() );
-
-        assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
-    }
-    
-    public void testGetNoProxyTimestampedSnapshotArtifactLegacyLayout()
-        throws Exception
-    {
-        RepositoryServlet servlet = (RepositoryServlet) sc.newInvocation( REQUEST_PATH ).getServlet();
-        assertNotNull( servlet );
-        assertRepositoryValid( servlet, REPOSITORY_ID );
-
-        String commonsLangJar = "commons-lang/commons-lang/2.1-SNAPSHOT/commons-lang-2.1-20050821.023400-1.jar";
-        String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
-
-        File artifactFile = new File( repositoryLocation, commonsLangJar );
-        artifactFile.getParentFile().mkdirs();
-
-        FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null );
-
-        WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/"
-            + "commons-lang/jars/commons-lang-2.1-20050821.023400-1.jar" );
-        WebResponse response = sc.getResponse( request );
-        assertEquals( "Response OK", HttpServletResponse.SC_OK, response.getResponseCode() );
-
-        assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
-    }
-    
-    public void testMimeTypesAvailable()
-        throws Exception
-    {
-        MimeTypes mimeTypes = (MimeTypes) lookup( MimeTypes.class );
-        assertNotNull( mimeTypes );
-        
-        // Test for some added types.
-        assertEquals( "sha1", "text/plain", mimeTypes.getMimeType( "foo.sha1" ) );
-        assertEquals( "md5", "text/plain", mimeTypes.getMimeType( "foo.md5" ) );
-        assertEquals( "pgp", "application/pgp-encrypted", mimeTypes.getMimeType( "foo.pgp" ) );
-        assertEquals( "jar", "application/java-archive", mimeTypes.getMimeType( "foo.jar" ) );
-    }
-
-    public static void dumpResponse( WebResponse response )
-    {
-        System.out.println( "---(response)---" );
-        System.out.println( "" + response.getResponseCode() + " " + response.getResponseMessage() );
-
-        String headerNames[] = response.getHeaderFieldNames();
-        for ( String headerName : headerNames )
-        {
-            System.out.println( "[header] " + headerName + ": " + response.getHeaderField( headerName ) );
-        }
-
-        System.out.println( "---(text)---" );
-        try
-        {
-            System.out.println( response.getText() );
-        }
-        catch ( IOException e )
-        {
-            System.err.print( "[Exception] : " );
-            e.printStackTrace( System.err );
-        }
-    }
-
-    private void assertRepositoryValid( RepositoryServlet servlet, String repoId )
-    {
-        ManagedRepositoryConfiguration repository = servlet.getRepository( repoId );
-        assertNotNull( "Archiva Managed Repository id:<" + repoId + "> should exist.", repository );
-        File repoRoot = new File( repository.getLocation() );
-        assertTrue( "Archiva Managed Repository id:<" + repoId + "> should have a valid location on disk.", 
-                    repoRoot.exists() && repoRoot.isDirectory() );
-    }
-
-    private void saveConfiguration()
-        throws Exception
-    {
-        configuration.save( configuration.getConfiguration() );
-    }
-
-    private ManagedRepositoryConfiguration createManagedRepository( String id, String name, File location )
-    {
-        ManagedRepositoryConfiguration repo = new ManagedRepositoryConfiguration();
-        repo.setId( id );
-        repo.setName( name );
-        repo.setLocation( location.getAbsolutePath() );
-        return repo;
-    }
-
-    private RemoteRepositoryConfiguration createRemoteRepository( String id, String name, String url )
-    {
-        RemoteRepositoryConfiguration repo = new RemoteRepositoryConfiguration();
-        repo.setId( id );
-        repo.setName( name );
-        repo.setUrl( url );
-        return repo;
+        assertRepositoryValid( servlet, REPOID_INTERNAL );
     }
 }
index 843455e0612f523ffad804bb0186e5e699323ef3..7e5f063cfe81515822de3ab020b1f7e22768d800 100644 (file)
@@ -1,11 +1,5 @@
 package org.apache.maven.archiva.web.repository;
 
-import org.codehaus.plexus.webdav.servlet.DavServerRequest;
-
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -25,6 +19,18 @@ import java.io.IOException;
  * under the License.
  */
 
+import org.codehaus.plexus.webdav.servlet.DavServerRequest;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+
+/**
+ * UnauthenticatedRepositoryServlet 
+ *
+ * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
+ * @version $Id$
+ */
 public class UnauthenticatedRepositoryServlet
     extends RepositoryServlet
 {
@@ -33,4 +39,11 @@ public class UnauthenticatedRepositoryServlet
     {
         return true;
     }
+    
+    @Override
+    public boolean isAuthenticated( DavServerRequest davRequest, HttpServletResponse response )
+        throws ServletException, IOException
+    {
+        return true;
+    }
 }
diff --git a/archiva-web/archiva-webapp/src/test/resources/META-INF/plexus/components.xml b/archiva-web/archiva-webapp/src/test/resources/META-INF/plexus/components.xml
new file mode 100644 (file)
index 0000000..1cb2190
--- /dev/null
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one
+  ~ or more contributor license agreements.  See the NOTICE file
+  ~ distributed with this work for additional information
+  ~ regarding copyright ownership.  The ASF licenses this file
+  ~ to you under the Apache License, Version 2.0 (the
+  ~ "License"); you may not use this file except in compliance
+  ~ with the License.  You may obtain a copy of the License at
+  ~
+  ~   http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing,
+  ~ software distributed under the License is distributed on an
+  ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  ~ KIND, either express or implied.  See the License for the
+  ~ specific language governing permissions and limitations
+  ~ under the License.
+  -->
+
+<component-set>
+  <components>
+    <!-- Components that are common for all test cases -->
+    <component>
+      <role>org.codehaus.plexus.webdav.util.MimeTypes</role>
+      <implementation>org.codehaus.plexus.webdav.util.MimeTypes</implementation>
+      <description>MimeTypes</description>
+      <configuration>
+        <resource>archiva-mime-types.txt</resource>
+      </configuration>
+    </component>
+  </components>
+</component-set>
\ No newline at end of file
diff --git a/archiva-web/archiva-webapp/src/test/resources/org/apache/maven/archiva/web/repository/RepositoryServletSecurityTest.xml b/archiva-web/archiva-webapp/src/test/resources/org/apache/maven/archiva/web/repository/RepositoryServletSecurityTest.xml
new file mode 100644 (file)
index 0000000..beccf43
--- /dev/null
@@ -0,0 +1,265 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one
+  ~ or more contributor license agreements.  See the NOTICE file
+  ~ distributed with this work for additional information
+  ~ regarding copyright ownership.  The ASF licenses this file
+  ~ to you under the Apache License, Version 2.0 (the
+  ~ "License"); you may not use this file except in compliance
+  ~ with the License.  You may obtain a copy of the License at
+  ~
+  ~  http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing,
+  ~ software distributed under the License is distributed on an
+  ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  ~ KIND, either express or implied.  See the License for the
+  ~ specific language governing permissions and limitations
+  ~ under the License.
+  -->
+
+<plexus>
+  <components>
+    <!--
+     | Logger manager
+     -->
+    <component>
+      <role>org.codehaus.plexus.logging.LoggerManager</role>
+      <implementation>org.codehaus.plexus.logging.slf4j.Slf4jLoggerManager</implementation>
+      <lifecycle-handler>basic</lifecycle-handler>
+    </component>
+
+    <!--
+     | Configuration
+     -->
+    <component>
+      <role>org.apache.maven.archiva.configuration.ArchivaConfiguration</role>
+      <implementation>org.apache.maven.archiva.configuration.DefaultArchivaConfiguration</implementation>
+      <requirements>
+        <requirement>
+          <role>org.codehaus.plexus.registry.Registry</role>
+          <role-hint>configured</role-hint>
+        </requirement>
+      </requirements>
+    </component>
+    <component>
+      <role>org.codehaus.plexus.registry.Registry</role>
+      <role-hint>configured</role-hint>
+      <implementation>org.codehaus.plexus.registry.commons.CommonsConfigurationRegistry</implementation>
+      <configuration>
+        <properties>
+          <system/>
+          <xml fileName="${appserver.base}/conf/archiva.xml"
+               config-name="org.apache.maven.archiva.base" config-at="org.apache.maven.archiva"/>
+        </properties>
+      </configuration>
+    </component>
+    
+    <component>
+      <role>org.codehaus.plexus.webdav.DavServerManager</role>
+      <role-hint>default</role-hint>
+      <implementation>org.codehaus.plexus.webdav.DefaultDavServerManager</implementation>
+      <description>DefaultDavServerManager</description>
+      <configuration>
+        <provider-hint>proxied</provider-hint>
+      </configuration>
+    </component>
+    
+    <component>
+      <role>org.codehaus.plexus.cache.Cache</role>
+      <role-hint>url-failures-cache</role-hint>
+      <implementation>org.codehaus.plexus.cache.ehcache.EhcacheCache</implementation>
+      <description>URL Failure Cache</description>
+      <configuration>
+        <disk-expiry-thread-interval-seconds>600</disk-expiry-thread-interval-seconds>
+        <disk-persistent>false</disk-persistent> <!--disabling disk persistence for unit testing. -->
+        <disk-store-path>${java.io.tmpdir}/archiva/urlcache</disk-store-path>
+        <eternal>false</eternal>
+        <max-elements-in-memory>1000</max-elements-in-memory>
+        <memory-eviction-policy>LRU</memory-eviction-policy>
+        <name>url-failures-cache</name>
+        <overflow-to-disk>false</overflow-to-disk>
+        <!-- 45 minutes = 2700 seconds -->
+        <time-to-idle-seconds>2700</time-to-idle-seconds>
+        <!-- 30 minutes = 1800 seconds  -->
+        <time-to-live-seconds>1800</time-to-live-seconds>
+      </configuration>
+    </component>    
+    
+    
+    <!-- Don't drag in the world just to test this -->
+    <component>
+      <role>org.apache.maven.archiva.repository.scanner.RepositoryContentConsumers</role>
+      <role-hint>default</role-hint>
+      <implementation>org.apache.maven.archiva.web.repository.StubRepositoryContentConsumers</implementation>
+    </component>
+
+    <!-- TODO: shouldn't need so many components just to use in-memory - is flaky since these are auto-generated -->
+    <component>
+      <role>org.codehaus.plexus.redback.system.SecuritySystem</role>
+      <role-hint>default</role-hint>
+      <implementation>org.codehaus.plexus.redback.system.DefaultSecuritySystem</implementation>
+      <requirements>
+        <requirement>
+          <role>org.codehaus.plexus.redback.authentication.AuthenticationManager</role>
+          <field-name>authnManager</field-name>
+        </requirement>
+        <requirement>
+          <role>org.codehaus.plexus.redback.authorization.Authorizer</role>
+          <role-hint>rbac</role-hint>
+          <field-name>authorizer</field-name>
+        </requirement>
+        <requirement>
+          <role>org.codehaus.plexus.redback.users.UserManager</role>
+          <role-hint>memory</role-hint>
+          <field-name>userManager</field-name>
+        </requirement>
+        <requirement>
+          <role>org.codehaus.plexus.redback.keys.KeyManager</role>
+          <role-hint>memory</role-hint>
+          <field-name>keyManager</field-name>
+        </requirement>
+        <requirement>
+          <role>org.codehaus.plexus.redback.policy.UserSecurityPolicy</role>
+          <field-name>policy</field-name>
+        </requirement>
+      </requirements>
+    </component>
+
+    <component>
+      <role>org.codehaus.plexus.redback.authentication.Authenticator</role>
+      <role-hint>user-manager</role-hint>
+      <implementation>org.codehaus.plexus.redback.authentication.users.UserManagerAuthenticator</implementation>
+      <requirements>
+        <requirement>
+          <role>org.codehaus.plexus.redback.users.UserManager</role>
+          <role-hint>memory</role-hint>
+          <field-name>userManager</field-name>
+        </requirement>
+        <requirement>
+          <role>org.codehaus.plexus.redback.policy.UserSecurityPolicy</role>
+          <field-name>securityPolicy</field-name>
+        </requirement>
+      </requirements>
+    </component>
+
+    <component>
+      <role>org.codehaus.plexus.redback.authentication.Authenticator</role>
+      <role-hint>keystore</role-hint>
+      <implementation>org.codehaus.plexus.redback.authentication.keystore.KeyStoreAuthenticator</implementation>
+      <requirements>
+        <requirement>
+          <role>org.codehaus.plexus.redback.keys.KeyManager</role>
+          <role-hint>memory</role-hint>
+          <field-name>keystore</field-name>
+        </requirement>
+        <requirement>
+          <role>org.codehaus.plexus.redback.users.UserManager</role>
+          <role-hint>memory</role-hint>
+          <field-name>userManager</field-name>
+        </requirement>
+      </requirements>
+    </component>
+
+    <component>
+      <role>org.codehaus.plexus.redback.authorization.rbac.evaluator.PermissionEvaluator</role>
+      <role-hint>default</role-hint>
+      <implementation>org.codehaus.plexus.redback.authorization.rbac.evaluator.DefaultPermissionEvaluator
+      </implementation>
+      <requirements>
+        <requirement>
+          <role>org.codehaus.plexus.redback.users.UserManager</role>
+          <role-hint>memory</role-hint>
+          <field-name>userManager</field-name>
+        </requirement>
+      </requirements>
+    </component>
+
+    <component>
+      <role>org.codehaus.plexus.redback.authorization.Authorizer</role>
+      <role-hint>rbac</role-hint>
+      <implementation>org.codehaus.plexus.redback.authorization.rbac.RbacAuthorizer</implementation>
+      <requirements>
+        <requirement>
+          <role>org.codehaus.plexus.redback.rbac.RBACManager</role>
+          <role-hint>memory</role-hint>
+          <field-name>manager</field-name>
+        </requirement>
+        <requirement>
+          <role>org.codehaus.plexus.redback.users.UserManager</role>
+          <role-hint>memory</role-hint>
+          <field-name>userManager</field-name>
+        </requirement>
+        <requirement>
+          <role>org.codehaus.plexus.redback.authorization.rbac.evaluator.PermissionEvaluator</role>
+          <role-hint>default</role-hint>
+          <field-name>evaluator</field-name>
+        </requirement>
+      </requirements>
+    </component>
+
+    <component>
+      <role>org.codehaus.plexus.redback.role.RoleManager</role>
+      <role-hint>default</role-hint>
+      <implementation>org.codehaus.plexus.redback.role.DefaultRoleManager</implementation>
+      <instantiation-strategy>singleton</instantiation-strategy>
+      <requirements>
+        <requirement>
+          <role>org.codehaus.plexus.redback.role.merger.RoleModelMerger</role>
+          <role-hint>default</role-hint>
+          <field-name>modelMerger</field-name>
+        </requirement>
+        <requirement>
+          <role>org.codehaus.plexus.redback.role.validator.RoleModelValidator</role>
+          <role-hint>default</role-hint>
+          <field-name>modelValidator</field-name>
+        </requirement>
+        <requirement>
+          <role>org.codehaus.plexus.redback.role.processor.RoleModelProcessor</role>
+          <role-hint>default</role-hint>
+          <field-name>modelProcessor</field-name>
+        </requirement>
+        <requirement>
+          <role>org.codehaus.plexus.redback.role.template.RoleTemplateProcessor</role>
+          <role-hint>default</role-hint>
+          <field-name>templateProcessor</field-name>
+        </requirement>
+        <requirement>
+          <role>org.codehaus.plexus.redback.rbac.RBACManager</role>
+          <role-hint>memory</role-hint>
+          <field-name>rbacManager</field-name>
+        </requirement>
+        <requirement>
+          <role>org.codehaus.plexus.PlexusContainer</role>
+          <field-name>container</field-name>
+        </requirement>
+      </requirements>
+    </component>
+
+    <component>
+      <role>org.codehaus.plexus.redback.role.processor.RoleModelProcessor</role>
+      <role-hint>default</role-hint>
+      <implementation>org.codehaus.plexus.redback.role.processor.DefaultRoleModelProcessor</implementation>
+      <requirements>
+        <requirement>
+          <role>org.codehaus.plexus.redback.rbac.RBACManager</role>
+          <role-hint>memory</role-hint>
+          <field-name>rbacManager</field-name>
+        </requirement>
+      </requirements>
+    </component>
+
+    <component>
+      <role>org.codehaus.plexus.redback.role.template.RoleTemplateProcessor</role>
+      <role-hint>default</role-hint>
+      <implementation>org.codehaus.plexus.redback.role.template.DefaultRoleTemplateProcessor</implementation>
+      <requirements>
+        <requirement>
+          <role>org.codehaus.plexus.redback.rbac.RBACManager</role>
+          <role-hint>memory</role-hint>
+          <field-name>rbacManager</field-name>
+        </requirement>
+      </requirements>
+    </component>
+  </components>
+</plexus>
index beccf43c939d8fd98fe846206393be24826887e6..974e148d29c5c1050484d4996205ebf50a2a2a7d 100644 (file)
       <role-hint>default</role-hint>
       <implementation>org.apache.maven.archiva.web.repository.StubRepositoryContentConsumers</implementation>
     </component>
-
-    <!-- TODO: shouldn't need so many components just to use in-memory - is flaky since these are auto-generated -->
+    
     <component>
       <role>org.codehaus.plexus.redback.system.SecuritySystem</role>
       <role-hint>default</role-hint>
-      <implementation>org.codehaus.plexus.redback.system.DefaultSecuritySystem</implementation>
-      <requirements>
-        <requirement>
-          <role>org.codehaus.plexus.redback.authentication.AuthenticationManager</role>
-          <field-name>authnManager</field-name>
-        </requirement>
-        <requirement>
-          <role>org.codehaus.plexus.redback.authorization.Authorizer</role>
-          <role-hint>rbac</role-hint>
-          <field-name>authorizer</field-name>
-        </requirement>
-        <requirement>
-          <role>org.codehaus.plexus.redback.users.UserManager</role>
-          <role-hint>memory</role-hint>
-          <field-name>userManager</field-name>
-        </requirement>
-        <requirement>
-          <role>org.codehaus.plexus.redback.keys.KeyManager</role>
-          <role-hint>memory</role-hint>
-          <field-name>keyManager</field-name>
-        </requirement>
-        <requirement>
-          <role>org.codehaus.plexus.redback.policy.UserSecurityPolicy</role>
-          <field-name>policy</field-name>
-        </requirement>
-      </requirements>
-    </component>
-
-    <component>
-      <role>org.codehaus.plexus.redback.authentication.Authenticator</role>
-      <role-hint>user-manager</role-hint>
-      <implementation>org.codehaus.plexus.redback.authentication.users.UserManagerAuthenticator</implementation>
-      <requirements>
-        <requirement>
-          <role>org.codehaus.plexus.redback.users.UserManager</role>
-          <role-hint>memory</role-hint>
-          <field-name>userManager</field-name>
-        </requirement>
-        <requirement>
-          <role>org.codehaus.plexus.redback.policy.UserSecurityPolicy</role>
-          <field-name>securityPolicy</field-name>
-        </requirement>
-      </requirements>
-    </component>
-
-    <component>
-      <role>org.codehaus.plexus.redback.authentication.Authenticator</role>
-      <role-hint>keystore</role-hint>
-      <implementation>org.codehaus.plexus.redback.authentication.keystore.KeyStoreAuthenticator</implementation>
-      <requirements>
-        <requirement>
-          <role>org.codehaus.plexus.redback.keys.KeyManager</role>
-          <role-hint>memory</role-hint>
-          <field-name>keystore</field-name>
-        </requirement>
-        <requirement>
-          <role>org.codehaus.plexus.redback.users.UserManager</role>
-          <role-hint>memory</role-hint>
-          <field-name>userManager</field-name>
-        </requirement>
-      </requirements>
-    </component>
-
-    <component>
-      <role>org.codehaus.plexus.redback.authorization.rbac.evaluator.PermissionEvaluator</role>
-      <role-hint>default</role-hint>
-      <implementation>org.codehaus.plexus.redback.authorization.rbac.evaluator.DefaultPermissionEvaluator
-      </implementation>
-      <requirements>
-        <requirement>
-          <role>org.codehaus.plexus.redback.users.UserManager</role>
-          <role-hint>memory</role-hint>
-          <field-name>userManager</field-name>
-        </requirement>
-      </requirements>
-    </component>
-
-    <component>
-      <role>org.codehaus.plexus.redback.authorization.Authorizer</role>
-      <role-hint>rbac</role-hint>
-      <implementation>org.codehaus.plexus.redback.authorization.rbac.RbacAuthorizer</implementation>
-      <requirements>
-        <requirement>
-          <role>org.codehaus.plexus.redback.rbac.RBACManager</role>
-          <role-hint>memory</role-hint>
-          <field-name>manager</field-name>
-        </requirement>
-        <requirement>
-          <role>org.codehaus.plexus.redback.users.UserManager</role>
-          <role-hint>memory</role-hint>
-          <field-name>userManager</field-name>
-        </requirement>
-        <requirement>
-          <role>org.codehaus.plexus.redback.authorization.rbac.evaluator.PermissionEvaluator</role>
-          <role-hint>default</role-hint>
-          <field-name>evaluator</field-name>
-        </requirement>
-      </requirements>
-    </component>
-
-    <component>
-      <role>org.codehaus.plexus.redback.role.RoleManager</role>
-      <role-hint>default</role-hint>
-      <implementation>org.codehaus.plexus.redback.role.DefaultRoleManager</implementation>
-      <instantiation-strategy>singleton</instantiation-strategy>
-      <requirements>
-        <requirement>
-          <role>org.codehaus.plexus.redback.role.merger.RoleModelMerger</role>
-          <role-hint>default</role-hint>
-          <field-name>modelMerger</field-name>
-        </requirement>
-        <requirement>
-          <role>org.codehaus.plexus.redback.role.validator.RoleModelValidator</role>
-          <role-hint>default</role-hint>
-          <field-name>modelValidator</field-name>
-        </requirement>
-        <requirement>
-          <role>org.codehaus.plexus.redback.role.processor.RoleModelProcessor</role>
-          <role-hint>default</role-hint>
-          <field-name>modelProcessor</field-name>
-        </requirement>
-        <requirement>
-          <role>org.codehaus.plexus.redback.role.template.RoleTemplateProcessor</role>
-          <role-hint>default</role-hint>
-          <field-name>templateProcessor</field-name>
-        </requirement>
-        <requirement>
-          <role>org.codehaus.plexus.redback.rbac.RBACManager</role>
-          <role-hint>memory</role-hint>
-          <field-name>rbacManager</field-name>
-        </requirement>
-        <requirement>
-          <role>org.codehaus.plexus.PlexusContainer</role>
-          <field-name>container</field-name>
-        </requirement>
-      </requirements>
-    </component>
-
-    <component>
-      <role>org.codehaus.plexus.redback.role.processor.RoleModelProcessor</role>
-      <role-hint>default</role-hint>
-      <implementation>org.codehaus.plexus.redback.role.processor.DefaultRoleModelProcessor</implementation>
-      <requirements>
-        <requirement>
-          <role>org.codehaus.plexus.redback.rbac.RBACManager</role>
-          <role-hint>memory</role-hint>
-          <field-name>rbacManager</field-name>
-        </requirement>
-      </requirements>
+      <implementation>org.apache.maven.archiva.web.repository.BypassSecuritySystem</implementation>
     </component>
 
-    <component>
-      <role>org.codehaus.plexus.redback.role.template.RoleTemplateProcessor</role>
-      <role-hint>default</role-hint>
-      <implementation>org.codehaus.plexus.redback.role.template.DefaultRoleTemplateProcessor</implementation>
-      <requirements>
-        <requirement>
-          <role>org.codehaus.plexus.redback.rbac.RBACManager</role>
-          <role-hint>memory</role-hint>
-          <field-name>rbacManager</field-name>
-        </requirement>
-      </requirements>
-    </component>
   </components>
 </plexus>