[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
This commit is contained in:
Joakim Erdfelt 2007-10-25 23:39:05 +00:00
parent 7c1ce938fc
commit 7edc5c26dc
20 changed files with 1946 additions and 565 deletions

View File

@ -192,10 +192,12 @@
<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>
@ -211,6 +213,13 @@
<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>
@ -238,6 +247,22 @@
</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>

View File

@ -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 );
}
}
}
}
}

View 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

View File

@ -198,6 +198,15 @@
</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

View File

@ -1,5 +1,3 @@
# 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.

View File

@ -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();
}
}

View File

@ -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;
}
}

View File

@ -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" ) );
}
}

View File

@ -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;
}
}

View File

@ -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() );
}
}
}

View File

@ -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() );
}
}

View File

@ -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() );
}
}

View File

@ -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;
}
}
}

View File

@ -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;
}
}
}

View File

@ -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()
{
}
}

View 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 );
}
}

View 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;
}
}

View File

@ -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>

View File

@ -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>

View File

@ -93,173 +93,12 @@
<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>
<implementation>org.apache.maven.archiva.web.repository.BypassSecuritySystem</implementation>
</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>