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.FileTypes;
35 import org.apache.archiva.configuration.RepositoryGroupConfiguration;
36 import org.apache.archiva.metadata.repository.storage.maven2.ArtifactMappingProvider;
37 import org.apache.archiva.proxy.ProxyRegistry;
38 import org.apache.archiva.repository.EditableManagedRepository;
39 import org.apache.archiva.repository.ManagedRepositoryContent;
40 import org.apache.archiva.repository.RemoteRepository;
41 import org.apache.archiva.repository.RemoteRepositoryContent;
42 import org.apache.archiva.repository.Repository;
43 import org.apache.archiva.repository.RepositoryContent;
44 import org.apache.archiva.repository.RepositoryContentFactory;
45 import org.apache.archiva.repository.RepositoryContentProvider;
46 import org.apache.archiva.repository.RepositoryException;
47 import org.apache.archiva.repository.RepositoryRegistry;
48 import org.apache.archiva.repository.RepositoryType;
49 import org.apache.archiva.repository.content.maven2.ManagedDefaultRepositoryContent;
50 import org.apache.archiva.repository.content.maven2.RepositoryRequest;
51 import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
52 import org.apache.commons.lang.StringUtils;
53 import org.apache.jackrabbit.webdav.DavException;
54 import org.apache.jackrabbit.webdav.DavResourceLocator;
55 import org.apache.jackrabbit.webdav.DavServletRequest;
56 import org.apache.jackrabbit.webdav.DavServletResponse;
57 import org.easymock.EasyMock;
58 import org.easymock.IMocksControl;
59 import org.junit.After;
60 import org.junit.Before;
61 import org.junit.Test;
62 import org.junit.runner.RunWith;
63 import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
64 import org.springframework.context.ApplicationContext;
65 import org.springframework.context.ConfigurableApplicationContext;
66 import org.springframework.test.context.ContextConfiguration;
68 import javax.inject.Inject;
69 import java.nio.file.Path;
70 import java.nio.file.Paths;
71 import java.util.ArrayList;
72 import java.util.HashSet;
73 import java.util.List;
74 import java.util.Locale;
76 import java.util.concurrent.atomic.AtomicReference;
78 import static org.easymock.EasyMock.*;
81 * ArchivaDavResourceFactoryTest
83 @RunWith( ArchivaSpringJUnit4ClassRunner.class )
84 @ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" } )
85 public class ArchivaDavResourceFactoryTest
88 private AtomicReference<Path> projectBase = new AtomicReference<>();
90 private static final String RELEASES_REPO = "releases";
92 private static final String INTERNAL_REPO = "internal";
94 private static final String LOCAL_MIRROR_REPO = "local-mirror";
96 private static final String LEGACY_REPO = "legacy-repo";
98 private static final String LOCAL_REPO_GROUP = "local";
100 private OverridingArchivaDavResourceFactory resourceFactory;
102 private IMocksControl requestControl;
104 private DavServletRequest request;
106 private IMocksControl repoRequestControl;
108 private RepositoryRequest repoRequest;
110 private IMocksControl responseControl;
112 private DavServletResponse response;
114 private IMocksControl archivaConfigurationControl;
116 private ArchivaConfiguration archivaConfiguration;
118 private Configuration config;
120 private IMocksControl repoContentFactoryControl;
122 private RepositoryContentFactory repoFactory;
125 ApplicationContext applicationContext;
128 PlexusSisuBridge plexusSisuBridge;
131 DefaultManagedRepositoryAdmin defaultManagedRepositoryAdmin;
134 RepositoryRegistry repositoryRegistry;
137 RemoteRepositoryAdmin remoteRepositoryAdmin;
140 ProxyRegistry proxyRegistry;
144 DefaultRepositoryGroupAdmin defaultRepositoryGroupAdmin;
147 List<? extends ArtifactMappingProvider> artifactMappingProviders;
152 public Path getProjectBase() {
153 if (this.projectBase.get()==null) {
154 String pathVal = System.getProperty("mvn.project.base.dir");
156 if (StringUtils.isEmpty(pathVal)) {
157 baseDir= Paths.get("").toAbsolutePath();
159 baseDir = Paths.get(pathVal).toAbsolutePath();
161 this.projectBase.compareAndSet(null, baseDir);
163 return this.projectBase.get();
173 requestControl = createControl();
174 request = requestControl.createMock( DavServletRequest.class );
176 responseControl = createControl();
177 response = responseControl.createMock( DavServletResponse.class );
178 //responseControl.setDefaultMatcher( MockControl.ALWAYS_MATCHER );
180 archivaConfigurationControl = createControl();
181 archivaConfiguration = archivaConfigurationControl.createMock( ArchivaConfiguration.class );
183 config = new Configuration();
184 expect( archivaConfiguration.getConfiguration() ).andReturn( config ).times( 2, 20 );
185 expect (archivaConfiguration.getDefaultLocale()).andReturn( Locale.getDefault() ).anyTimes();
186 archivaConfiguration.addListener( EasyMock.anyObject( ) );
187 expectLastCall().times(0, 4);
188 archivaConfiguration.save( config );
190 expectLastCall().times( 0, 4 );
191 archivaConfigurationControl.replay();
193 defaultManagedRepositoryAdmin.setArchivaConfiguration( archivaConfiguration );
194 repositoryRegistry.setArchivaConfiguration( archivaConfiguration );
195 repositoryRegistry.reload();
196 ( (DefaultRepositoryCommonValidator) defaultManagedRepositoryAdmin.getRepositoryCommonValidator() ).setArchivaConfiguration(
197 archivaConfiguration );
198 if ( defaultManagedRepositoryAdmin.getManagedRepository( RELEASES_REPO ) == null )
200 defaultManagedRepositoryAdmin.addManagedRepository(
201 createManagedRepository( RELEASES_REPO, getProjectBase().resolve( "target/test-classes/" + RELEASES_REPO ).toString(),
202 "default" ), false, null );
204 if ( defaultManagedRepositoryAdmin.getManagedRepository( INTERNAL_REPO ) == null )
206 defaultManagedRepositoryAdmin.addManagedRepository(
207 createManagedRepository( INTERNAL_REPO, getProjectBase().resolve( "target/test-classes/" + INTERNAL_REPO ).toString(),
208 "default" ), false, null );
210 RepositoryGroup repoGroupConfig = new RepositoryGroup();
211 repoGroupConfig.setId( LOCAL_REPO_GROUP );
212 repoGroupConfig.addRepository( RELEASES_REPO );
213 repoGroupConfig.addRepository( INTERNAL_REPO );
215 defaultRepositoryGroupAdmin.setArchivaConfiguration( archivaConfiguration );
216 if ( defaultManagedRepositoryAdmin.getManagedRepository( LOCAL_REPO_GROUP ) == null )
218 defaultRepositoryGroupAdmin.addRepositoryGroup( repoGroupConfig, null );
221 repoContentFactoryControl = createControl();
222 repoFactory = repoContentFactoryControl.createMock( RepositoryContentFactory.class );
224 repoRequestControl = createControl();
225 repoRequest = repoRequestControl.createMock( RepositoryRequest.class );
228 new OverridingArchivaDavResourceFactory( applicationContext, plexusSisuBridge, archivaConfiguration );
229 resourceFactory.setArchivaConfiguration( archivaConfiguration );
230 resourceFactory.setRepositoryFactory( repoFactory );
231 resourceFactory.setRepositoryRequest( repoRequest );
232 proxyRegistry.getAllHandler().get(RepositoryType.MAVEN).clear();
233 proxyRegistry.getAllHandler().get(RepositoryType.MAVEN).add(new OverridingRepositoryProxyHandler(this));
234 resourceFactory.setProxyRegistry(proxyRegistry);
235 resourceFactory.setRemoteRepositoryAdmin( remoteRepositoryAdmin );
236 resourceFactory.setManagedRepositoryAdmin( defaultManagedRepositoryAdmin );
237 resourceFactory.setRepositoryRegistry( repositoryRegistry );
240 private ManagedRepository createManagedRepository( String id, String location, String layout )
242 ManagedRepository repoConfig = new ManagedRepository( Locale.getDefault());
243 repoConfig.setId( id );
244 repoConfig.setName( id );
245 repoConfig.setLocation( location );
246 repoConfig.setLayout( layout );
251 private ManagedRepositoryContent createManagedRepositoryContent( String repoId )
252 throws RepositoryAdminException
254 ManagedRepositoryContent repoContent = new ManagedDefaultRepositoryContent(artifactMappingProviders, fileTypes);
255 org.apache.archiva.repository.ManagedRepository repo = repositoryRegistry.getManagedRepository( repoId );
256 repoContent.setRepository( repo );
257 if (repo!=null && repo instanceof EditableManagedRepository)
259 ( (EditableManagedRepository) repo ).setContent( repoContent );
264 private RepositoryContentProvider createRepositoryContentProvider(ManagedRepositoryContent content) {
265 Set<RepositoryType> TYPES = new HashSet<>( );
266 TYPES.add(RepositoryType.MAVEN);
267 return new RepositoryContentProvider( )
272 public boolean supportsLayout( String layout )
278 public Set<RepositoryType> getSupportedRepositoryTypes( )
284 public boolean supports( RepositoryType type )
290 public RemoteRepositoryContent createRemoteContent( RemoteRepository repository ) throws RepositoryException
296 public ManagedRepositoryContent createManagedContent( org.apache.archiva.repository.ManagedRepository repository ) throws RepositoryException
298 content.setRepository( repository );
303 public <T extends RepositoryContent, V extends Repository> T createContent( Class<T> clazz, V repository ) throws RepositoryException
312 public void tearDown()
316 String appserverBase = System.getProperty( "appserver.base" );
317 if ( StringUtils.isNotEmpty( appserverBase ) )
319 org.apache.archiva.common.utils.FileUtils.deleteDirectory( Paths.get( appserverBase ) );
323 // MRM-1232 - Unable to get artifacts from repositories which requires Repository Manager role using repository group
325 public void testRepositoryGroupFirstRepositoryRequiresAuthentication()
328 DavResourceLocator locator = new ArchivaDavResourceLocator( "", "/repository/" + LOCAL_REPO_GROUP
329 + "/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar", LOCAL_REPO_GROUP,
330 new ArchivaDavLocatorFactory() );
332 ManagedRepositoryContent internalRepo = createManagedRepositoryContent( INTERNAL_REPO );
333 ManagedRepositoryContent releasesRepo = createManagedRepositoryContent( RELEASES_REPO );
337 archivaConfigurationControl.reset();
339 expect( archivaConfiguration.getConfiguration() ).andReturn( config ).times( 3 );
341 expect( request.getMethod() ).andReturn( "GET" ).times( 3 );
343 expect( request.getPathInfo() ).andReturn( "org/apache/archiva" ).times( 0, 2 );
345 expect( repoFactory.getManagedRepositoryContent( RELEASES_REPO ) ).andReturn( releasesRepo );
347 expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 2 );
349 expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 2 );
351 expect( request.getContextPath() ).andReturn( "" ).times( 2 );
353 expect( repoRequest.isSupportFile( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( true );
356 repoRequest.isDefault( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn(
359 expect( repoRequest.toArtifactReference(
360 "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( null );
362 expect( repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar",
363 internalRepo ) ).andReturn(
364 Paths.get( config.findManagedRepositoryById( INTERNAL_REPO ).getLocation(),
365 "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).toString());
367 expect( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ) ).andReturn( internalRepo );
369 expect( repoRequest.isArchetypeCatalog(
370 "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( false );
371 archivaConfigurationControl.replay();
372 requestControl.replay();
373 repoContentFactoryControl.replay();
374 repoRequestControl.replay();
376 resourceFactory.createResource( locator, request, response );
378 archivaConfigurationControl.verify();
379 requestControl.verify();
380 repoContentFactoryControl.verify();
381 repoRequestControl.verify();
383 fail( "A DavException with 401 error code should have been thrown." );
385 catch ( DavException e )
387 assertEquals( 401, e.getErrorCode() );
392 public void testRepositoryGroupLastRepositoryRequiresAuthentication()
395 DavResourceLocator locator = new ArchivaDavResourceLocator( "", "/repository/" + LOCAL_REPO_GROUP
396 + "/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar", LOCAL_REPO_GROUP,
397 new ArchivaDavLocatorFactory() );
399 List<RepositoryGroupConfiguration> repoGroups = new ArrayList<>();
400 RepositoryGroupConfiguration repoGroup = new RepositoryGroupConfiguration();
401 repoGroup.setId( LOCAL_REPO_GROUP );
402 repoGroup.addRepository( INTERNAL_REPO );
403 repoGroup.addRepository( RELEASES_REPO );
405 repoGroups.add( repoGroup );
407 config.setRepositoryGroups( repoGroups );
409 ManagedRepositoryContent internalRepo = createManagedRepositoryContent( INTERNAL_REPO );
411 ManagedRepositoryContent releasesRepo = createManagedRepositoryContent( RELEASES_REPO );
415 archivaConfigurationControl.reset();
417 expect( archivaConfiguration.getConfiguration() ).andReturn( config ).times( 3 );
419 expect( request.getMethod() ).andReturn( "GET" ).times( 3 );
421 expect( request.getPathInfo() ).andReturn( "org/apache/archiva" ).times( 0, 2 );
423 expect( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ) ).andReturn( internalRepo );
425 expect( repoFactory.getManagedRepositoryContent( RELEASES_REPO ) ).andReturn( releasesRepo );
427 expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 2 );
429 expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 2 );
431 expect( request.getContextPath() ).andReturn( "" ).times( 2 );
433 expect( repoRequest.isSupportFile( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( false );
436 repoRequest.isDefault( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn(
439 expect( repoRequest.toArtifactReference(
440 "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( null );
442 expect( repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar",
443 internalRepo ) ).andReturn(
444 Paths.get( config.findManagedRepositoryById( INTERNAL_REPO ).getLocation(),
445 "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).toString());
448 expect( repoRequest.isArchetypeCatalog(
449 "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( false );
450 archivaConfigurationControl.replay();
451 requestControl.replay();
452 repoContentFactoryControl.replay();
453 repoRequestControl.replay();
455 resourceFactory.createResource( locator, request, response );
457 archivaConfigurationControl.verify();
458 requestControl.verify();
459 repoContentFactoryControl.verify();
460 repoRequestControl.verify();
462 fail( "A DavException with 401 error code should have been thrown." );
464 catch ( DavException e )
466 assertEquals( 401, e.getErrorCode() );
471 public void testRepositoryGroupArtifactDoesNotExistInAnyOfTheReposAuthenticationDisabled()
474 DavResourceLocator locator = new ArchivaDavResourceLocator( "", "/repository/" + LOCAL_REPO_GROUP
475 + "/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar", LOCAL_REPO_GROUP,
476 new ArchivaDavLocatorFactory() );
478 defaultManagedRepositoryAdmin.addManagedRepository(
479 createManagedRepository( LOCAL_MIRROR_REPO, Paths.get( "target/test-classes/local-mirror" ).toString(),
480 "default" ), false, null );
482 List<RepositoryGroupConfiguration> repoGroups = new ArrayList<>();
483 RepositoryGroupConfiguration repoGroup = new RepositoryGroupConfiguration();
484 repoGroup.setId( LOCAL_REPO_GROUP );
485 repoGroup.addRepository( INTERNAL_REPO );
486 repoGroup.addRepository( LOCAL_MIRROR_REPO );
488 repoGroups.add( repoGroup );
490 config.setRepositoryGroups( repoGroups );
492 ManagedRepositoryContent internalRepo = createManagedRepositoryContent( INTERNAL_REPO );
493 ManagedRepositoryContent localMirrorRepo = createManagedRepositoryContent( LOCAL_MIRROR_REPO );
497 archivaConfigurationControl.reset();
499 expect( archivaConfiguration.getConfiguration() ).andReturn( config ).times( 3 );
501 expect( request.getMethod() ).andReturn( "GET" ).times( 5 );
503 expect( request.getPathInfo() ).andReturn( "org/apache/archiva" ).times( 0, 2 );
505 expect( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ) ).andReturn( internalRepo );
507 expect( repoFactory.getManagedRepositoryContent( LOCAL_MIRROR_REPO ) ).andReturn( localMirrorRepo );
509 expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 4 );
511 expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 4 );
513 expect( request.getContextPath() ).andReturn( "" ).times( 2 );
515 expect( repoRequest.isSupportFile( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( false ).times( 2 );
518 repoRequest.isDefault( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn(
521 expect( repoRequest.toArtifactReference(
522 "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( null ).times( 2 );
524 expect( repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar",
525 internalRepo ) ).andReturn(
526 Paths.get( config.findManagedRepositoryById( INTERNAL_REPO ).getLocation(),
527 "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).toString() );
529 expect( repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar",
531 .andReturn( Paths.get( config.findManagedRepositoryById( LOCAL_MIRROR_REPO ).getLocation(),
532 "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).toString());
534 expect( repoRequest.isArchetypeCatalog( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( false ).times( 2 );
535 archivaConfigurationControl.replay();
536 requestControl.replay();
537 repoContentFactoryControl.replay();
538 repoRequestControl.replay();
540 resourceFactory.createResource( locator, request, response );
542 archivaConfigurationControl.verify();
543 requestControl.verify();
544 repoContentFactoryControl.verify();
545 repoRequestControl.verify();
547 fail( "A DavException with 404 error code should have been thrown." );
549 catch ( DavException e )
551 assertEquals( 404, e.getErrorCode() );
557 public void testRequestArtifactMetadataThreePartsRepoHasDefaultLayout()
560 // should fetch metadata
561 DavResourceLocator locator =
562 new ArchivaDavResourceLocator( "", "/repository/" + INTERNAL_REPO + "/eclipse/jdtcore/maven-metadata.xml",
563 INTERNAL_REPO, new ArchivaDavLocatorFactory() );
565 ManagedRepositoryContent internalRepo = createManagedRepositoryContent( INTERNAL_REPO );
567 // use actual object (this performs the isMetadata, isDefault and isSupportFile check!)
568 RepositoryRequest repoRequest = new RepositoryRequest( );
569 resourceFactory.setRepositoryRequest( repoRequest );
573 archivaConfigurationControl.reset();
575 expect( archivaConfiguration.getConfiguration() ).andReturn( config ).times( 1 );
577 expect( request.getMethod() ).andReturn( "GET" ).times( 4 );
579 expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 3 );
581 expect( request.getContextPath() ).andReturn( "" ).times( 1 );
583 expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 2 );
585 expect( request.getRequestURI() ).andReturn( "http://localhost:8080/archiva/repository/" + INTERNAL_REPO + "/eclipse/jdtcore/maven-metadata.xml" );
586 response.setHeader( "Pragma", "no-cache" );
590 response.setHeader( "Cache-Control", "no-cache" );
594 response.setDateHeader( eq("Last-Modified"), anyLong() );
597 archivaConfigurationControl.replay();
598 repoContentFactoryControl.replay();
599 requestControl.replay();
600 responseControl.replay();
602 resourceFactory.createResource( locator, request, response );
604 archivaConfigurationControl.verify();
605 repoContentFactoryControl.verify();
606 requestControl.verify();
607 responseControl.verify();
609 catch ( DavException e )
612 fail( "A DavException should not have been thrown! "+e.getMessage() );
617 public void testRequestArtifactMetadataTwoPartsRepoHasDefaultLayout()
620 // should not fetch metadata
621 DavResourceLocator locator =
622 new ArchivaDavResourceLocator( "", "/repository/" + INTERNAL_REPO + "/eclipse/maven-metadata.xml",
623 INTERNAL_REPO, new ArchivaDavLocatorFactory() );
625 ManagedRepositoryContent internalRepo = createManagedRepositoryContent( INTERNAL_REPO );
627 // use actual object (this performs the isMetadata, isDefault and isSupportFile check!)
628 RepositoryRequest repoRequest = new RepositoryRequest( );
629 resourceFactory.setRepositoryRequest( repoRequest );
633 archivaConfigurationControl.reset();
635 expect( archivaConfiguration.getConfiguration() ).andReturn( config ).times( 2 );
637 expect( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ) ).andReturn( internalRepo );
639 expect( request.getMethod() ).andReturn( "GET" ).times( 3 );
641 expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 3 );
643 expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 2 );
645 expect( request.getContextPath() ).andReturn( "" ).times( 2 );
647 archivaConfigurationControl.replay();
648 repoContentFactoryControl.replay();
649 requestControl.replay();
651 resourceFactory.createResource( locator, request, response );
653 archivaConfigurationControl.verify();
654 repoContentFactoryControl.verify();
655 requestControl.verify();
657 fail( "A 404 error should have been thrown!" );
659 catch ( DavException e )
661 assertEquals( 404, e.getErrorCode() );
666 public void testRequestMetadataRepoIsLegacy()
669 ManagedRepositoryContent legacyRepo = createManagedRepositoryContent( LEGACY_REPO );
670 ConfigurableListableBeanFactory beanFactory = ((ConfigurableApplicationContext) applicationContext).getBeanFactory();
671 RepositoryContentProvider provider = createRepositoryContentProvider(legacyRepo );
672 beanFactory.registerSingleton("repositoryContentProvider#legacy", provider);
673 RepositoryContentFactory repoContentFactory = applicationContext.getBean( "repositoryContentFactory#default", RepositoryContentFactory.class );
674 repoContentFactory.getRepositoryContentProviders().add(provider);
675 defaultManagedRepositoryAdmin.addManagedRepository(
676 createManagedRepository( LEGACY_REPO, getProjectBase().resolve( "target/test-classes/" + LEGACY_REPO ).toString(),
677 "legacy" ), false, null );
678 DavResourceLocator locator =
679 new ArchivaDavResourceLocator( "", "/repository/" + LEGACY_REPO + "/eclipse/maven-metadata.xml",
680 LEGACY_REPO, new ArchivaDavLocatorFactory() );
683 // use actual object (this performs the isMetadata, isDefault and isSupportFile check!)
684 RepositoryRequest repoRequest = new RepositoryRequest( );
685 resourceFactory.setRepositoryRequest( repoRequest );
689 archivaConfigurationControl.reset();
691 expect( archivaConfiguration.getConfiguration() ).andReturn( config ).times( 2 );
693 expect( repoFactory.getManagedRepositoryContent( LEGACY_REPO ) ).andReturn( legacyRepo );
695 expect( request.getMethod() ).andReturn( "GET" ).times( 3 );
697 expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 3 );
699 expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 2 );
701 expect( request.getContextPath() ).andReturn( "" ).times( 2 );
703 archivaConfigurationControl.replay();
704 repoContentFactoryControl.replay();
705 requestControl.replay();
707 resourceFactory.createResource( locator, request, response );
709 archivaConfigurationControl.verify();
710 repoContentFactoryControl.verify();
711 requestControl.verify();
713 fail( "A 404 error should have been thrown!" );
715 catch ( DavException e )
717 assertEquals( 404, e.getErrorCode() );
721 class OverridingArchivaDavResourceFactory
722 extends ArchivaDavResourceFactory
725 OverridingArchivaDavResourceFactory( ApplicationContext applicationContext, PlexusSisuBridge plexusSisuBridge,
726 ArchivaConfiguration archivaConfiguration )
727 throws PlexusSisuBridgeException
729 super( applicationContext, plexusSisuBridge, archivaConfiguration );
733 protected boolean isAuthorized( DavServletRequest request, String repositoryId )
736 if ( RELEASES_REPO.equals( repositoryId ) )
738 throw new UnauthorizedDavException( repositoryId,
739 "You are not authenticated and authorized to access any repository." );
748 protected String getActivePrincipal( DavServletRequest request )