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.filelock.FileLockManager;
31 import org.apache.archiva.common.plexusbridge.PlexusSisuBridge;
32 import org.apache.archiva.common.plexusbridge.PlexusSisuBridgeException;
33 import org.apache.archiva.configuration.ArchivaConfiguration;
34 import org.apache.archiva.configuration.Configuration;
35 import org.apache.archiva.configuration.FileTypes;
36 import org.apache.archiva.configuration.RepositoryGroupConfiguration;
37 import org.apache.archiva.repository.ManagedRepositoryContent;
38 import org.apache.archiva.repository.maven.content.MavenContentHelper;
39 import org.apache.archiva.repository.maven.metadata.storage.ArtifactMappingProvider;
40 import org.apache.archiva.proxy.ProxyRegistry;
41 import org.apache.archiva.repository.EditableManagedRepository;
42 import org.apache.archiva.repository.BaseRepositoryContentLayout;
43 import org.apache.archiva.repository.RemoteRepository;
44 import org.apache.archiva.repository.RemoteRepositoryContent;
45 import org.apache.archiva.repository.Repository;
46 import org.apache.archiva.repository.RepositoryContent;
47 import org.apache.archiva.repository.RepositoryContentFactory;
48 import org.apache.archiva.repository.RepositoryContentProvider;
49 import org.apache.archiva.repository.RepositoryException;
50 import org.apache.archiva.repository.RepositoryRegistry;
51 import org.apache.archiva.repository.RepositoryType;
52 import org.apache.archiva.repository.maven.content.ManagedDefaultRepositoryContent;
53 import org.apache.archiva.repository.maven.content.MavenRepositoryRequestInfo;
54 import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
55 import org.apache.commons.lang3.StringUtils;
56 import org.apache.jackrabbit.webdav.DavException;
57 import org.apache.jackrabbit.webdav.DavResourceLocator;
58 import org.apache.jackrabbit.webdav.DavServletRequest;
59 import org.apache.jackrabbit.webdav.DavServletResponse;
60 import org.easymock.EasyMock;
61 import org.easymock.IMocksControl;
62 import org.junit.After;
63 import org.junit.Before;
64 import org.junit.Test;
65 import org.junit.runner.RunWith;
66 import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
67 import org.springframework.context.ApplicationContext;
68 import org.springframework.context.ConfigurableApplicationContext;
69 import org.springframework.test.context.ContextConfiguration;
71 import javax.inject.Inject;
72 import javax.inject.Named;
73 import java.nio.file.Path;
74 import java.nio.file.Paths;
75 import java.util.ArrayList;
76 import java.util.HashSet;
77 import java.util.List;
78 import java.util.Locale;
80 import java.util.concurrent.atomic.AtomicReference;
82 import static org.easymock.EasyMock.*;
85 * ArchivaDavResourceFactoryTest
87 @RunWith( ArchivaSpringJUnit4ClassRunner.class )
88 @ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" } )
89 public class ArchivaDavResourceFactoryTest
92 private AtomicReference<Path> projectBase = new AtomicReference<>();
94 private static final String RELEASES_REPO = "releases";
96 private static final String INTERNAL_REPO = "internal";
98 private static final String LOCAL_MIRROR_REPO = "local-mirror";
100 private static final String LEGACY_REPO = "legacy-repo";
102 private static final String LOCAL_REPO_GROUP = "local";
104 private OverridingArchivaDavResourceFactory resourceFactory;
106 private IMocksControl requestControl;
108 private DavServletRequest request;
110 private IMocksControl repoRequestControl;
112 private MavenRepositoryRequestInfo repoRequest;
114 private IMocksControl responseControl;
116 private DavServletResponse response;
118 private IMocksControl archivaConfigurationControl;
120 private ArchivaConfiguration archivaConfiguration;
122 private Configuration config;
124 private IMocksControl repoContentFactoryControl;
126 private RepositoryContentFactory repoFactory;
129 ApplicationContext applicationContext;
132 PlexusSisuBridge plexusSisuBridge;
135 DefaultManagedRepositoryAdmin defaultManagedRepositoryAdmin;
138 RepositoryRegistry repositoryRegistry;
141 RemoteRepositoryAdmin remoteRepositoryAdmin;
144 ProxyRegistry proxyRegistry;
147 @Named( "MavenContentHelper" )
148 MavenContentHelper mavenContentHelper;
151 DefaultRepositoryGroupAdmin defaultRepositoryGroupAdmin;
154 List<? extends ArtifactMappingProvider> artifactMappingProviders;
157 FileLockManager fileLockManager;
162 public Path getProjectBase() {
163 if (this.projectBase.get()==null) {
164 String pathVal = System.getProperty("mvn.project.base.dir");
166 if (StringUtils.isEmpty(pathVal)) {
167 baseDir= Paths.get("").toAbsolutePath();
169 baseDir = Paths.get(pathVal).toAbsolutePath();
171 this.projectBase.compareAndSet(null, baseDir);
173 return this.projectBase.get();
183 requestControl = createControl();
184 request = requestControl.createMock( DavServletRequest.class );
186 responseControl = createControl();
187 response = responseControl.createMock( DavServletResponse.class );
188 //responseControl.setDefaultMatcher( MockControl.ALWAYS_MATCHER );
190 archivaConfigurationControl = createControl();
191 archivaConfiguration = archivaConfigurationControl.createMock( ArchivaConfiguration.class );
193 config = new Configuration();
194 expect( archivaConfiguration.getConfiguration() ).andReturn( config ).times( 2, 20 );
195 expect (archivaConfiguration.getDefaultLocale()).andReturn( Locale.getDefault() ).anyTimes();
196 archivaConfiguration.addListener( EasyMock.anyObject( ) );
197 expectLastCall().times(0, 4);
198 archivaConfiguration.save( config );
200 expectLastCall().times( 0, 5 );
201 archivaConfigurationControl.replay();
203 defaultManagedRepositoryAdmin.setArchivaConfiguration( archivaConfiguration );
204 repositoryRegistry.setArchivaConfiguration( archivaConfiguration );
205 repositoryRegistry.reload();
206 ( (DefaultRepositoryCommonValidator) defaultManagedRepositoryAdmin.getRepositoryCommonValidator() ).setArchivaConfiguration(
207 archivaConfiguration );
208 if ( defaultManagedRepositoryAdmin.getManagedRepository( RELEASES_REPO ) == null )
210 defaultManagedRepositoryAdmin.addManagedRepository(
211 createManagedRepository( RELEASES_REPO, getProjectBase().resolve( "target/test-classes/" + RELEASES_REPO ).toString(),
212 "default" ), false, null );
214 if ( defaultManagedRepositoryAdmin.getManagedRepository( INTERNAL_REPO ) == null )
216 defaultManagedRepositoryAdmin.addManagedRepository(
217 createManagedRepository( INTERNAL_REPO, getProjectBase().resolve( "target/test-classes/" + INTERNAL_REPO ).toString(),
218 "default" ), false, null );
220 RepositoryGroup repoGroupConfig = new RepositoryGroup();
221 repoGroupConfig.setId( LOCAL_REPO_GROUP );
222 repoGroupConfig.addRepository( RELEASES_REPO );
223 repoGroupConfig.addRepository( INTERNAL_REPO );
225 defaultRepositoryGroupAdmin.setArchivaConfiguration( archivaConfiguration );
226 if ( defaultManagedRepositoryAdmin.getManagedRepository( LOCAL_REPO_GROUP ) == null )
228 defaultRepositoryGroupAdmin.addRepositoryGroup( repoGroupConfig, null );
231 repoContentFactoryControl = createControl();
232 repoFactory = repoContentFactoryControl.createMock( RepositoryContentFactory.class );
234 repoRequestControl = createControl();
235 repoRequest = repoRequestControl.createMock( MavenRepositoryRequestInfo.class );
238 new OverridingArchivaDavResourceFactory( applicationContext, plexusSisuBridge, archivaConfiguration );
239 resourceFactory.setArchivaConfiguration( archivaConfiguration );
240 proxyRegistry.getAllHandler().get(RepositoryType.MAVEN).clear();
241 proxyRegistry.getAllHandler().get(RepositoryType.MAVEN).add(new OverridingRepositoryProxyHandler(this));
242 resourceFactory.setProxyRegistry(proxyRegistry);
243 resourceFactory.setRemoteRepositoryAdmin( remoteRepositoryAdmin );
244 resourceFactory.setManagedRepositoryAdmin( defaultManagedRepositoryAdmin );
245 resourceFactory.setRepositoryRegistry( repositoryRegistry );
248 private ManagedRepository createManagedRepository( String id, String location, String layout )
250 ManagedRepository repoConfig = new ManagedRepository( Locale.getDefault());
251 repoConfig.setId( id );
252 repoConfig.setName( id );
253 repoConfig.setLocation( location );
254 repoConfig.setLayout( layout );
259 private ManagedRepositoryContent createManagedRepositoryContent( String repoId )
260 throws RepositoryAdminException
262 org.apache.archiva.repository.ManagedRepository repo = repositoryRegistry.getManagedRepository( repoId );
263 ManagedDefaultRepositoryContent repoContent = new ManagedDefaultRepositoryContent(repo, artifactMappingProviders, fileTypes, fileLockManager);
264 if (repo!=null && repo instanceof EditableManagedRepository)
266 ( (EditableManagedRepository) repo ).setContent( repoContent );
268 repoContent.setMavenContentHelper( mavenContentHelper );
272 private RepositoryContentProvider createRepositoryContentProvider( ManagedRepositoryContent content) {
273 Set<RepositoryType> TYPES = new HashSet<>( );
274 TYPES.add(RepositoryType.MAVEN);
275 return new RepositoryContentProvider( )
280 public boolean supportsLayout( String layout )
286 public Set<RepositoryType> getSupportedRepositoryTypes( )
292 public boolean supports( RepositoryType type )
298 public RemoteRepositoryContent createRemoteContent( RemoteRepository repository ) throws RepositoryException
304 public ManagedRepositoryContent createManagedContent( org.apache.archiva.repository.ManagedRepository repository ) throws RepositoryException
306 content.setRepository( repository );
311 public <T extends RepositoryContent, V extends Repository> T createContent( Class<T> clazz, V repository ) throws RepositoryException
320 public void tearDown()
324 String appserverBase = System.getProperty( "appserver.base" );
325 if ( StringUtils.isNotEmpty( appserverBase ) )
327 org.apache.archiva.common.utils.FileUtils.deleteDirectory( Paths.get( appserverBase ) );
331 // MRM-1232 - Unable to get artifacts from repositories which requires Repository Manager role using repository group
333 public void testRepositoryGroupFirstRepositoryRequiresAuthentication()
336 DavResourceLocator locator = new ArchivaDavResourceLocator( "", "/repository/" + LOCAL_REPO_GROUP
337 + "/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar", LOCAL_REPO_GROUP,
338 new ArchivaDavLocatorFactory() );
340 ManagedRepositoryContent internalRepo = createManagedRepositoryContent( INTERNAL_REPO );
341 ManagedRepositoryContent releasesRepo = createManagedRepositoryContent( RELEASES_REPO );
345 archivaConfigurationControl.reset();
347 expect( archivaConfiguration.getConfiguration() ).andReturn( config ).times( 3 );
349 expect( request.getMethod() ).andReturn( "GET" ).times( 3 );
351 expect( request.getPathInfo() ).andReturn( "org/apache/archiva" ).times( 0, 2 );
353 expect( repoFactory.getManagedRepositoryContent( RELEASES_REPO ) ).andReturn( releasesRepo );
355 expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 2 );
357 expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 2 );
359 expect( request.getContextPath() ).andReturn( "" ).times( 2 );
361 expect( repoRequest.isSupportFile( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( true );
364 repoRequest.getLayout( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn(
367 expect( repoRequest.toItemSelector(
368 "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( null );
370 expect( repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar"
372 Paths.get( config.findManagedRepositoryById( INTERNAL_REPO ).getLocation(),
373 "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).toString());
375 expect( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ) ).andReturn( internalRepo );
377 expect( repoRequest.isArchetypeCatalog(
378 "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( false );
379 archivaConfigurationControl.replay();
380 requestControl.replay();
381 repoContentFactoryControl.replay();
382 repoRequestControl.replay();
384 resourceFactory.createResource( locator, request, response );
386 archivaConfigurationControl.verify();
387 requestControl.verify();
388 repoContentFactoryControl.verify();
389 repoRequestControl.verify();
391 fail( "A DavException with 401 error code should have been thrown." );
393 catch ( DavException e )
395 assertEquals( 401, e.getErrorCode() );
400 public void testRepositoryGroupLastRepositoryRequiresAuthentication()
403 DavResourceLocator locator = new ArchivaDavResourceLocator( "", "/repository/" + LOCAL_REPO_GROUP
404 + "/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar", LOCAL_REPO_GROUP,
405 new ArchivaDavLocatorFactory() );
407 List<RepositoryGroupConfiguration> repoGroups = new ArrayList<>();
408 RepositoryGroupConfiguration repoGroup = new RepositoryGroupConfiguration();
409 repoGroup.setId( LOCAL_REPO_GROUP );
410 repoGroup.addRepository( INTERNAL_REPO );
411 repoGroup.addRepository( RELEASES_REPO );
413 repoGroups.add( repoGroup );
415 config.setRepositoryGroups( repoGroups );
417 ManagedRepositoryContent internalRepo = createManagedRepositoryContent( INTERNAL_REPO );
419 ManagedRepositoryContent releasesRepo = createManagedRepositoryContent( RELEASES_REPO );
423 archivaConfigurationControl.reset();
425 expect( archivaConfiguration.getConfiguration() ).andReturn( config ).times( 3 );
427 expect( request.getMethod() ).andReturn( "GET" ).times( 3 );
429 expect( request.getPathInfo() ).andReturn( "org/apache/archiva" ).times( 0, 2 );
431 expect( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ) ).andReturn( internalRepo );
433 expect( repoFactory.getManagedRepositoryContent( RELEASES_REPO ) ).andReturn( releasesRepo );
435 expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 2 );
437 expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 2 );
439 expect( request.getContextPath() ).andReturn( "" ).times( 2 );
441 expect( repoRequest.isSupportFile( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( false );
444 repoRequest.getLayout( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn(
447 expect( repoRequest.toItemSelector(
448 "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( null );
450 expect( repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar"
452 Paths.get( config.findManagedRepositoryById( INTERNAL_REPO ).getLocation(),
453 "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).toString());
456 expect( repoRequest.isArchetypeCatalog(
457 "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( false );
458 archivaConfigurationControl.replay();
459 requestControl.replay();
460 repoContentFactoryControl.replay();
461 repoRequestControl.replay();
463 resourceFactory.createResource( locator, request, response );
465 archivaConfigurationControl.verify();
466 requestControl.verify();
467 repoContentFactoryControl.verify();
468 repoRequestControl.verify();
470 fail( "A DavException with 401 error code should have been thrown." );
472 catch ( DavException e )
474 assertEquals( 401, e.getErrorCode() );
479 public void testRepositoryGroupArtifactDoesNotExistInAnyOfTheReposAuthenticationDisabled()
482 DavResourceLocator locator = new ArchivaDavResourceLocator( "", "/repository/" + LOCAL_REPO_GROUP
483 + "/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar", LOCAL_REPO_GROUP,
484 new ArchivaDavLocatorFactory() );
486 defaultManagedRepositoryAdmin.addManagedRepository(
487 createManagedRepository( LOCAL_MIRROR_REPO, Paths.get( "target/test-classes/local-mirror" ).toString(),
488 "default" ), false, null );
490 List<RepositoryGroupConfiguration> repoGroups = new ArrayList<>();
491 RepositoryGroupConfiguration repoGroup = new RepositoryGroupConfiguration();
492 repoGroup.setId( LOCAL_REPO_GROUP );
493 repoGroup.addRepository( INTERNAL_REPO );
494 repoGroup.addRepository( LOCAL_MIRROR_REPO );
496 repoGroups.add( repoGroup );
498 config.setRepositoryGroups( repoGroups );
500 ManagedRepositoryContent internalRepo = createManagedRepositoryContent( INTERNAL_REPO );
501 ManagedRepositoryContent localMirrorRepo = createManagedRepositoryContent( LOCAL_MIRROR_REPO );
503 repositoryRegistry.putRepositoryGroup( repoGroup );
507 archivaConfigurationControl.reset();
509 expect( archivaConfiguration.getConfiguration() ).andReturn( config ).times( 3 );
511 expect( request.getMethod() ).andReturn( "GET" ).times( 5 );
513 expect( request.getPathInfo() ).andReturn( "org/apache/archiva" ).times( 0, 2 );
515 expect( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ) ).andReturn( internalRepo );
517 expect( repoFactory.getManagedRepositoryContent( LOCAL_MIRROR_REPO ) ).andReturn( localMirrorRepo );
519 expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 4 );
521 expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 4 );
523 expect( request.getContextPath() ).andReturn( "" ).times( 2 );
525 expect( repoRequest.isSupportFile( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( false ).times( 2 );
528 repoRequest.getLayout( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn(
529 "legacy" ).times( 2 );
531 expect( repoRequest.toItemSelector(
532 "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( null ).times( 2 );
534 expect( repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar"
536 Paths.get( config.findManagedRepositoryById( INTERNAL_REPO ).getLocation(),
537 "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).toString() );
539 expect( repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar"
541 .andReturn( Paths.get( config.findManagedRepositoryById( LOCAL_MIRROR_REPO ).getLocation(),
542 "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).toString());
544 expect( repoRequest.isArchetypeCatalog( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( false ).times( 2 );
545 archivaConfigurationControl.replay();
546 requestControl.replay();
547 repoContentFactoryControl.replay();
548 repoRequestControl.replay();
550 resourceFactory.createResource( locator, request, response );
552 archivaConfigurationControl.verify();
553 requestControl.verify();
554 repoContentFactoryControl.verify();
555 repoRequestControl.verify();
557 fail( "A DavException with 404 error code should have been thrown." );
559 catch ( DavException e )
561 assertEquals( 404, e.getErrorCode() );
567 public void testRequestArtifactMetadataThreePartsRepoHasDefaultLayout()
570 // should fetch metadata
571 DavResourceLocator locator =
572 new ArchivaDavResourceLocator( "", "/repository/" + INTERNAL_REPO + "/eclipse/jdtcore/maven-metadata.xml",
573 INTERNAL_REPO, new ArchivaDavLocatorFactory() );
575 ManagedRepositoryContent internalRepo = createManagedRepositoryContent( INTERNAL_REPO );
577 // use actual object (this performs the isMetadata, isDefault and isSupportFile check!)
578 MavenRepositoryRequestInfo repoRequest = new MavenRepositoryRequestInfo(internalRepo.getRepository() );
582 archivaConfigurationControl.reset();
584 expect( request.getMethod() ).andReturn( "GET" ).times( 4 );
586 expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 3 );
588 expect( request.getContextPath() ).andReturn( "" ).times( 1 );
590 expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 2 );
592 expect( request.getRequestURI() ).andReturn( "http://localhost:8080/archiva/repository/" + INTERNAL_REPO + "/eclipse/jdtcore/maven-metadata.xml" );
593 response.setHeader( "Pragma", "no-cache" );
597 response.setHeader( "Cache-Control", "no-cache" );
601 response.setDateHeader( eq("Last-Modified"), anyLong() );
604 archivaConfigurationControl.replay();
605 repoContentFactoryControl.replay();
606 requestControl.replay();
607 responseControl.replay();
609 resourceFactory.createResource( locator, request, response );
611 archivaConfigurationControl.verify();
612 repoContentFactoryControl.verify();
613 requestControl.verify();
614 responseControl.verify();
616 catch ( DavException e )
619 fail( "A DavException should not have been thrown! "+e.getMessage() );
624 public void testRequestArtifactMetadataTwoPartsRepoHasDefaultLayout()
627 // should not fetch metadata
628 DavResourceLocator locator =
629 new ArchivaDavResourceLocator( "", "/repository/" + INTERNAL_REPO + "/eclipse/maven-metadata.xml",
630 INTERNAL_REPO, new ArchivaDavLocatorFactory() );
632 ManagedRepositoryContent internalRepo = createManagedRepositoryContent( INTERNAL_REPO );
636 archivaConfigurationControl.reset();
638 expect( archivaConfiguration.getConfiguration() ).andReturn( config ).times( 2 );
640 expect( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ) ).andReturn( internalRepo );
642 expect( request.getMethod() ).andReturn( "GET" ).times( 3 );
644 expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 3 );
646 expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 2 );
648 expect( request.getContextPath() ).andReturn( "" ).times( 2 );
650 archivaConfigurationControl.replay();
651 repoContentFactoryControl.replay();
652 requestControl.replay();
654 resourceFactory.createResource( locator, request, response );
656 archivaConfigurationControl.verify();
657 repoContentFactoryControl.verify();
658 requestControl.verify();
660 fail( "A 404 error should have been thrown!" );
662 catch ( DavException e )
664 assertEquals( 404, e.getErrorCode() );
669 public void testRequestMetadataRepoIsLegacy()
672 ManagedRepositoryContent legacyRepo = createManagedRepositoryContent( LEGACY_REPO );
673 ConfigurableListableBeanFactory beanFactory = ((ConfigurableApplicationContext) applicationContext).getBeanFactory();
674 RepositoryContentProvider provider = createRepositoryContentProvider(legacyRepo );
675 beanFactory.registerSingleton("repositoryContentProvider#legacy", provider);
676 RepositoryContentFactory repoContentFactory = applicationContext.getBean( "repositoryContentFactory#default", RepositoryContentFactory.class );
677 repoContentFactory.getRepositoryContentProviders().add(provider);
678 defaultManagedRepositoryAdmin.addManagedRepository(
679 createManagedRepository( LEGACY_REPO, getProjectBase().resolve( "target/test-classes/" + LEGACY_REPO ).toString(),
680 "legacy" ), false, null );
682 DavResourceLocator locator =
683 new ArchivaDavResourceLocator( "", "/repository/" + LEGACY_REPO + "/eclipse/maven-metadata.xml",
684 LEGACY_REPO, new ArchivaDavLocatorFactory() );
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, 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 )