From 7edc5c26dc86412261ddc26a3f74b6cb2b92678e Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Thu, 25 Oct 2007 23:39:05 +0000 Subject: [PATCH] [MRM-567] Unable to download plugin SNAPSHOT's from proxy. 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 --- archiva-web/archiva-webapp/pom.xml | 25 ++ .../web/repository/ArchivaMimeTypeLoader.java | 72 ++++ .../web/repository/RepositoryServlet.java | 53 ++- .../resources/META-INF/plexus/application.xml | 9 + .../mime-types.txt => archiva-mime-types.txt} | 2 - ...tractRepositoryServletProxiedTestCase.java | 301 +++++++++++++ .../AbstractRepositoryServletTestCase.java | 226 ++++++++++ .../repository/ArchivaMimeTypeLoaderTest.java | 47 ++ .../web/repository/BypassSecuritySystem.java | 134 ++++++ .../RepositoryServletBrowseTest.java | 62 +++ .../RepositoryServletDeployTest.java | 62 +++ .../RepositoryServletNoProxyTest.java | 220 ++++++++++ ...sitoryServletProxiedReleasePolicyTest.java | 193 +++++++++ ...itoryServletProxiedSnapshotPolicyTest.java | 195 +++++++++ .../RepositoryServletSecurityTest.java | 21 + .../web/repository/RepositoryServletTest.java | 401 +----------------- .../UnauthenticatedRepositoryServlet.java | 25 +- .../resources/META-INF/plexus/components.xml | 33 ++ .../RepositoryServletSecurityTest.xml | 265 ++++++++++++ .../web/repository/RepositoryServletTest.xml | 165 +------ 20 files changed, 1946 insertions(+), 565 deletions(-) create mode 100644 archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/repository/ArchivaMimeTypeLoader.java rename archiva-web/archiva-webapp/src/main/resources/{org/codehaus/plexus/webdav/util/mime-types.txt => archiva-mime-types.txt} (99%) create mode 100644 archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/AbstractRepositoryServletProxiedTestCase.java create mode 100644 archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/AbstractRepositoryServletTestCase.java create mode 100644 archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/ArchivaMimeTypeLoaderTest.java create mode 100644 archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/BypassSecuritySystem.java create mode 100644 archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletBrowseTest.java create mode 100644 archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletDeployTest.java create mode 100644 archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletNoProxyTest.java create mode 100644 archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletProxiedReleasePolicyTest.java create mode 100644 archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletProxiedSnapshotPolicyTest.java create mode 100644 archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletSecurityTest.java create mode 100644 archiva-web/archiva-webapp/src/test/resources/META-INF/plexus/components.xml create mode 100644 archiva-web/archiva-webapp/src/test/resources/org/apache/maven/archiva/web/repository/RepositoryServletSecurityTest.xml diff --git a/archiva-web/archiva-webapp/pom.xml b/archiva-web/archiva-webapp/pom.xml index 5456b47bb..159a41294 100644 --- a/archiva-web/archiva-webapp/pom.xml +++ b/archiva-web/archiva-webapp/pom.xml @@ -192,10 +192,12 @@ org.codehaus.plexus plexus-xwork-integration + org.apache.derby derby @@ -211,6 +213,13 @@ activation provided + + + org.mortbay.jetty + jetty + 6.1.5 + test + httpunit httpunit @@ -238,6 +247,22 @@ + org.apache.maven.plugins maven-clean-plugin 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 index 000000000..2a821848b --- /dev/null +++ b/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/repository/ArchivaMimeTypeLoader.java @@ -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 Joakim Erdfelt + * @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 ); + } + } + } + } +} diff --git a/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/repository/RepositoryServlet.java b/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/repository/RepositoryServlet.java index 9bd9596e6..61919910d 100644 --- a/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/repository/RepositoryServlet.java +++ b/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/repository/RepositoryServlet.java @@ -68,12 +68,16 @@ public class RepositoryServlet private ArchivaConfiguration configuration; private Map 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 diff --git a/archiva-web/archiva-webapp/src/main/resources/META-INF/plexus/application.xml b/archiva-web/archiva-webapp/src/main/resources/META-INF/plexus/application.xml index c1fe07d13..aed45580b 100644 --- a/archiva-web/archiva-webapp/src/main/resources/META-INF/plexus/application.xml +++ b/archiva-web/archiva-webapp/src/main/resources/META-INF/plexus/application.xml @@ -198,6 +198,15 @@ + + + org.codehaus.plexus.webdav.util.MimeTypes + org.codehaus.plexus.webdav.util.MimeTypes + MimeTypes + + archiva-mime-types.txt + + + + + + + + org.codehaus.plexus.webdav.util.MimeTypes + org.codehaus.plexus.webdav.util.MimeTypes + MimeTypes + + archiva-mime-types.txt + + + + \ 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 index 000000000..beccf43c9 --- /dev/null +++ b/archiva-web/archiva-webapp/src/test/resources/org/apache/maven/archiva/web/repository/RepositoryServletSecurityTest.xml @@ -0,0 +1,265 @@ + + + + + + + + org.codehaus.plexus.logging.LoggerManager + org.codehaus.plexus.logging.slf4j.Slf4jLoggerManager + basic + + + + + org.apache.maven.archiva.configuration.ArchivaConfiguration + org.apache.maven.archiva.configuration.DefaultArchivaConfiguration + + + org.codehaus.plexus.registry.Registry + configured + + + + + org.codehaus.plexus.registry.Registry + configured + org.codehaus.plexus.registry.commons.CommonsConfigurationRegistry + + + + + + + + + + org.codehaus.plexus.webdav.DavServerManager + default + org.codehaus.plexus.webdav.DefaultDavServerManager + DefaultDavServerManager + + proxied + + + + + org.codehaus.plexus.cache.Cache + url-failures-cache + org.codehaus.plexus.cache.ehcache.EhcacheCache + URL Failure Cache + + 600 + false + ${java.io.tmpdir}/archiva/urlcache + false + 1000 + LRU + url-failures-cache + false + + 2700 + + 1800 + + + + + + + org.apache.maven.archiva.repository.scanner.RepositoryContentConsumers + default + org.apache.maven.archiva.web.repository.StubRepositoryContentConsumers + + + + + org.codehaus.plexus.redback.system.SecuritySystem + default + org.codehaus.plexus.redback.system.DefaultSecuritySystem + + + org.codehaus.plexus.redback.authentication.AuthenticationManager + authnManager + + + org.codehaus.plexus.redback.authorization.Authorizer + rbac + authorizer + + + org.codehaus.plexus.redback.users.UserManager + memory + userManager + + + org.codehaus.plexus.redback.keys.KeyManager + memory + keyManager + + + org.codehaus.plexus.redback.policy.UserSecurityPolicy + policy + + + + + + org.codehaus.plexus.redback.authentication.Authenticator + user-manager + org.codehaus.plexus.redback.authentication.users.UserManagerAuthenticator + + + org.codehaus.plexus.redback.users.UserManager + memory + userManager + + + org.codehaus.plexus.redback.policy.UserSecurityPolicy + securityPolicy + + + + + + org.codehaus.plexus.redback.authentication.Authenticator + keystore + org.codehaus.plexus.redback.authentication.keystore.KeyStoreAuthenticator + + + org.codehaus.plexus.redback.keys.KeyManager + memory + keystore + + + org.codehaus.plexus.redback.users.UserManager + memory + userManager + + + + + + org.codehaus.plexus.redback.authorization.rbac.evaluator.PermissionEvaluator + default + org.codehaus.plexus.redback.authorization.rbac.evaluator.DefaultPermissionEvaluator + + + + org.codehaus.plexus.redback.users.UserManager + memory + userManager + + + + + + org.codehaus.plexus.redback.authorization.Authorizer + rbac + org.codehaus.plexus.redback.authorization.rbac.RbacAuthorizer + + + org.codehaus.plexus.redback.rbac.RBACManager + memory + manager + + + org.codehaus.plexus.redback.users.UserManager + memory + userManager + + + org.codehaus.plexus.redback.authorization.rbac.evaluator.PermissionEvaluator + default + evaluator + + + + + + org.codehaus.plexus.redback.role.RoleManager + default + org.codehaus.plexus.redback.role.DefaultRoleManager + singleton + + + org.codehaus.plexus.redback.role.merger.RoleModelMerger + default + modelMerger + + + org.codehaus.plexus.redback.role.validator.RoleModelValidator + default + modelValidator + + + org.codehaus.plexus.redback.role.processor.RoleModelProcessor + default + modelProcessor + + + org.codehaus.plexus.redback.role.template.RoleTemplateProcessor + default + templateProcessor + + + org.codehaus.plexus.redback.rbac.RBACManager + memory + rbacManager + + + org.codehaus.plexus.PlexusContainer + container + + + + + + org.codehaus.plexus.redback.role.processor.RoleModelProcessor + default + org.codehaus.plexus.redback.role.processor.DefaultRoleModelProcessor + + + org.codehaus.plexus.redback.rbac.RBACManager + memory + rbacManager + + + + + + org.codehaus.plexus.redback.role.template.RoleTemplateProcessor + default + org.codehaus.plexus.redback.role.template.DefaultRoleTemplateProcessor + + + org.codehaus.plexus.redback.rbac.RBACManager + memory + rbacManager + + + + + diff --git a/archiva-web/archiva-webapp/src/test/resources/org/apache/maven/archiva/web/repository/RepositoryServletTest.xml b/archiva-web/archiva-webapp/src/test/resources/org/apache/maven/archiva/web/repository/RepositoryServletTest.xml index beccf43c9..974e148d2 100644 --- a/archiva-web/archiva-webapp/src/test/resources/org/apache/maven/archiva/web/repository/RepositoryServletTest.xml +++ b/archiva-web/archiva-webapp/src/test/resources/org/apache/maven/archiva/web/repository/RepositoryServletTest.xml @@ -93,173 +93,12 @@ default org.apache.maven.archiva.web.repository.StubRepositoryContentConsumers - - + org.codehaus.plexus.redback.system.SecuritySystem default - org.codehaus.plexus.redback.system.DefaultSecuritySystem - - - org.codehaus.plexus.redback.authentication.AuthenticationManager - authnManager - - - org.codehaus.plexus.redback.authorization.Authorizer - rbac - authorizer - - - org.codehaus.plexus.redback.users.UserManager - memory - userManager - - - org.codehaus.plexus.redback.keys.KeyManager - memory - keyManager - - - org.codehaus.plexus.redback.policy.UserSecurityPolicy - policy - - - - - - org.codehaus.plexus.redback.authentication.Authenticator - user-manager - org.codehaus.plexus.redback.authentication.users.UserManagerAuthenticator - - - org.codehaus.plexus.redback.users.UserManager - memory - userManager - - - org.codehaus.plexus.redback.policy.UserSecurityPolicy - securityPolicy - - - - - - org.codehaus.plexus.redback.authentication.Authenticator - keystore - org.codehaus.plexus.redback.authentication.keystore.KeyStoreAuthenticator - - - org.codehaus.plexus.redback.keys.KeyManager - memory - keystore - - - org.codehaus.plexus.redback.users.UserManager - memory - userManager - - - - - - org.codehaus.plexus.redback.authorization.rbac.evaluator.PermissionEvaluator - default - org.codehaus.plexus.redback.authorization.rbac.evaluator.DefaultPermissionEvaluator - - - - org.codehaus.plexus.redback.users.UserManager - memory - userManager - - - - - - org.codehaus.plexus.redback.authorization.Authorizer - rbac - org.codehaus.plexus.redback.authorization.rbac.RbacAuthorizer - - - org.codehaus.plexus.redback.rbac.RBACManager - memory - manager - - - org.codehaus.plexus.redback.users.UserManager - memory - userManager - - - org.codehaus.plexus.redback.authorization.rbac.evaluator.PermissionEvaluator - default - evaluator - - - - - - org.codehaus.plexus.redback.role.RoleManager - default - org.codehaus.plexus.redback.role.DefaultRoleManager - singleton - - - org.codehaus.plexus.redback.role.merger.RoleModelMerger - default - modelMerger - - - org.codehaus.plexus.redback.role.validator.RoleModelValidator - default - modelValidator - - - org.codehaus.plexus.redback.role.processor.RoleModelProcessor - default - modelProcessor - - - org.codehaus.plexus.redback.role.template.RoleTemplateProcessor - default - templateProcessor - - - org.codehaus.plexus.redback.rbac.RBACManager - memory - rbacManager - - - org.codehaus.plexus.PlexusContainer - container - - - - - - org.codehaus.plexus.redback.role.processor.RoleModelProcessor - default - org.codehaus.plexus.redback.role.processor.DefaultRoleModelProcessor - - - org.codehaus.plexus.redback.rbac.RBACManager - memory - rbacManager - - + org.apache.maven.archiva.web.repository.BypassSecuritySystem - - org.codehaus.plexus.redback.role.template.RoleTemplateProcessor - default - org.codehaus.plexus.redback.role.template.DefaultRoleTemplateProcessor - - - org.codehaus.plexus.redback.rbac.RBACManager - memory - rbacManager - - - -- 2.39.5