1 package org.apache.maven.archiva.web.servlet.repository;
4 * Copyright 2001-2006 The Apache Software Foundation.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 import org.apache.maven.archiva.web.servlet.PlexusServlet;
20 import org.codehaus.plexus.PlexusTestCase;
23 * RepositoryAccessTest
25 * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
28 public class RepositoryAccessTest
29 extends PlexusTestCase
31 private void assertRequestPath( String expectedId, String expectedPath, String rawpath )
34 RepositoryAccess repoaccess = (RepositoryAccess) lookup( PlexusServlet.ROLE, "repositoryAccess" );
36 RepositoryAccess.RequestPath requestPath = repoaccess.getRepositoryPath( rawpath );
38 if ( expectedId == null )
40 // special case, should be null.
41 assertNull( requestPath );
45 assertNotNull( requestPath );
47 assertEquals( expectedId, requestPath.repoName );
48 assertEquals( expectedPath, requestPath.path );
51 public void testGetRepoPath() throws Exception
53 // Test for paths with no id.
54 assertRequestPath( null, null, null );
55 assertRequestPath( null, null, "" );
56 assertRequestPath( null, null, "/" );
58 // Test for paths with root browse
59 assertRequestPath( "central", "/", "/central" );
60 assertRequestPath( "central", "/", "/central/" );
61 assertRequestPath( "snapshots", "/", "/snapshots/" );
63 // Test for paths deep within repository.
64 assertRequestPath( "central", "/org/apache/maven/", "/central/org/apache/maven/" );
65 assertRequestPath( "snapshots", "/org/codehaus/mojo", "/snapshots/org/codehaus/mojo" );
67 assertRequestPath( "central", "/org/apache/maven/archiva/metadata.xml",
68 "/central/org/apache/maven/archiva/metadata.xml" );
69 assertRequestPath( "sandbox", "/org/company/experiment/1.0/experiment-1.0.jar.pom",
70 "/sandbox/org/company/experiment/1.0/experiment-1.0.jar.pom" );
72 // Test for paths with "/../" nastyness
73 assertRequestPath( "central", "/", "/central/.." );
74 assertRequestPath( "central", "/", "/central/../../../" );
75 assertRequestPath( "central", "/", "/central/org/../../etc/passwd" );
76 assertRequestPath( "central", "/etc/passwd", "/central//etc/passwd" );
77 assertRequestPath( "central", "/org/codehaus/mojo", "/central/org/apache/../codehaus/mojo" );