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.maven.metadata.storage.ArtifactMappingProvider;
38 import org.apache.archiva.proxy.ProxyRegistry;
39 import org.apache.archiva.repository.EditableManagedRepository;
40 import org.apache.archiva.repository.BaseRepositoryContentLayout;
41 import org.apache.archiva.repository.RemoteRepository;
42 import org.apache.archiva.repository.RemoteRepositoryContent;
43 import org.apache.archiva.repository.Repository;
44 import org.apache.archiva.repository.RepositoryContent;
45 import org.apache.archiva.repository.RepositoryContentFactory;
46 import org.apache.archiva.repository.RepositoryContentProvider;
47 import org.apache.archiva.repository.RepositoryException;
48 import org.apache.archiva.repository.RepositoryRegistry;
49 import org.apache.archiva.repository.RepositoryType;
50 import org.apache.archiva.repository.maven.content.ManagedDefaultRepositoryContent;
51 import org.apache.archiva.repository.maven.content.MavenRepositoryRequestInfo;
52 import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
53 import org.apache.commons.lang3.StringUtils;
54 import org.apache.jackrabbit.webdav.DavException;
55 import org.apache.jackrabbit.webdav.DavResourceLocator;
56 import org.apache.jackrabbit.webdav.DavServletRequest;
57 import org.apache.jackrabbit.webdav.DavServletResponse;
58 import org.easymock.EasyMock;
59 import org.easymock.IMocksControl;
60 import org.junit.After;
61 import org.junit.Before;
62 import org.junit.Test;
63 import org.junit.runner.RunWith;
64 import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
65 import org.springframework.context.ApplicationContext;
66 import org.springframework.context.ConfigurableApplicationContext;
67 import org.springframework.test.context.ContextConfiguration;
69 import javax.inject.Inject;
70 import java.nio.file.Path;
71 import java.nio.file.Paths;
72 import java.util.ArrayList;
73 import java.util.HashSet;
74 import java.util.List;
75 import java.util.Locale;
77 import java.util.concurrent.atomic.AtomicReference;
79 import static org.easymock.EasyMock.*;
82 * ArchivaDavResourceFactoryTest
84 @RunWith( ArchivaSpringJUnit4ClassRunner.class )
85 @ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" } )
86 public class ArchivaDavResourceFactoryTest
89 private AtomicReference<Path> projectBase = new AtomicReference<>();
91 private static final String RELEASES_REPO = "releases";
93 private static final String INTERNAL_REPO = "internal";
95 private static final String LOCAL_MIRROR_REPO = "local-mirror";
97 private static final String LEGACY_REPO = "legacy-repo";
99 private static final String LOCAL_REPO_GROUP = "local";
101 private OverridingArchivaDavResourceFactory resourceFactory;
103 private IMocksControl requestControl;
105 private DavServletRequest request;
107 private IMocksControl repoRequestControl;
109 private MavenRepositoryRequestInfo repoRequest;
111 private IMocksControl responseControl;
113 private DavServletResponse response;
115 private IMocksControl archivaConfigurationControl;
117 private ArchivaConfiguration archivaConfiguration;
119 private Configuration config;
121 private IMocksControl repoContentFactoryControl;
123 private RepositoryContentFactory repoFactory;
126 ApplicationContext applicationContext;
129 PlexusSisuBridge plexusSisuBridge;
132 DefaultManagedRepositoryAdmin defaultManagedRepositoryAdmin;
135 RepositoryRegistry repositoryRegistry;
138 RemoteRepositoryAdmin remoteRepositoryAdmin;
141 ProxyRegistry proxyRegistry;
145 DefaultRepositoryGroupAdmin defaultRepositoryGroupAdmin;
148 List<? extends ArtifactMappingProvider> artifactMappingProviders;
151 FileLockManager fileLockManager;
156 public Path getProjectBase() {
157 if (this.projectBase.get()==null) {
158 String pathVal = System.getProperty("mvn.project.base.dir");
160 if (StringUtils.isEmpty(pathVal)) {
161 baseDir= Paths.get("").toAbsolutePath();
163 baseDir = Paths.get(pathVal).toAbsolutePath();
165 this.projectBase.compareAndSet(null, baseDir);
167 return this.projectBase.get();
177 requestControl = createControl();
178 request = requestControl.createMock( DavServletRequest.class );
180 responseControl = createControl();
181 response = responseControl.createMock( DavServletResponse.class );
182 //responseControl.setDefaultMatcher( MockControl.ALWAYS_MATCHER );
184 archivaConfigurationControl = createControl();
185 archivaConfiguration = archivaConfigurationControl.createMock( ArchivaConfiguration.class );
187 config = new Configuration();
188 expect( archivaConfiguration.getConfiguration() ).andReturn( config ).times( 2, 20 );
189 expect (archivaConfiguration.getDefaultLocale()).andReturn( Locale.getDefault() ).anyTimes();
190 archivaConfiguration.addListener( EasyMock.anyObject( ) );
191 expectLastCall().times(0, 4);
192 archivaConfiguration.save( config );
194 expectLastCall().times( 0, 5 );
195 archivaConfigurationControl.replay();
197 defaultManagedRepositoryAdmin.setArchivaConfiguration( archivaConfiguration );
198 repositoryRegistry.setArchivaConfiguration( archivaConfiguration );
199 repositoryRegistry.reload();
200 ( (DefaultRepositoryCommonValidator) defaultManagedRepositoryAdmin.getRepositoryCommonValidator() ).setArchivaConfiguration(
201 archivaConfiguration );
202 if ( defaultManagedRepositoryAdmin.getManagedRepository( RELEASES_REPO ) == null )
204 defaultManagedRepositoryAdmin.addManagedRepository(
205 createManagedRepository( RELEASES_REPO, getProjectBase().resolve( "target/test-classes/" + RELEASES_REPO ).toString(),
206 "default" ), false, null );
208 if ( defaultManagedRepositoryAdmin.getManagedRepository( INTERNAL_REPO ) == null )
210 defaultManagedRepositoryAdmin.addManagedRepository(
211 createManagedRepository( INTERNAL_REPO, getProjectBase().resolve( "target/test-classes/" + INTERNAL_REPO ).toString(),
212 "default" ), false, null );
214 RepositoryGroup repoGroupConfig = new RepositoryGroup();
215 repoGroupConfig.setId( LOCAL_REPO_GROUP );
216 repoGroupConfig.addRepository( RELEASES_REPO );
217 repoGroupConfig.addRepository( INTERNAL_REPO );
219 defaultRepositoryGroupAdmin.setArchivaConfiguration( archivaConfiguration );
220 if ( defaultManagedRepositoryAdmin.getManagedRepository( LOCAL_REPO_GROUP ) == null )
222 defaultRepositoryGroupAdmin.addRepositoryGroup( repoGroupConfig, null );
225 repoContentFactoryControl = createControl();
226 repoFactory = repoContentFactoryControl.createMock( RepositoryContentFactory.class );
228 repoRequestControl = createControl();
229 repoRequest = repoRequestControl.createMock( MavenRepositoryRequestInfo.class );
232 new OverridingArchivaDavResourceFactory( applicationContext, plexusSisuBridge, archivaConfiguration );
233 resourceFactory.setArchivaConfiguration( archivaConfiguration );
234 proxyRegistry.getAllHandler().get(RepositoryType.MAVEN).clear();
235 proxyRegistry.getAllHandler().get(RepositoryType.MAVEN).add(new OverridingRepositoryProxyHandler(this));
236 resourceFactory.setProxyRegistry(proxyRegistry);
237 resourceFactory.setRemoteRepositoryAdmin( remoteRepositoryAdmin );
238 resourceFactory.setManagedRepositoryAdmin( defaultManagedRepositoryAdmin );
239 resourceFactory.setRepositoryRegistry( repositoryRegistry );
242 private ManagedRepository createManagedRepository( String id, String location, String layout )
244 ManagedRepository repoConfig = new ManagedRepository( Locale.getDefault());
245 repoConfig.setId( id );
246 repoConfig.setName( id );
247 repoConfig.setLocation( location );
248 repoConfig.setLayout( layout );
253 private BaseRepositoryContentLayout createManagedRepositoryContent( String repoId )
254 throws RepositoryAdminException
256 org.apache.archiva.repository.ManagedRepository repo = repositoryRegistry.getManagedRepository( repoId );
257 BaseRepositoryContentLayout repoContent = new ManagedDefaultRepositoryContent(repo, artifactMappingProviders, fileTypes, fileLockManager);
258 if (repo!=null && repo instanceof EditableManagedRepository)
260 ( (EditableManagedRepository) repo ).setContent( repoContent );
265 private RepositoryContentProvider createRepositoryContentProvider( BaseRepositoryContentLayout content) {
266 Set<RepositoryType> TYPES = new HashSet<>( );
267 TYPES.add(RepositoryType.MAVEN);
268 return new RepositoryContentProvider( )
273 public boolean supportsLayout( String layout )
279 public Set<RepositoryType> getSupportedRepositoryTypes( )
285 public boolean supports( RepositoryType type )
291 public RemoteRepositoryContent createRemoteContent( RemoteRepository repository ) throws RepositoryException
297 public BaseRepositoryContentLayout createManagedContent( org.apache.archiva.repository.ManagedRepository repository ) throws RepositoryException
299 content.setRepository( repository );
304 public <T extends RepositoryContent, V extends Repository> T createContent( Class<T> clazz, V repository ) throws RepositoryException
313 public void tearDown()
317 String appserverBase = System.getProperty( "appserver.base" );
318 if ( StringUtils.isNotEmpty( appserverBase ) )
320 org.apache.archiva.common.utils.FileUtils.deleteDirectory( Paths.get( appserverBase ) );
324 // MRM-1232 - Unable to get artifacts from repositories which requires Repository Manager role using repository group
326 public void testRepositoryGroupFirstRepositoryRequiresAuthentication()
329 DavResourceLocator locator = new ArchivaDavResourceLocator( "", "/repository/" + LOCAL_REPO_GROUP
330 + "/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar", LOCAL_REPO_GROUP,
331 new ArchivaDavLocatorFactory() );
333 BaseRepositoryContentLayout internalRepo = createManagedRepositoryContent( INTERNAL_REPO );
334 BaseRepositoryContentLayout releasesRepo = createManagedRepositoryContent( RELEASES_REPO );
338 archivaConfigurationControl.reset();
340 expect( archivaConfiguration.getConfiguration() ).andReturn( config ).times( 3 );
342 expect( request.getMethod() ).andReturn( "GET" ).times( 3 );
344 expect( request.getPathInfo() ).andReturn( "org/apache/archiva" ).times( 0, 2 );
346 expect( repoFactory.getManagedRepositoryContent( RELEASES_REPO ) ).andReturn( releasesRepo );
348 expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 2 );
350 expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 2 );
352 expect( request.getContextPath() ).andReturn( "" ).times( 2 );
354 expect( repoRequest.isSupportFile( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( true );
357 repoRequest.getLayout( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn(
360 expect( repoRequest.toArtifactReference(
361 "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( null );
363 expect( repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar"
365 Paths.get( config.findManagedRepositoryById( INTERNAL_REPO ).getLocation(),
366 "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).toString());
368 expect( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ) ).andReturn( internalRepo );
370 expect( repoRequest.isArchetypeCatalog(
371 "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( false );
372 archivaConfigurationControl.replay();
373 requestControl.replay();
374 repoContentFactoryControl.replay();
375 repoRequestControl.replay();
377 resourceFactory.createResource( locator, request, response );
379 archivaConfigurationControl.verify();
380 requestControl.verify();
381 repoContentFactoryControl.verify();
382 repoRequestControl.verify();
384 fail( "A DavException with 401 error code should have been thrown." );
386 catch ( DavException e )
388 assertEquals( 401, e.getErrorCode() );
393 public void testRepositoryGroupLastRepositoryRequiresAuthentication()
396 DavResourceLocator locator = new ArchivaDavResourceLocator( "", "/repository/" + LOCAL_REPO_GROUP
397 + "/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar", LOCAL_REPO_GROUP,
398 new ArchivaDavLocatorFactory() );
400 List<RepositoryGroupConfiguration> repoGroups = new ArrayList<>();
401 RepositoryGroupConfiguration repoGroup = new RepositoryGroupConfiguration();
402 repoGroup.setId( LOCAL_REPO_GROUP );
403 repoGroup.addRepository( INTERNAL_REPO );
404 repoGroup.addRepository( RELEASES_REPO );
406 repoGroups.add( repoGroup );
408 config.setRepositoryGroups( repoGroups );
410 BaseRepositoryContentLayout internalRepo = createManagedRepositoryContent( INTERNAL_REPO );
412 BaseRepositoryContentLayout releasesRepo = createManagedRepositoryContent( RELEASES_REPO );
416 archivaConfigurationControl.reset();
418 expect( archivaConfiguration.getConfiguration() ).andReturn( config ).times( 3 );
420 expect( request.getMethod() ).andReturn( "GET" ).times( 3 );
422 expect( request.getPathInfo() ).andReturn( "org/apache/archiva" ).times( 0, 2 );
424 expect( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ) ).andReturn( internalRepo );
426 expect( repoFactory.getManagedRepositoryContent( RELEASES_REPO ) ).andReturn( releasesRepo );
428 expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 2 );
430 expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 2 );
432 expect( request.getContextPath() ).andReturn( "" ).times( 2 );
434 expect( repoRequest.isSupportFile( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( false );
437 repoRequest.getLayout( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn(
440 expect( repoRequest.toArtifactReference(
441 "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( null );
443 expect( repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar"
445 Paths.get( config.findManagedRepositoryById( INTERNAL_REPO ).getLocation(),
446 "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).toString());
449 expect( repoRequest.isArchetypeCatalog(
450 "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( false );
451 archivaConfigurationControl.replay();
452 requestControl.replay();
453 repoContentFactoryControl.replay();
454 repoRequestControl.replay();
456 resourceFactory.createResource( locator, request, response );
458 archivaConfigurationControl.verify();
459 requestControl.verify();
460 repoContentFactoryControl.verify();
461 repoRequestControl.verify();
463 fail( "A DavException with 401 error code should have been thrown." );
465 catch ( DavException e )
467 assertEquals( 401, e.getErrorCode() );
472 public void testRepositoryGroupArtifactDoesNotExistInAnyOfTheReposAuthenticationDisabled()
475 DavResourceLocator locator = new ArchivaDavResourceLocator( "", "/repository/" + LOCAL_REPO_GROUP
476 + "/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar", LOCAL_REPO_GROUP,
477 new ArchivaDavLocatorFactory() );
479 defaultManagedRepositoryAdmin.addManagedRepository(
480 createManagedRepository( LOCAL_MIRROR_REPO, Paths.get( "target/test-classes/local-mirror" ).toString(),
481 "default" ), false, null );
483 List<RepositoryGroupConfiguration> repoGroups = new ArrayList<>();
484 RepositoryGroupConfiguration repoGroup = new RepositoryGroupConfiguration();
485 repoGroup.setId( LOCAL_REPO_GROUP );
486 repoGroup.addRepository( INTERNAL_REPO );
487 repoGroup.addRepository( LOCAL_MIRROR_REPO );
489 repoGroups.add( repoGroup );
491 config.setRepositoryGroups( repoGroups );
493 BaseRepositoryContentLayout internalRepo = createManagedRepositoryContent( INTERNAL_REPO );
494 BaseRepositoryContentLayout localMirrorRepo = createManagedRepositoryContent( LOCAL_MIRROR_REPO );
496 repositoryRegistry.putRepositoryGroup( repoGroup );
500 archivaConfigurationControl.reset();
502 expect( archivaConfiguration.getConfiguration() ).andReturn( config ).times( 3 );
504 expect( request.getMethod() ).andReturn( "GET" ).times( 5 );
506 expect( request.getPathInfo() ).andReturn( "org/apache/archiva" ).times( 0, 2 );
508 expect( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ) ).andReturn( internalRepo );
510 expect( repoFactory.getManagedRepositoryContent( LOCAL_MIRROR_REPO ) ).andReturn( localMirrorRepo );
512 expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 4 );
514 expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 4 );
516 expect( request.getContextPath() ).andReturn( "" ).times( 2 );
518 expect( repoRequest.isSupportFile( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( false ).times( 2 );
521 repoRequest.getLayout( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn(
522 "legacy" ).times( 2 );
524 expect( repoRequest.toArtifactReference(
525 "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( null ).times( 2 );
527 expect( repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar"
529 Paths.get( config.findManagedRepositoryById( INTERNAL_REPO ).getLocation(),
530 "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).toString() );
532 expect( repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar"
534 .andReturn( Paths.get( config.findManagedRepositoryById( LOCAL_MIRROR_REPO ).getLocation(),
535 "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).toString());
537 expect( repoRequest.isArchetypeCatalog( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( false ).times( 2 );
538 archivaConfigurationControl.replay();
539 requestControl.replay();
540 repoContentFactoryControl.replay();
541 repoRequestControl.replay();
543 resourceFactory.createResource( locator, request, response );
545 archivaConfigurationControl.verify();
546 requestControl.verify();
547 repoContentFactoryControl.verify();
548 repoRequestControl.verify();
550 fail( "A DavException with 404 error code should have been thrown." );
552 catch ( DavException e )
554 assertEquals( 404, e.getErrorCode() );
560 public void testRequestArtifactMetadataThreePartsRepoHasDefaultLayout()
563 // should fetch metadata
564 DavResourceLocator locator =
565 new ArchivaDavResourceLocator( "", "/repository/" + INTERNAL_REPO + "/eclipse/jdtcore/maven-metadata.xml",
566 INTERNAL_REPO, new ArchivaDavLocatorFactory() );
568 BaseRepositoryContentLayout internalRepo = createManagedRepositoryContent( INTERNAL_REPO );
570 // use actual object (this performs the isMetadata, isDefault and isSupportFile check!)
571 MavenRepositoryRequestInfo repoRequest = new MavenRepositoryRequestInfo(internalRepo.getRepository() );
575 archivaConfigurationControl.reset();
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 BaseRepositoryContentLayout internalRepo = createManagedRepositoryContent( INTERNAL_REPO );
629 archivaConfigurationControl.reset();
631 expect( archivaConfiguration.getConfiguration() ).andReturn( config ).times( 2 );
633 expect( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ) ).andReturn( internalRepo );
635 expect( request.getMethod() ).andReturn( "GET" ).times( 3 );
637 expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 3 );
639 expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 2 );
641 expect( request.getContextPath() ).andReturn( "" ).times( 2 );
643 archivaConfigurationControl.replay();
644 repoContentFactoryControl.replay();
645 requestControl.replay();
647 resourceFactory.createResource( locator, request, response );
649 archivaConfigurationControl.verify();
650 repoContentFactoryControl.verify();
651 requestControl.verify();
653 fail( "A 404 error should have been thrown!" );
655 catch ( DavException e )
657 assertEquals( 404, e.getErrorCode() );
662 public void testRequestMetadataRepoIsLegacy()
665 BaseRepositoryContentLayout legacyRepo = createManagedRepositoryContent( LEGACY_REPO );
666 ConfigurableListableBeanFactory beanFactory = ((ConfigurableApplicationContext) applicationContext).getBeanFactory();
667 RepositoryContentProvider provider = createRepositoryContentProvider(legacyRepo );
668 beanFactory.registerSingleton("repositoryContentProvider#legacy", provider);
669 RepositoryContentFactory repoContentFactory = applicationContext.getBean( "repositoryContentFactory#default", RepositoryContentFactory.class );
670 repoContentFactory.getRepositoryContentProviders().add(provider);
671 defaultManagedRepositoryAdmin.addManagedRepository(
672 createManagedRepository( LEGACY_REPO, getProjectBase().resolve( "target/test-classes/" + LEGACY_REPO ).toString(),
673 "legacy" ), false, null );
675 DavResourceLocator locator =
676 new ArchivaDavResourceLocator( "", "/repository/" + LEGACY_REPO + "/eclipse/maven-metadata.xml",
677 LEGACY_REPO, new ArchivaDavLocatorFactory() );
682 archivaConfigurationControl.reset();
684 expect( archivaConfiguration.getConfiguration() ).andReturn( config ).times( 2 );
686 expect( repoFactory.getManagedRepositoryContent( LEGACY_REPO ) ).andReturn( legacyRepo );
688 expect( request.getMethod() ).andReturn( "GET" ).times( 3 );
690 expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 3 );
692 expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 2 );
694 expect( request.getContextPath() ).andReturn( "" ).times( 2 );
696 archivaConfigurationControl.replay();
697 repoContentFactoryControl.replay();
698 requestControl.replay();
700 resourceFactory.createResource( locator, request, response );
702 archivaConfigurationControl.verify();
703 repoContentFactoryControl.verify();
704 requestControl.verify();
706 fail( "A 404 error should have been thrown!" );
708 catch ( DavException e )
710 assertEquals( 404, e.getErrorCode() );
714 class OverridingArchivaDavResourceFactory
715 extends ArchivaDavResourceFactory
718 OverridingArchivaDavResourceFactory( ApplicationContext applicationContext, PlexusSisuBridge plexusSisuBridge,
719 ArchivaConfiguration archivaConfiguration )
720 throws PlexusSisuBridgeException
722 super( applicationContext, archivaConfiguration );
726 protected boolean isAuthorized( DavServletRequest request, String repositoryId )
729 if ( RELEASES_REPO.equals( repositoryId ) )
731 throw new UnauthorizedDavException( repositoryId,
732 "You are not authenticated and authorized to access any repository." );
741 protected String getActivePrincipal( DavServletRequest request )