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.configuration.ArchivaConfiguration;
32 import org.apache.archiva.configuration.Configuration;
33 import org.apache.archiva.configuration.FileTypes;
34 import org.apache.archiva.configuration.RepositoryGroupConfiguration;
35 import org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator;
36 import org.apache.archiva.proxy.ProxyRegistry;
37 import org.apache.archiva.repository.EditableManagedRepository;
38 import org.apache.archiva.repository.ManagedRepositoryContent;
39 import org.apache.archiva.repository.RemoteRepository;
40 import org.apache.archiva.repository.RemoteRepositoryContent;
41 import org.apache.archiva.repository.Repository;
42 import org.apache.archiva.repository.RepositoryContent;
43 import org.apache.archiva.repository.RepositoryContentFactory;
44 import org.apache.archiva.repository.RepositoryContentProvider;
45 import org.apache.archiva.repository.RepositoryException;
46 import org.apache.archiva.repository.RepositoryRegistry;
47 import org.apache.archiva.repository.RepositoryType;
48 import org.apache.archiva.repository.base.RepositoryHandlerDependencies;
49 import org.apache.archiva.maven.repository.content.ManagedDefaultRepositoryContent;
50 import org.apache.archiva.maven.repository.content.MavenContentHelper;
51 import org.apache.archiva.maven.repository.content.MavenRepositoryRequestInfo;
52 import org.apache.archiva.maven.repository.metadata.storage.ArtifactMappingProvider;
53 import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
54 import org.apache.commons.lang3.StringUtils;
55 import org.apache.jackrabbit.webdav.DavException;
56 import org.apache.jackrabbit.webdav.DavResourceLocator;
57 import org.apache.jackrabbit.webdav.DavServletRequest;
58 import org.apache.jackrabbit.webdav.DavServletResponse;
59 import org.easymock.EasyMock;
60 import org.easymock.IMocksControl;
61 import org.junit.After;
62 import org.junit.Before;
63 import org.junit.Test;
64 import org.junit.runner.RunWith;
65 import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
66 import org.springframework.context.ApplicationContext;
67 import org.springframework.context.ConfigurableApplicationContext;
68 import org.springframework.test.context.ContextConfiguration;
70 import javax.inject.Inject;
71 import javax.inject.Named;
72 import java.nio.file.Path;
73 import java.nio.file.Paths;
74 import java.util.ArrayList;
75 import java.util.HashSet;
76 import java.util.List;
77 import java.util.Locale;
79 import java.util.concurrent.atomic.AtomicReference;
81 import static org.easymock.EasyMock.*;
84 * ArchivaDavResourceFactoryTest
86 @RunWith( ArchivaSpringJUnit4ClassRunner.class )
87 @ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" } )
88 public class ArchivaDavResourceFactoryTest
91 private AtomicReference<Path> projectBase = new AtomicReference<>();
93 private static final String RELEASES_REPO = "releases";
95 private static final String INTERNAL_REPO = "internal";
97 private static final String LOCAL_MIRROR_REPO = "local-mirror";
99 private static final String LEGACY_REPO = "legacy-repo";
101 private static final String LOCAL_REPO_GROUP = "local";
103 private OverridingArchivaDavResourceFactory resourceFactory;
105 private IMocksControl requestControl;
107 private DavServletRequest request;
109 private IMocksControl repoRequestControl;
111 private MavenRepositoryRequestInfo repoRequest;
113 private IMocksControl responseControl;
115 private DavServletResponse response;
117 private IMocksControl archivaConfigurationControl;
119 private ArchivaConfiguration archivaConfiguration;
121 private Configuration config;
123 private IMocksControl repoContentFactoryControl;
125 private RepositoryContentFactory repoFactory;
128 ApplicationContext applicationContext;
131 DefaultManagedRepositoryAdmin defaultManagedRepositoryAdmin;
134 RepositoryRegistry repositoryRegistry;
137 RemoteRepositoryAdmin remoteRepositoryAdmin;
140 ProxyRegistry proxyRegistry;
143 @Named( "MavenContentHelper" )
144 MavenContentHelper mavenContentHelper;
147 DefaultRepositoryGroupAdmin defaultRepositoryGroupAdmin;
150 List<? extends ArtifactMappingProvider> artifactMappingProviders;
153 @Named( "repositoryPathTranslator#maven2" )
154 RepositoryPathTranslator pathTranslator;
157 FileLockManager fileLockManager;
162 @SuppressWarnings( "unused" )
164 RepositoryHandlerDependencies repositoryHandlerDependencies;
166 public Path getProjectBase() {
167 if (this.projectBase.get()==null) {
168 String pathVal = System.getProperty("mvn.project.base.dir");
170 if (StringUtils.isEmpty(pathVal)) {
171 baseDir= Paths.get("").toAbsolutePath();
173 baseDir = Paths.get(pathVal).toAbsolutePath();
175 this.projectBase.compareAndSet(null, baseDir);
177 return this.projectBase.get();
187 requestControl = createControl();
188 request = requestControl.createMock( DavServletRequest.class );
190 responseControl = createControl();
191 response = responseControl.createMock( DavServletResponse.class );
192 //responseControl.setDefaultMatcher( MockControl.ALWAYS_MATCHER );
194 archivaConfigurationControl = createControl();
195 archivaConfiguration = archivaConfigurationControl.createMock( ArchivaConfiguration.class );
197 config = new Configuration();
198 expect( archivaConfiguration.getConfiguration() ).andReturn( config ).times( 2, 25 );
199 expect (archivaConfiguration.getDefaultLocale()).andReturn( Locale.getDefault() ).anyTimes();
200 archivaConfiguration.addListener( EasyMock.anyObject( ) );
201 expectLastCall().times(0, 4);
202 archivaConfiguration.save( eq(config));
203 expectLastCall().times( 0, 5 );
204 archivaConfiguration.save( eq(config), EasyMock.anyString());
205 expectLastCall().times( 0, 5 );
206 archivaConfigurationControl.replay();
208 defaultManagedRepositoryAdmin.setArchivaConfiguration( archivaConfiguration );
209 repositoryRegistry.setArchivaConfiguration( archivaConfiguration );
210 repositoryRegistry.reload();
211 ( (DefaultRepositoryCommonValidator) defaultManagedRepositoryAdmin.getRepositoryCommonValidator() ).setArchivaConfiguration(
212 archivaConfiguration );
213 if ( defaultManagedRepositoryAdmin.getManagedRepository( RELEASES_REPO ) == null )
215 defaultManagedRepositoryAdmin.addManagedRepository(
216 createManagedRepository( RELEASES_REPO, getProjectBase().resolve( "target/test-classes/" + RELEASES_REPO ).toString(),
217 "default" ), false, null );
219 if ( defaultManagedRepositoryAdmin.getManagedRepository( INTERNAL_REPO ) == null )
221 defaultManagedRepositoryAdmin.addManagedRepository(
222 createManagedRepository( INTERNAL_REPO, getProjectBase().resolve( "target/test-classes/" + INTERNAL_REPO ).toString(),
223 "default" ), false, null );
225 RepositoryGroup repoGroupConfig = new RepositoryGroup();
226 repoGroupConfig.setId( LOCAL_REPO_GROUP );
227 repoGroupConfig.addRepository( RELEASES_REPO );
228 repoGroupConfig.addRepository( INTERNAL_REPO );
230 defaultRepositoryGroupAdmin.setArchivaConfiguration( archivaConfiguration );
231 if ( defaultManagedRepositoryAdmin.getManagedRepository( LOCAL_REPO_GROUP ) == null )
233 defaultRepositoryGroupAdmin.addRepositoryGroup( repoGroupConfig, null );
236 repoContentFactoryControl = createControl();
237 repoFactory = repoContentFactoryControl.createMock( RepositoryContentFactory.class );
239 repoRequestControl = createControl();
240 repoRequest = repoRequestControl.createMock( MavenRepositoryRequestInfo.class );
243 new OverridingArchivaDavResourceFactory( applicationContext, archivaConfiguration );
244 resourceFactory.setArchivaConfiguration( archivaConfiguration );
245 proxyRegistry.getAllHandler().get(RepositoryType.MAVEN).clear();
246 proxyRegistry.getAllHandler().get(RepositoryType.MAVEN).add(new OverridingRepositoryProxyHandler(this));
247 resourceFactory.setProxyRegistry(proxyRegistry);
248 resourceFactory.setRemoteRepositoryAdmin( remoteRepositoryAdmin );
249 resourceFactory.setManagedRepositoryAdmin( defaultManagedRepositoryAdmin );
250 resourceFactory.setRepositoryRegistry( repositoryRegistry );
253 private ManagedRepository createManagedRepository( String id, String location, String layout )
255 ManagedRepository repoConfig = new ManagedRepository( Locale.getDefault());
256 repoConfig.setId( id );
257 repoConfig.setName( id );
258 repoConfig.setLocation( location );
259 repoConfig.setLayout( layout );
264 private ManagedRepositoryContent createManagedRepositoryContent( String repoId )
265 throws RepositoryAdminException
267 org.apache.archiva.repository.ManagedRepository repo = repositoryRegistry.getManagedRepository( repoId );
268 ManagedDefaultRepositoryContent repoContent = new ManagedDefaultRepositoryContent(repo, fileTypes, fileLockManager);
269 if (repo!=null && repo instanceof EditableManagedRepository)
271 ( (EditableManagedRepository) repo ).setContent( repoContent );
273 repoContent.setMavenContentHelper( mavenContentHelper );
274 repoContent.setArtifactMappingProviders( artifactMappingProviders );
275 repoContent.setPathTranslator( pathTranslator );
279 private RepositoryContentProvider createRepositoryContentProvider( ManagedRepositoryContent content) {
280 Set<RepositoryType> TYPES = new HashSet<>( );
281 TYPES.add(RepositoryType.MAVEN);
282 return new RepositoryContentProvider( )
287 public boolean supportsLayout( String layout )
293 public Set<RepositoryType> getSupportedRepositoryTypes( )
299 public boolean supports( RepositoryType type )
305 public RemoteRepositoryContent createRemoteContent( RemoteRepository repository ) throws RepositoryException
311 public ManagedRepositoryContent createManagedContent( org.apache.archiva.repository.ManagedRepository repository ) throws RepositoryException
313 content.setRepository( repository );
318 public <T extends RepositoryContent, V extends Repository> T createContent( Class<T> clazz, V repository ) throws RepositoryException
327 public void tearDown()
331 String appserverBase = System.getProperty( "appserver.base" );
332 if ( StringUtils.isNotEmpty( appserverBase ) )
334 org.apache.archiva.common.utils.FileUtils.deleteDirectory( Paths.get( appserverBase ) );
338 // MRM-1232 - Unable to get artifacts from repositories which requires Repository Manager role using repository group
340 public void testRepositoryGroupFirstRepositoryRequiresAuthentication()
343 DavResourceLocator locator = new ArchivaDavResourceLocator( "", "/repository/" + LOCAL_REPO_GROUP
344 + "/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar", LOCAL_REPO_GROUP,
345 new ArchivaDavLocatorFactory() );
347 ManagedRepositoryContent internalRepo = createManagedRepositoryContent( INTERNAL_REPO );
348 ManagedRepositoryContent releasesRepo = createManagedRepositoryContent( RELEASES_REPO );
352 archivaConfigurationControl.reset();
354 expect( archivaConfiguration.getConfiguration() ).andReturn( config ).times( 3 );
356 expect( request.getMethod() ).andReturn( "GET" ).times( 3 );
358 expect( request.getPathInfo() ).andReturn( "org/apache/archiva" ).times( 0, 2 );
360 expect( repoFactory.getManagedRepositoryContent( RELEASES_REPO ) ).andReturn( releasesRepo );
362 expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 2 );
364 expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 2 );
366 expect( request.getContextPath() ).andReturn( "" ).times( 2 );
368 expect( repoRequest.isSupportFile( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( true );
371 repoRequest.getLayout( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn(
374 expect( repoRequest.toItemSelector(
375 "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( null );
377 expect( repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar"
379 Paths.get( config.findManagedRepositoryById( INTERNAL_REPO ).getLocation(),
380 "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).toString());
382 expect( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ) ).andReturn( internalRepo );
384 expect( repoRequest.isArchetypeCatalog(
385 "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( false );
386 archivaConfigurationControl.replay();
387 requestControl.replay();
388 repoContentFactoryControl.replay();
389 repoRequestControl.replay();
391 resourceFactory.createResource( locator, request, response );
393 archivaConfigurationControl.verify();
394 requestControl.verify();
395 repoContentFactoryControl.verify();
396 repoRequestControl.verify();
398 fail( "A DavException with 401 error code should have been thrown." );
400 catch ( DavException e )
402 assertEquals( 401, e.getErrorCode() );
407 public void testRepositoryGroupLastRepositoryRequiresAuthentication()
410 DavResourceLocator locator = new ArchivaDavResourceLocator( "", "/repository/" + LOCAL_REPO_GROUP
411 + "/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar", LOCAL_REPO_GROUP,
412 new ArchivaDavLocatorFactory() );
414 List<RepositoryGroupConfiguration> repoGroups = new ArrayList<>();
415 RepositoryGroupConfiguration repoGroup = new RepositoryGroupConfiguration();
416 repoGroup.setId( LOCAL_REPO_GROUP );
417 repoGroup.addRepository( INTERNAL_REPO );
418 repoGroup.addRepository( RELEASES_REPO );
420 repoGroups.add( repoGroup );
422 config.setRepositoryGroups( repoGroups );
424 ManagedRepositoryContent internalRepo = createManagedRepositoryContent( INTERNAL_REPO );
426 ManagedRepositoryContent releasesRepo = createManagedRepositoryContent( RELEASES_REPO );
430 archivaConfigurationControl.reset();
432 expect( archivaConfiguration.getConfiguration() ).andReturn( config ).times( 3 );
434 expect( request.getMethod() ).andReturn( "GET" ).times( 3 );
436 expect( request.getPathInfo() ).andReturn( "org/apache/archiva" ).times( 0, 2 );
438 expect( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ) ).andReturn( internalRepo );
440 expect( repoFactory.getManagedRepositoryContent( RELEASES_REPO ) ).andReturn( releasesRepo );
442 expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 2 );
444 expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 2 );
446 expect( request.getContextPath() ).andReturn( "" ).times( 2 );
448 expect( repoRequest.isSupportFile( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( false );
451 repoRequest.getLayout( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn(
454 expect( repoRequest.toItemSelector(
455 "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( null );
457 expect( repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar"
459 Paths.get( config.findManagedRepositoryById( INTERNAL_REPO ).getLocation(),
460 "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).toString());
463 expect( repoRequest.isArchetypeCatalog(
464 "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( false );
465 archivaConfigurationControl.replay();
466 requestControl.replay();
467 repoContentFactoryControl.replay();
468 repoRequestControl.replay();
470 resourceFactory.createResource( locator, request, response );
472 archivaConfigurationControl.verify();
473 requestControl.verify();
474 repoContentFactoryControl.verify();
475 repoRequestControl.verify();
477 fail( "A DavException with 401 error code should have been thrown." );
479 catch ( DavException e )
481 assertEquals( 401, e.getErrorCode() );
486 public void testRepositoryGroupArtifactDoesNotExistInAnyOfTheReposAuthenticationDisabled()
489 DavResourceLocator locator = new ArchivaDavResourceLocator( "", "/repository/" + LOCAL_REPO_GROUP
490 + "/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar", LOCAL_REPO_GROUP,
491 new ArchivaDavLocatorFactory() );
493 defaultManagedRepositoryAdmin.addManagedRepository(
494 createManagedRepository( LOCAL_MIRROR_REPO, Paths.get( "target/test-classes/local-mirror" ).toString(),
495 "default" ), false, null );
497 List<RepositoryGroupConfiguration> repoGroups = new ArrayList<>();
498 RepositoryGroupConfiguration repoGroup = new RepositoryGroupConfiguration();
499 repoGroup.setId( LOCAL_REPO_GROUP );
500 repoGroup.addRepository( INTERNAL_REPO );
501 repoGroup.addRepository( LOCAL_MIRROR_REPO );
503 repoGroups.add( repoGroup );
505 config.setRepositoryGroups( repoGroups );
507 ManagedRepositoryContent internalRepo = createManagedRepositoryContent( INTERNAL_REPO );
508 ManagedRepositoryContent localMirrorRepo = createManagedRepositoryContent( LOCAL_MIRROR_REPO );
510 repositoryRegistry.putRepositoryGroup( repoGroup );
514 archivaConfigurationControl.reset();
516 expect( archivaConfiguration.getConfiguration() ).andReturn( config ).times( 3 );
518 expect( request.getMethod() ).andReturn( "GET" ).times( 5 );
520 expect( request.getPathInfo() ).andReturn( "org/apache/archiva" ).times( 0, 2 );
522 expect( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ) ).andReturn( internalRepo );
524 expect( repoFactory.getManagedRepositoryContent( LOCAL_MIRROR_REPO ) ).andReturn( localMirrorRepo );
526 expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 4 );
528 expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 4 );
530 expect( request.getContextPath() ).andReturn( "" ).times( 2 );
532 expect( repoRequest.isSupportFile( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( false ).times( 2 );
535 repoRequest.getLayout( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn(
536 "legacy" ).times( 2 );
538 expect( repoRequest.toItemSelector(
539 "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( null ).times( 2 );
541 expect( repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar"
543 Paths.get( config.findManagedRepositoryById( INTERNAL_REPO ).getLocation(),
544 "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).toString() );
546 expect( repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar"
548 .andReturn( Paths.get( config.findManagedRepositoryById( LOCAL_MIRROR_REPO ).getLocation(),
549 "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).toString());
551 expect( repoRequest.isArchetypeCatalog( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( false ).times( 2 );
552 archivaConfigurationControl.replay();
553 requestControl.replay();
554 repoContentFactoryControl.replay();
555 repoRequestControl.replay();
557 resourceFactory.createResource( locator, request, response );
559 archivaConfigurationControl.verify();
560 requestControl.verify();
561 repoContentFactoryControl.verify();
562 repoRequestControl.verify();
564 fail( "A DavException with 404 error code should have been thrown." );
566 catch ( DavException e )
568 assertEquals( 404, e.getErrorCode() );
574 public void testRequestArtifactMetadataThreePartsRepoHasDefaultLayout()
577 // should fetch metadata
578 DavResourceLocator locator =
579 new ArchivaDavResourceLocator( "", "/repository/" + INTERNAL_REPO + "/eclipse/jdtcore/maven-metadata.xml",
580 INTERNAL_REPO, new ArchivaDavLocatorFactory() );
582 ManagedRepositoryContent internalRepo = createManagedRepositoryContent( INTERNAL_REPO );
584 // use actual object (this performs the isMetadata, isDefault and isSupportFile check!)
585 MavenRepositoryRequestInfo repoRequest = new MavenRepositoryRequestInfo(internalRepo.getRepository() );
589 archivaConfigurationControl.reset();
591 expect( request.getMethod() ).andReturn( "GET" ).times( 4 );
593 expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 3 );
595 expect( request.getContextPath() ).andReturn( "" ).times( 1 );
597 expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 2 );
599 expect( request.getRequestURI() ).andReturn( "http://localhost:8080/archiva/repository/" + INTERNAL_REPO + "/eclipse/jdtcore/maven-metadata.xml" );
600 response.setHeader( "Pragma", "no-cache" );
604 response.setHeader( "Cache-Control", "no-cache" );
608 response.setDateHeader( eq("Last-Modified"), anyLong() );
611 archivaConfigurationControl.replay();
612 repoContentFactoryControl.replay();
613 requestControl.replay();
614 responseControl.replay();
616 resourceFactory.createResource( locator, request, response );
618 archivaConfigurationControl.verify();
619 repoContentFactoryControl.verify();
620 requestControl.verify();
621 responseControl.verify();
623 catch ( DavException e )
626 fail( "A DavException should not have been thrown! "+e.getMessage() );
631 public void testRequestArtifactMetadataTwoPartsRepoHasDefaultLayout()
634 // should not fetch metadata
635 DavResourceLocator locator =
636 new ArchivaDavResourceLocator( "", "/repository/" + INTERNAL_REPO + "/eclipse/maven-metadata.xml",
637 INTERNAL_REPO, new ArchivaDavLocatorFactory() );
639 ManagedRepositoryContent internalRepo = createManagedRepositoryContent( INTERNAL_REPO );
643 archivaConfigurationControl.reset();
645 expect( archivaConfiguration.getConfiguration() ).andReturn( config ).times( 2 );
647 expect( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ) ).andReturn( internalRepo );
649 expect( request.getMethod() ).andReturn( "GET" ).times( 3 );
651 expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 3 );
653 expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 2 );
655 expect( request.getContextPath() ).andReturn( "" ).times( 2 );
657 archivaConfigurationControl.replay();
658 repoContentFactoryControl.replay();
659 requestControl.replay();
661 resourceFactory.createResource( locator, request, response );
663 archivaConfigurationControl.verify();
664 repoContentFactoryControl.verify();
665 requestControl.verify();
667 fail( "A 404 error should have been thrown!" );
669 catch ( DavException e )
671 assertEquals( 404, e.getErrorCode() );
676 public void testRequestMetadataRepoIsLegacy()
679 ManagedRepositoryContent legacyRepo = createManagedRepositoryContent( LEGACY_REPO );
680 ConfigurableListableBeanFactory beanFactory = ((ConfigurableApplicationContext) applicationContext).getBeanFactory();
681 RepositoryContentProvider provider = createRepositoryContentProvider(legacyRepo );
682 beanFactory.registerSingleton("repositoryContentProvider#legacy", provider);
683 RepositoryContentFactory repoContentFactory = applicationContext.getBean( "repositoryContentFactory#default", RepositoryContentFactory.class );
684 repoContentFactory.getRepositoryContentProviders().add(provider);
685 defaultManagedRepositoryAdmin.addManagedRepository(
686 createManagedRepository( LEGACY_REPO, getProjectBase().resolve( "target/test-classes/" + LEGACY_REPO ).toString(),
687 "legacy" ), false, null );
689 DavResourceLocator locator =
690 new ArchivaDavResourceLocator( "", "/repository/" + LEGACY_REPO + "/eclipse/maven-metadata.xml",
691 LEGACY_REPO, new ArchivaDavLocatorFactory() );
696 archivaConfigurationControl.reset();
698 expect( archivaConfiguration.getConfiguration() ).andReturn( config ).times( 2 );
700 expect( repoFactory.getManagedRepositoryContent( LEGACY_REPO ) ).andReturn( legacyRepo );
702 expect( request.getMethod() ).andReturn( "GET" ).times( 3 );
704 expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 3 );
706 expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 2 );
708 expect( request.getContextPath() ).andReturn( "" ).times( 2 );
710 archivaConfigurationControl.replay();
711 repoContentFactoryControl.replay();
712 requestControl.replay();
714 resourceFactory.createResource( locator, request, response );
716 archivaConfigurationControl.verify();
717 repoContentFactoryControl.verify();
718 requestControl.verify();
720 fail( "A 404 error should have been thrown!" );
722 catch ( DavException e )
724 assertEquals( 404, e.getErrorCode() );
728 class OverridingArchivaDavResourceFactory
729 extends ArchivaDavResourceFactory
732 OverridingArchivaDavResourceFactory( ApplicationContext applicationContext,
733 ArchivaConfiguration archivaConfiguration )
735 super( applicationContext, archivaConfiguration );
739 protected boolean isAuthorized( DavServletRequest request, String repositoryId )
742 if ( RELEASES_REPO.equals( repositoryId ) )
744 throw new UnauthorizedDavException( repositoryId,
745 "You are not authenticated and authorized to access any repository." );
754 protected String getActivePrincipal( DavServletRequest request )