1 package org.apache.archiva.webdav;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import junit.framework.TestCase;
23 import org.apache.archiva.admin.model.RepositoryAdminException;
24 import org.apache.archiva.admin.model.beans.ManagedRepository;
25 import org.apache.archiva.admin.model.beans.RepositoryGroup;
26 import org.apache.archiva.admin.model.remote.RemoteRepositoryAdmin;
27 import org.apache.archiva.admin.repository.DefaultRepositoryCommonValidator;
28 import org.apache.archiva.admin.repository.group.DefaultRepositoryGroupAdmin;
29 import org.apache.archiva.admin.repository.managed.DefaultManagedRepositoryAdmin;
30 import org.apache.archiva.common.plexusbridge.PlexusSisuBridge;
31 import org.apache.archiva.common.plexusbridge.PlexusSisuBridgeException;
32 import org.apache.archiva.configuration.ArchivaConfiguration;
33 import org.apache.archiva.configuration.Configuration;
34 import org.apache.archiva.configuration.RepositoryGroupConfiguration;
35 import org.apache.archiva.proxy.DefaultRepositoryProxyConnectors;
36 import org.apache.archiva.repository.ManagedRepositoryContent;
37 import org.apache.archiva.repository.RepositoryContentFactory;
38 import org.apache.archiva.repository.content.legacy.LegacyPathParser;
39 import org.apache.archiva.repository.content.maven2.ManagedDefaultRepositoryContent;
40 import org.apache.archiva.repository.content.maven2.RepositoryRequest;
41 import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
42 import org.apache.commons.io.FileUtils;
43 import org.apache.jackrabbit.webdav.DavException;
44 import org.apache.jackrabbit.webdav.DavResourceLocator;
45 import org.apache.jackrabbit.webdav.DavServletRequest;
46 import org.apache.jackrabbit.webdav.DavServletResponse;
48 import org.easymock.IMocksControl;
49 import org.junit.After;
50 import org.junit.Before;
51 import org.junit.Test;
52 import org.junit.runner.RunWith;
53 import org.springframework.context.ApplicationContext;
54 import org.springframework.test.context.ContextConfiguration;
56 import javax.inject.Inject;
58 import java.io.IOException;
59 import java.util.ArrayList;
60 import java.util.List;
62 import static org.easymock.EasyMock.*;
65 * ArchivaDavResourceFactoryTest
67 @RunWith( ArchivaSpringJUnit4ClassRunner.class )
68 @ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" } )
69 public class ArchivaDavResourceFactoryTest
72 private static final String RELEASES_REPO = "releases";
74 private static final String INTERNAL_REPO = "internal";
76 private static final String LOCAL_MIRROR_REPO = "local-mirror";
78 private static final String LEGACY_REPO = "legacy-repo";
80 private static final String LOCAL_REPO_GROUP = "local";
82 private OverridingArchivaDavResourceFactory resourceFactory;
84 private IMocksControl requestControl;
86 private DavServletRequest request;
88 private IMocksControl repoRequestControl;
90 private RepositoryRequest repoRequest;
92 private IMocksControl responseControl;
94 private DavServletResponse response;
96 private IMocksControl archivaConfigurationControl;
98 private ArchivaConfiguration archivaConfiguration;
100 private Configuration config;
102 private IMocksControl repoContentFactoryControl;
104 private RepositoryContentFactory repoFactory;
107 ApplicationContext applicationContext;
110 PlexusSisuBridge plexusSisuBridge;
113 DefaultManagedRepositoryAdmin defaultManagedRepositoryAdmin;
116 RemoteRepositoryAdmin remoteRepositoryAdmin;
120 DefaultRepositoryGroupAdmin defaultRepositoryGroupAdmin;
129 requestControl = createControl();
130 request = requestControl.createMock( DavServletRequest.class );
132 responseControl = createControl();
133 response = responseControl.createMock( DavServletResponse.class );
134 //responseControl.setDefaultMatcher( MockControl.ALWAYS_MATCHER );
136 archivaConfigurationControl = createControl();
137 archivaConfiguration = archivaConfigurationControl.createMock( ArchivaConfiguration.class );
139 config = new Configuration();
140 //archivaConfiguration.getConfiguration();
141 //archivaConfigurationControl.setReturnValue( config, 5, 20 );
142 expect( archivaConfiguration.getConfiguration() ).andReturn( config ).times( 5, 20 );
143 archivaConfiguration.save( config );
144 //archivaConfigurationControl.setVoidCallable( 1, 4 );
145 expectLastCall().times( 1, 4 );
146 archivaConfigurationControl.replay();
148 defaultManagedRepositoryAdmin.setArchivaConfiguration( archivaConfiguration );
149 ( (DefaultRepositoryCommonValidator) defaultManagedRepositoryAdmin.getRepositoryCommonValidator() ).setArchivaConfiguration(
150 archivaConfiguration );
151 if ( defaultManagedRepositoryAdmin.getManagedRepository( RELEASES_REPO ) == null )
153 defaultManagedRepositoryAdmin.addManagedRepository(
154 createManagedRepository( RELEASES_REPO, new File( "target/test-classes/" + RELEASES_REPO ).getPath(),
155 "default" ), false, null );
157 if ( defaultManagedRepositoryAdmin.getManagedRepository( INTERNAL_REPO ) == null )
159 defaultManagedRepositoryAdmin.addManagedRepository(
160 createManagedRepository( INTERNAL_REPO, new File( "target/test-classes/" + INTERNAL_REPO ).getPath(),
161 "default" ), false, null );
163 RepositoryGroup repoGroupConfig = new RepositoryGroup();
164 repoGroupConfig.setId( LOCAL_REPO_GROUP );
165 repoGroupConfig.addRepository( RELEASES_REPO );
166 repoGroupConfig.addRepository( INTERNAL_REPO );
168 defaultRepositoryGroupAdmin.setArchivaConfiguration( archivaConfiguration );
169 if ( defaultManagedRepositoryAdmin.getManagedRepository( LOCAL_REPO_GROUP ) == null )
171 defaultRepositoryGroupAdmin.addRepositoryGroup( repoGroupConfig, null );
174 repoContentFactoryControl = createControl();
175 repoFactory = repoContentFactoryControl.createMock( RepositoryContentFactory.class );
177 repoRequestControl = createControl();
178 repoRequest = repoRequestControl.createMock( RepositoryRequest.class );
181 new OverridingArchivaDavResourceFactory( applicationContext, plexusSisuBridge, archivaConfiguration );
182 resourceFactory.setArchivaConfiguration( archivaConfiguration );
183 resourceFactory.setRepositoryFactory( repoFactory );
184 resourceFactory.setRepositoryRequest( repoRequest );
185 resourceFactory.setConnectors( new OverridingRepositoryProxyConnectors() );
186 resourceFactory.setRemoteRepositoryAdmin( remoteRepositoryAdmin );
189 private ManagedRepository createManagedRepository( String id, String location, String layout )
191 ManagedRepository repoConfig = new ManagedRepository();
192 repoConfig.setId( id );
193 repoConfig.setName( id );
194 repoConfig.setLocation( location );
195 repoConfig.setLayout( layout );
200 private ManagedRepositoryContent createManagedRepositoryContent( String repoId )
201 throws RepositoryAdminException
203 ManagedRepositoryContent repoContent = new ManagedDefaultRepositoryContent();
204 repoContent.setRepository( defaultManagedRepositoryAdmin.getManagedRepository( repoId ) );
210 public void tearDown()
216 // MRM-1232 - Unable to get artifacts from repositories which requires Repository Manager role using repository group
218 public void testRepositoryGroupFirstRepositoryRequiresAuthentication()
221 DavResourceLocator locator = new ArchivaDavResourceLocator( "", "/repository/" + LOCAL_REPO_GROUP
222 + "/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar", LOCAL_REPO_GROUP,
223 new ArchivaDavLocatorFactory() );
225 ManagedRepositoryContent internalRepo = createManagedRepositoryContent( INTERNAL_REPO );
226 ManagedRepositoryContent releasesRepo = createManagedRepositoryContent( RELEASES_REPO );
230 archivaConfigurationControl.reset();
231 //archivaConfigurationControl.expectAndReturn( archivaConfiguration.getConfiguration(), config );
232 expect( archivaConfiguration.getConfiguration() ).andReturn( config );
233 //requestControl.expectAndReturn( request.getMethod(), "GET", 2 );
234 expect( request.getMethod() ).andReturn( "GET" ).times( 2 );
235 //requestControl.expectAndReturn( request.getPathInfo(), "org/apache/archiva", 0, 2 );
236 expect( request.getPathInfo() ).andReturn( "org/apache/archiva" ).times( 0, 2 );
237 //repoContentFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( RELEASES_REPO ),
239 expect( repoFactory.getManagedRepositoryContent( RELEASES_REPO ) ).andReturn( releasesRepo );
240 //requestControl.expectAndReturn( request.getRemoteAddr(), "http://localhost:8080", 2 );
241 expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 2 );
242 //requestControl.expectAndReturn( request.getDavSession(), new ArchivaDavSession(), 2 );
243 expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 2 );
245 //repoRequestControl.expectAndReturn(
246 // repoRequest.isSupportFile( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ),
248 expect( repoRequest.isSupportFile(
249 "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( true );
250 //repoRequestControl.expectAndReturn(
251 // repoRequest.isDefault( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ), false );
253 repoRequest.isDefault( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn(
255 //repoRequestControl.expectAndReturn(
256 // repoRequest.toArtifactReference( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ),
258 expect( repoRequest.toArtifactReference(
259 "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( null );
260 //repoRequestControl.expectAndReturn(
261 // repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar", internalRepo ),
262 // new File( config.findManagedRepositoryById( INTERNAL_REPO ).getLocation(),
263 // "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).getPath() );
264 expect( repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar",
265 internalRepo ) ).andReturn(
266 new File( config.findManagedRepositoryById( INTERNAL_REPO ).getLocation(),
267 "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).getPath() );
268 //repoContentFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ),
270 expect( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ) ).andReturn( internalRepo );
271 //repoRequestControl.expectAndReturn(
272 // repoRequest.isArchetypeCatalog( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ),
274 expect( repoRequest.isArchetypeCatalog(
275 "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( false );
276 archivaConfigurationControl.replay();
277 requestControl.replay();
278 repoContentFactoryControl.replay();
279 repoRequestControl.replay();
281 resourceFactory.createResource( locator, request, response );
283 archivaConfigurationControl.verify();
284 requestControl.verify();
285 repoContentFactoryControl.verify();
286 repoRequestControl.verify();
288 fail( "A DavException with 401 error code should have been thrown." );
290 catch ( DavException e )
292 assertEquals( 401, e.getErrorCode() );
297 public void testRepositoryGroupLastRepositoryRequiresAuthentication()
300 DavResourceLocator locator = new ArchivaDavResourceLocator( "", "/repository/" + LOCAL_REPO_GROUP
301 + "/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar", LOCAL_REPO_GROUP,
302 new ArchivaDavLocatorFactory() );
304 List<RepositoryGroupConfiguration> repoGroups = new ArrayList<RepositoryGroupConfiguration>();
305 RepositoryGroupConfiguration repoGroup = new RepositoryGroupConfiguration();
306 repoGroup.setId( LOCAL_REPO_GROUP );
307 repoGroup.addRepository( INTERNAL_REPO );
308 repoGroup.addRepository( RELEASES_REPO );
310 repoGroups.add( repoGroup );
312 config.setRepositoryGroups( repoGroups );
314 ManagedRepositoryContent internalRepo = createManagedRepositoryContent( INTERNAL_REPO );
316 ManagedRepositoryContent releasesRepo = createManagedRepositoryContent( RELEASES_REPO );
320 archivaConfigurationControl.reset();
321 //archivaConfigurationControl.expectAndReturn( archivaConfiguration.getConfiguration(), config );
322 expect( archivaConfiguration.getConfiguration() ).andReturn( config );
323 //requestControl.expectAndReturn( request.getMethod(), "GET", 2 );
324 expect( request.getMethod() ).andReturn( "GET" ).times( 2 );
325 //requestControl.expectAndReturn( request.getPathInfo(), "org/apache/archiva", 0, 2 );
326 expect( request.getPathInfo() ).andReturn( "org/apache/archiva" ).times( 0, 2 );
327 //repoContentFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ),
329 expect( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ) ).andReturn( internalRepo );
330 //repoContentFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( RELEASES_REPO ),
332 expect( repoFactory.getManagedRepositoryContent( RELEASES_REPO ) ).andReturn( releasesRepo );
333 //requestControl.expectAndReturn( request.getRemoteAddr(), "http://localhost:8080", 2 );
334 expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 2 );
335 //requestControl.expectAndReturn( request.getDavSession(), new ArchivaDavSession(), 2 );
336 expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 2 );
337 //repoRequestControl.expectAndReturn(
338 // repoRequest.isSupportFile( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ),
340 expect( repoRequest.isSupportFile(
341 "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( false );
342 //repoRequestControl.expectAndReturn(
343 // repoRequest.isDefault( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ), false );
345 repoRequest.isDefault( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn(
347 //repoRequestControl.expectAndReturn(
348 // repoRequest.toArtifactReference( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ),
350 expect( repoRequest.toArtifactReference(
351 "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( null );
352 //repoRequestControl.expectAndReturn(
353 // repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar", internalRepo ),
354 // new File( config.findManagedRepositoryById( INTERNAL_REPO ).getLocation(),
355 // "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).getPath() );
356 expect( repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar",
357 internalRepo ) ).andReturn(
358 new File( config.findManagedRepositoryById( INTERNAL_REPO ).getLocation(),
359 "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).getPath() );
361 //repoRequestControl.expectAndReturn(
362 // repoRequest.isArchetypeCatalog( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ),
364 expect( repoRequest.isArchetypeCatalog(
365 "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( false );
366 archivaConfigurationControl.replay();
367 requestControl.replay();
368 repoContentFactoryControl.replay();
369 repoRequestControl.replay();
371 resourceFactory.createResource( locator, request, response );
373 archivaConfigurationControl.verify();
374 requestControl.verify();
375 repoContentFactoryControl.verify();
376 repoRequestControl.verify();
378 fail( "A DavException with 401 error code should have been thrown." );
380 catch ( DavException e )
382 assertEquals( 401, e.getErrorCode() );
387 public void testRepositoryGroupArtifactDoesNotExistInAnyOfTheReposAuthenticationDisabled()
390 DavResourceLocator locator = new ArchivaDavResourceLocator( "", "/repository/" + LOCAL_REPO_GROUP
391 + "/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar", LOCAL_REPO_GROUP,
392 new ArchivaDavLocatorFactory() );
394 defaultManagedRepositoryAdmin.addManagedRepository(
395 createManagedRepository( LOCAL_MIRROR_REPO, new File( "target/test-classes/local-mirror" ).getPath(),
396 "default" ), false, null );
398 List<RepositoryGroupConfiguration> repoGroups = new ArrayList<RepositoryGroupConfiguration>();
399 RepositoryGroupConfiguration repoGroup = new RepositoryGroupConfiguration();
400 repoGroup.setId( LOCAL_REPO_GROUP );
401 repoGroup.addRepository( INTERNAL_REPO );
402 repoGroup.addRepository( LOCAL_MIRROR_REPO );
404 repoGroups.add( repoGroup );
406 config.setRepositoryGroups( repoGroups );
408 ManagedRepositoryContent internalRepo = createManagedRepositoryContent( INTERNAL_REPO );
409 ManagedRepositoryContent localMirrorRepo = createManagedRepositoryContent( LOCAL_MIRROR_REPO );
413 archivaConfigurationControl.reset();
414 //archivaConfigurationControl.expectAndReturn( archivaConfiguration.getConfiguration(), config );
415 expect( archivaConfiguration.getConfiguration() ).andReturn( config );
416 //requestControl.expectAndReturn( request.getMethod(), "GET", 4 );
417 expect( request.getMethod() ).andReturn( "GET" ).times( 4 );
418 //requestControl.expectAndReturn( request.getPathInfo(), "org/apache/archiva", 0, 2 );
419 expect( request.getPathInfo() ).andReturn( "org/apache/archiva" ).times( 0, 2 );
420 //repoContentFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ),
422 expect( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ) ).andReturn( internalRepo );
423 //repoContentFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( LOCAL_MIRROR_REPO ),
424 // localMirrorRepo );
425 expect( repoFactory.getManagedRepositoryContent( LOCAL_MIRROR_REPO ) ).andReturn( localMirrorRepo );
426 //requestControl.expectAndReturn( request.getRemoteAddr(), "http://localhost:8080", 4 );
427 expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 4 );
428 //requestControl.expectAndReturn( request.getDavSession(), new ArchivaDavSession(), 4 );
429 expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 4 );
430 //repoRequestControl.expectAndReturn(
431 // repoRequest.isSupportFile( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ), false,
433 expect( repoRequest.isSupportFile(
434 "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( false ).times( 2 );
435 //repoRequestControl.expectAndReturn(
436 // repoRequest.isDefault( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ), false, 2 );
438 repoRequest.isDefault( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn(
440 //repoRequestControl.expectAndReturn(
441 // repoRequest.toArtifactReference( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ),
443 expect( repoRequest.toArtifactReference(
444 "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( null ).times( 2 );
445 //repoRequestControl.expectAndReturn(
446 //repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar",
448 //new File( config.findManagedRepositoryById( INTERNAL_REPO ).getLocation(),
449 // "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).getPath() );
450 expect( repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar",
451 internalRepo ) ).andReturn(
452 new File( config.findManagedRepositoryById( INTERNAL_REPO ).getLocation(),
453 "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).getPath() );
454 //repoRequestControl.expectAndReturn(
455 // repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar", localMirrorRepo ),
456 // new File( config.findManagedRepositoryById( LOCAL_MIRROR_REPO ).getLocation(),
457 // "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).getPath() );
458 expect( repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar",
460 .andReturn( new File( config.findManagedRepositoryById( LOCAL_MIRROR_REPO ).getLocation(),
461 "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).getPath() );
462 //repoRequestControl.expectAndReturn(
463 // repoRequest.isArchetypeCatalog( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ),
465 expect( repoRequest.isArchetypeCatalog( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( false ).times( 2 );
466 archivaConfigurationControl.replay();
467 requestControl.replay();
468 repoContentFactoryControl.replay();
469 repoRequestControl.replay();
471 resourceFactory.createResource( locator, request, response );
473 archivaConfigurationControl.verify();
474 requestControl.verify();
475 repoContentFactoryControl.verify();
476 repoRequestControl.verify();
478 fail( "A DavException with 404 error code should have been thrown." );
480 catch ( DavException e )
482 assertEquals( 404, e.getErrorCode() );
488 public void testRequestArtifactMetadataThreePartsRepoHasDefaultLayout()
491 // should fetch metadata
492 DavResourceLocator locator =
493 new ArchivaDavResourceLocator( "", "/repository/" + INTERNAL_REPO + "/eclipse/jdtcore/maven-metadata.xml",
494 INTERNAL_REPO, new ArchivaDavLocatorFactory() );
496 ManagedRepositoryContent internalRepo = createManagedRepositoryContent( INTERNAL_REPO );
498 // use actual object (this performs the isMetadata, isDefault and isSupportFile check!)
499 RepositoryRequest repoRequest = new RepositoryRequest( new LegacyPathParser( this.archivaConfiguration ) );
500 resourceFactory.setRepositoryRequest( repoRequest );
504 archivaConfigurationControl.reset();
505 //archivaConfigurationControl.expectAndReturn( archivaConfiguration.getConfiguration(), config );
506 expect( archivaConfiguration.getConfiguration() ).andReturn( config );
507 //repoContentFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ),
509 expect( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ) ).andReturn( internalRepo );
510 //requestControl.expectAndReturn( request.getMethod(), "GET", 3 );
511 expect( request.getMethod() ).andReturn( "GET" ).times( 3 );
512 //requestControl.expectAndReturn( request.getRemoteAddr(), "http://localhost:8080", 3 );
513 expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 3 );
514 //requestControl.expectAndReturn( request.getDavSession(), new ArchivaDavSession(), 2 );
515 expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 2 );
516 //requestControl.expectAndReturn( request.getRequestURI(),
517 // "http://localhost:8080/archiva/repository/" + INTERNAL_REPO + "/eclipse/jdtcore/maven-metadata.xml" );
518 expect( request.getRequestURI() ).andReturn( "http://localhost:8080/archiva/repository/" + INTERNAL_REPO + "/eclipse/jdtcore/maven-metadata.xml" );
519 response.setHeader( "Pragma", "no-cache" );
520 //responseControl.setVoidCallable();
523 response.setHeader( "Cache-Control", "no-cache" );
524 //responseControl.setVoidCallable();
527 //long date = 2039842134;
528 response.setDateHeader( eq("Last-Modified"), anyLong() );
529 //responseControl.setVoidCallable();
532 archivaConfigurationControl.replay();
533 repoContentFactoryControl.replay();
534 requestControl.replay();
535 responseControl.replay();
537 resourceFactory.createResource( locator, request, response );
539 archivaConfigurationControl.verify();
540 repoContentFactoryControl.verify();
541 requestControl.verify();
542 responseControl.verify();
544 catch ( DavException e )
546 fail( "A DavException should not have been thrown!" );
551 public void testRequestArtifactMetadataTwoPartsRepoHasDefaultLayout()
554 // should not fetch metadata
555 DavResourceLocator locator =
556 new ArchivaDavResourceLocator( "", "/repository/" + INTERNAL_REPO + "/eclipse/maven-metadata.xml",
557 INTERNAL_REPO, new ArchivaDavLocatorFactory() );
559 ManagedRepositoryContent internalRepo = createManagedRepositoryContent( INTERNAL_REPO );
561 // use actual object (this performs the isMetadata, isDefault and isSupportFile check!)
562 RepositoryRequest repoRequest = new RepositoryRequest( new LegacyPathParser( this.archivaConfiguration ) );
563 resourceFactory.setRepositoryRequest( repoRequest );
567 archivaConfigurationControl.reset();
568 //archivaConfigurationControl.expectAndReturn( archivaConfiguration.getConfiguration(), config );
569 expect( archivaConfiguration.getConfiguration() ).andReturn( config );
570 //repoContentFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ),
572 expect( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ) ).andReturn( internalRepo );
573 //requestControl.expectAndReturn( request.getMethod(), "GET", 2 );
574 expect( request.getMethod() ).andReturn( "GET" ).times( 2 );
575 //requestControl.expectAndReturn( request.getRemoteAddr(), "http://localhost:8080", 2 );
576 expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 2 );
577 //requestControl.expectAndReturn( request.getDavSession(), new ArchivaDavSession(), 2 );
578 expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 2 );
580 archivaConfigurationControl.replay();
581 repoContentFactoryControl.replay();
582 requestControl.replay();
584 resourceFactory.createResource( locator, request, response );
586 archivaConfigurationControl.verify();
587 repoContentFactoryControl.verify();
588 requestControl.verify();
590 fail( "A 404 error should have been thrown!" );
592 catch ( DavException e )
594 assertEquals( 404, e.getErrorCode() );
599 public void testRequestMetadataRepoIsLegacy()
602 defaultManagedRepositoryAdmin.addManagedRepository(
603 createManagedRepository( LEGACY_REPO, new File( "target/test-classes/" + LEGACY_REPO ).getPath(),
604 "legacy" ), false, null );
605 DavResourceLocator locator =
606 new ArchivaDavResourceLocator( "", "/repository/" + LEGACY_REPO + "/eclipse/maven-metadata.xml",
607 LEGACY_REPO, new ArchivaDavLocatorFactory() );
609 ManagedRepositoryContent legacyRepo = createManagedRepositoryContent( LEGACY_REPO );
611 // use actual object (this performs the isMetadata, isDefault and isSupportFile check!)
612 RepositoryRequest repoRequest = new RepositoryRequest( new LegacyPathParser( this.archivaConfiguration ) );
613 resourceFactory.setRepositoryRequest( repoRequest );
617 archivaConfigurationControl.reset();
618 //archivaConfigurationControl.expectAndReturn( archivaConfiguration.getConfiguration(), config );
619 expect( archivaConfiguration.getConfiguration() ).andReturn( config );
620 //repoContentFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( LEGACY_REPO ),
622 expect( repoFactory.getManagedRepositoryContent( LEGACY_REPO ) ).andReturn( legacyRepo );
623 //requestControl.expectAndReturn( request.getMethod(), "GET", 2 );
624 expect( request.getMethod() ).andReturn( "GET" ).times( 2 );
625 //requestControl.expectAndReturn( request.getRemoteAddr(), "http://localhost:8080", 2 );
626 expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 2 );
627 //requestControl.expectAndReturn( request.getDavSession(), new ArchivaDavSession(), 2 );
628 expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 2 );
630 archivaConfigurationControl.replay();
631 repoContentFactoryControl.replay();
632 requestControl.replay();
634 resourceFactory.createResource( locator, request, response );
636 archivaConfigurationControl.verify();
637 repoContentFactoryControl.verify();
638 requestControl.verify();
640 fail( "A 404 error should have been thrown!" );
642 catch ( DavException e )
644 assertEquals( 404, e.getErrorCode() );
648 class OverridingArchivaDavResourceFactory
649 extends ArchivaDavResourceFactory
652 OverridingArchivaDavResourceFactory( ApplicationContext applicationContext, PlexusSisuBridge plexusSisuBridge,
653 ArchivaConfiguration archivaConfiguration )
654 throws PlexusSisuBridgeException
656 super( applicationContext, plexusSisuBridge, archivaConfiguration );
659 protected boolean isAuthorized( DavServletRequest request, String repositoryId )
662 if ( RELEASES_REPO.equals( repositoryId ) )
664 throw new UnauthorizedDavException( repositoryId,
665 "You are not authenticated and authorized to access any repository." );
673 protected String getActivePrincipal( DavServletRequest request )
679 class OverridingRepositoryProxyConnectors
680 extends DefaultRepositoryProxyConnectors
682 public File fetchMetatadaFromProxies( ManagedRepositoryContent repository, String logicalPath )
684 File target = new File( repository.getRepoRoot(), logicalPath );
687 FileUtils.copyFile( new File( "target/test-classes/maven-metadata.xml" ), target );
689 catch ( IOException e )