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.repository.ManagedRepositoryContent;
37 import org.apache.archiva.repository.maven.content.MavenContentHelper;
38 import org.apache.archiva.repository.maven.metadata.storage.ArtifactMappingProvider;
39 import org.apache.archiva.proxy.ProxyRegistry;
40 import org.apache.archiva.repository.EditableManagedRepository;
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 javax.inject.Named;
71 import java.nio.file.Path;
72 import java.nio.file.Paths;
73 import java.util.ArrayList;
74 import java.util.HashSet;
75 import java.util.List;
76 import java.util.Locale;
78 import java.util.concurrent.atomic.AtomicReference;
80 import static org.easymock.EasyMock.*;
83 * ArchivaDavResourceFactoryTest
85 @RunWith( ArchivaSpringJUnit4ClassRunner.class )
86 @ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" } )
87 public class ArchivaDavResourceFactoryTest
90 private AtomicReference<Path> projectBase = new AtomicReference<>();
92 private static final String RELEASES_REPO = "releases";
94 private static final String INTERNAL_REPO = "internal";
96 private static final String LOCAL_MIRROR_REPO = "local-mirror";
98 private static final String LEGACY_REPO = "legacy-repo";
100 private static final String LOCAL_REPO_GROUP = "local";
102 private OverridingArchivaDavResourceFactory resourceFactory;
104 private IMocksControl requestControl;
106 private DavServletRequest request;
108 private IMocksControl repoRequestControl;
110 private MavenRepositoryRequestInfo repoRequest;
112 private IMocksControl responseControl;
114 private DavServletResponse response;
116 private IMocksControl archivaConfigurationControl;
118 private ArchivaConfiguration archivaConfiguration;
120 private Configuration config;
122 private IMocksControl repoContentFactoryControl;
124 private RepositoryContentFactory repoFactory;
127 ApplicationContext applicationContext;
130 DefaultManagedRepositoryAdmin defaultManagedRepositoryAdmin;
133 RepositoryRegistry repositoryRegistry;
136 RemoteRepositoryAdmin remoteRepositoryAdmin;
139 ProxyRegistry proxyRegistry;
142 @Named( "MavenContentHelper" )
143 MavenContentHelper mavenContentHelper;
146 DefaultRepositoryGroupAdmin defaultRepositoryGroupAdmin;
149 List<? extends ArtifactMappingProvider> artifactMappingProviders;
152 @Named( "repositoryPathTranslator#maven2" )
153 RepositoryPathTranslator pathTranslator;
156 FileLockManager fileLockManager;
161 public Path getProjectBase() {
162 if (this.projectBase.get()==null) {
163 String pathVal = System.getProperty("mvn.project.base.dir");
165 if (StringUtils.isEmpty(pathVal)) {
166 baseDir= Paths.get("").toAbsolutePath();
168 baseDir = Paths.get(pathVal).toAbsolutePath();
170 this.projectBase.compareAndSet(null, baseDir);
172 return this.projectBase.get();
182 requestControl = createControl();
183 request = requestControl.createMock( DavServletRequest.class );
185 responseControl = createControl();
186 response = responseControl.createMock( DavServletResponse.class );
187 //responseControl.setDefaultMatcher( MockControl.ALWAYS_MATCHER );
189 archivaConfigurationControl = createControl();
190 archivaConfiguration = archivaConfigurationControl.createMock( ArchivaConfiguration.class );
192 config = new Configuration();
193 expect( archivaConfiguration.getConfiguration() ).andReturn( config ).times( 2, 20 );
194 expect (archivaConfiguration.getDefaultLocale()).andReturn( Locale.getDefault() ).anyTimes();
195 archivaConfiguration.addListener( EasyMock.anyObject( ) );
196 expectLastCall().times(0, 4);
197 archivaConfiguration.save( config );
199 expectLastCall().times( 0, 5 );
200 archivaConfigurationControl.replay();
202 defaultManagedRepositoryAdmin.setArchivaConfiguration( archivaConfiguration );
203 repositoryRegistry.setArchivaConfiguration( archivaConfiguration );
204 repositoryRegistry.reload();
205 ( (DefaultRepositoryCommonValidator) defaultManagedRepositoryAdmin.getRepositoryCommonValidator() ).setArchivaConfiguration(
206 archivaConfiguration );
207 if ( defaultManagedRepositoryAdmin.getManagedRepository( RELEASES_REPO ) == null )
209 defaultManagedRepositoryAdmin.addManagedRepository(
210 createManagedRepository( RELEASES_REPO, getProjectBase().resolve( "target/test-classes/" + RELEASES_REPO ).toString(),
211 "default" ), false, null );
213 if ( defaultManagedRepositoryAdmin.getManagedRepository( INTERNAL_REPO ) == null )
215 defaultManagedRepositoryAdmin.addManagedRepository(
216 createManagedRepository( INTERNAL_REPO, getProjectBase().resolve( "target/test-classes/" + INTERNAL_REPO ).toString(),
217 "default" ), false, null );
219 RepositoryGroup repoGroupConfig = new RepositoryGroup();
220 repoGroupConfig.setId( LOCAL_REPO_GROUP );
221 repoGroupConfig.addRepository( RELEASES_REPO );
222 repoGroupConfig.addRepository( INTERNAL_REPO );
224 defaultRepositoryGroupAdmin.setArchivaConfiguration( archivaConfiguration );
225 if ( defaultManagedRepositoryAdmin.getManagedRepository( LOCAL_REPO_GROUP ) == null )
227 defaultRepositoryGroupAdmin.addRepositoryGroup( repoGroupConfig, null );
230 repoContentFactoryControl = createControl();
231 repoFactory = repoContentFactoryControl.createMock( RepositoryContentFactory.class );
233 repoRequestControl = createControl();
234 repoRequest = repoRequestControl.createMock( MavenRepositoryRequestInfo.class );
237 new OverridingArchivaDavResourceFactory( applicationContext, archivaConfiguration );
238 resourceFactory.setArchivaConfiguration( archivaConfiguration );
239 proxyRegistry.getAllHandler().get(RepositoryType.MAVEN).clear();
240 proxyRegistry.getAllHandler().get(RepositoryType.MAVEN).add(new OverridingRepositoryProxyHandler(this));
241 resourceFactory.setProxyRegistry(proxyRegistry);
242 resourceFactory.setRemoteRepositoryAdmin( remoteRepositoryAdmin );
243 resourceFactory.setManagedRepositoryAdmin( defaultManagedRepositoryAdmin );
244 resourceFactory.setRepositoryRegistry( repositoryRegistry );
247 private ManagedRepository createManagedRepository( String id, String location, String layout )
249 ManagedRepository repoConfig = new ManagedRepository( Locale.getDefault());
250 repoConfig.setId( id );
251 repoConfig.setName( id );
252 repoConfig.setLocation( location );
253 repoConfig.setLayout( layout );
258 private ManagedRepositoryContent createManagedRepositoryContent( String repoId )
259 throws RepositoryAdminException
261 org.apache.archiva.repository.ManagedRepository repo = repositoryRegistry.getManagedRepository( repoId );
262 ManagedDefaultRepositoryContent repoContent = new ManagedDefaultRepositoryContent(repo, fileTypes, fileLockManager);
263 if (repo!=null && repo instanceof EditableManagedRepository)
265 ( (EditableManagedRepository) repo ).setContent( repoContent );
267 repoContent.setMavenContentHelper( mavenContentHelper );
268 repoContent.setArtifactMappingProviders( artifactMappingProviders );
269 repoContent.setPathTranslator( pathTranslator );
273 private RepositoryContentProvider createRepositoryContentProvider( ManagedRepositoryContent content) {
274 Set<RepositoryType> TYPES = new HashSet<>( );
275 TYPES.add(RepositoryType.MAVEN);
276 return new RepositoryContentProvider( )
281 public boolean supportsLayout( String layout )
287 public Set<RepositoryType> getSupportedRepositoryTypes( )
293 public boolean supports( RepositoryType type )
299 public RemoteRepositoryContent createRemoteContent( RemoteRepository repository ) throws RepositoryException
305 public ManagedRepositoryContent createManagedContent( org.apache.archiva.repository.ManagedRepository repository ) throws RepositoryException
307 content.setRepository( repository );
312 public <T extends RepositoryContent, V extends Repository> T createContent( Class<T> clazz, V repository ) throws RepositoryException
321 public void tearDown()
325 String appserverBase = System.getProperty( "appserver.base" );
326 if ( StringUtils.isNotEmpty( appserverBase ) )
328 org.apache.archiva.common.utils.FileUtils.deleteDirectory( Paths.get( appserverBase ) );
332 // MRM-1232 - Unable to get artifacts from repositories which requires Repository Manager role using repository group
334 public void testRepositoryGroupFirstRepositoryRequiresAuthentication()
337 DavResourceLocator locator = new ArchivaDavResourceLocator( "", "/repository/" + LOCAL_REPO_GROUP
338 + "/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar", LOCAL_REPO_GROUP,
339 new ArchivaDavLocatorFactory() );
341 ManagedRepositoryContent internalRepo = createManagedRepositoryContent( INTERNAL_REPO );
342 ManagedRepositoryContent releasesRepo = createManagedRepositoryContent( RELEASES_REPO );
346 archivaConfigurationControl.reset();
348 expect( archivaConfiguration.getConfiguration() ).andReturn( config ).times( 3 );
350 expect( request.getMethod() ).andReturn( "GET" ).times( 3 );
352 expect( request.getPathInfo() ).andReturn( "org/apache/archiva" ).times( 0, 2 );
354 expect( repoFactory.getManagedRepositoryContent( RELEASES_REPO ) ).andReturn( releasesRepo );
356 expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 2 );
358 expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 2 );
360 expect( request.getContextPath() ).andReturn( "" ).times( 2 );
362 expect( repoRequest.isSupportFile( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( true );
365 repoRequest.getLayout( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn(
368 expect( repoRequest.toItemSelector(
369 "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( null );
371 expect( repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar"
373 Paths.get( config.findManagedRepositoryById( INTERNAL_REPO ).getLocation(),
374 "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).toString());
376 expect( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ) ).andReturn( internalRepo );
378 expect( repoRequest.isArchetypeCatalog(
379 "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( false );
380 archivaConfigurationControl.replay();
381 requestControl.replay();
382 repoContentFactoryControl.replay();
383 repoRequestControl.replay();
385 resourceFactory.createResource( locator, request, response );
387 archivaConfigurationControl.verify();
388 requestControl.verify();
389 repoContentFactoryControl.verify();
390 repoRequestControl.verify();
392 fail( "A DavException with 401 error code should have been thrown." );
394 catch ( DavException e )
396 assertEquals( 401, e.getErrorCode() );
401 public void testRepositoryGroupLastRepositoryRequiresAuthentication()
404 DavResourceLocator locator = new ArchivaDavResourceLocator( "", "/repository/" + LOCAL_REPO_GROUP
405 + "/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar", LOCAL_REPO_GROUP,
406 new ArchivaDavLocatorFactory() );
408 List<RepositoryGroupConfiguration> repoGroups = new ArrayList<>();
409 RepositoryGroupConfiguration repoGroup = new RepositoryGroupConfiguration();
410 repoGroup.setId( LOCAL_REPO_GROUP );
411 repoGroup.addRepository( INTERNAL_REPO );
412 repoGroup.addRepository( RELEASES_REPO );
414 repoGroups.add( repoGroup );
416 config.setRepositoryGroups( repoGroups );
418 ManagedRepositoryContent internalRepo = createManagedRepositoryContent( INTERNAL_REPO );
420 ManagedRepositoryContent releasesRepo = createManagedRepositoryContent( RELEASES_REPO );
424 archivaConfigurationControl.reset();
426 expect( archivaConfiguration.getConfiguration() ).andReturn( config ).times( 3 );
428 expect( request.getMethod() ).andReturn( "GET" ).times( 3 );
430 expect( request.getPathInfo() ).andReturn( "org/apache/archiva" ).times( 0, 2 );
432 expect( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ) ).andReturn( internalRepo );
434 expect( repoFactory.getManagedRepositoryContent( RELEASES_REPO ) ).andReturn( releasesRepo );
436 expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 2 );
438 expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 2 );
440 expect( request.getContextPath() ).andReturn( "" ).times( 2 );
442 expect( repoRequest.isSupportFile( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( false );
445 repoRequest.getLayout( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn(
448 expect( repoRequest.toItemSelector(
449 "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( null );
451 expect( repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar"
453 Paths.get( config.findManagedRepositoryById( INTERNAL_REPO ).getLocation(),
454 "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).toString());
457 expect( repoRequest.isArchetypeCatalog(
458 "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( false );
459 archivaConfigurationControl.replay();
460 requestControl.replay();
461 repoContentFactoryControl.replay();
462 repoRequestControl.replay();
464 resourceFactory.createResource( locator, request, response );
466 archivaConfigurationControl.verify();
467 requestControl.verify();
468 repoContentFactoryControl.verify();
469 repoRequestControl.verify();
471 fail( "A DavException with 401 error code should have been thrown." );
473 catch ( DavException e )
475 assertEquals( 401, e.getErrorCode() );
480 public void testRepositoryGroupArtifactDoesNotExistInAnyOfTheReposAuthenticationDisabled()
483 DavResourceLocator locator = new ArchivaDavResourceLocator( "", "/repository/" + LOCAL_REPO_GROUP
484 + "/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar", LOCAL_REPO_GROUP,
485 new ArchivaDavLocatorFactory() );
487 defaultManagedRepositoryAdmin.addManagedRepository(
488 createManagedRepository( LOCAL_MIRROR_REPO, Paths.get( "target/test-classes/local-mirror" ).toString(),
489 "default" ), false, null );
491 List<RepositoryGroupConfiguration> repoGroups = new ArrayList<>();
492 RepositoryGroupConfiguration repoGroup = new RepositoryGroupConfiguration();
493 repoGroup.setId( LOCAL_REPO_GROUP );
494 repoGroup.addRepository( INTERNAL_REPO );
495 repoGroup.addRepository( LOCAL_MIRROR_REPO );
497 repoGroups.add( repoGroup );
499 config.setRepositoryGroups( repoGroups );
501 ManagedRepositoryContent internalRepo = createManagedRepositoryContent( INTERNAL_REPO );
502 ManagedRepositoryContent localMirrorRepo = createManagedRepositoryContent( LOCAL_MIRROR_REPO );
504 repositoryRegistry.putRepositoryGroup( repoGroup );
508 archivaConfigurationControl.reset();
510 expect( archivaConfiguration.getConfiguration() ).andReturn( config ).times( 3 );
512 expect( request.getMethod() ).andReturn( "GET" ).times( 5 );
514 expect( request.getPathInfo() ).andReturn( "org/apache/archiva" ).times( 0, 2 );
516 expect( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ) ).andReturn( internalRepo );
518 expect( repoFactory.getManagedRepositoryContent( LOCAL_MIRROR_REPO ) ).andReturn( localMirrorRepo );
520 expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 4 );
522 expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 4 );
524 expect( request.getContextPath() ).andReturn( "" ).times( 2 );
526 expect( repoRequest.isSupportFile( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( false ).times( 2 );
529 repoRequest.getLayout( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn(
530 "legacy" ).times( 2 );
532 expect( repoRequest.toItemSelector(
533 "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( null ).times( 2 );
535 expect( repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar"
537 Paths.get( config.findManagedRepositoryById( INTERNAL_REPO ).getLocation(),
538 "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).toString() );
540 expect( repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar"
542 .andReturn( Paths.get( config.findManagedRepositoryById( LOCAL_MIRROR_REPO ).getLocation(),
543 "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).toString());
545 expect( repoRequest.isArchetypeCatalog( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( false ).times( 2 );
546 archivaConfigurationControl.replay();
547 requestControl.replay();
548 repoContentFactoryControl.replay();
549 repoRequestControl.replay();
551 resourceFactory.createResource( locator, request, response );
553 archivaConfigurationControl.verify();
554 requestControl.verify();
555 repoContentFactoryControl.verify();
556 repoRequestControl.verify();
558 fail( "A DavException with 404 error code should have been thrown." );
560 catch ( DavException e )
562 assertEquals( 404, e.getErrorCode() );
568 public void testRequestArtifactMetadataThreePartsRepoHasDefaultLayout()
571 // should fetch metadata
572 DavResourceLocator locator =
573 new ArchivaDavResourceLocator( "", "/repository/" + INTERNAL_REPO + "/eclipse/jdtcore/maven-metadata.xml",
574 INTERNAL_REPO, new ArchivaDavLocatorFactory() );
576 ManagedRepositoryContent internalRepo = createManagedRepositoryContent( INTERNAL_REPO );
578 // use actual object (this performs the isMetadata, isDefault and isSupportFile check!)
579 MavenRepositoryRequestInfo repoRequest = new MavenRepositoryRequestInfo(internalRepo.getRepository() );
583 archivaConfigurationControl.reset();
585 expect( request.getMethod() ).andReturn( "GET" ).times( 4 );
587 expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 3 );
589 expect( request.getContextPath() ).andReturn( "" ).times( 1 );
591 expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 2 );
593 expect( request.getRequestURI() ).andReturn( "http://localhost:8080/archiva/repository/" + INTERNAL_REPO + "/eclipse/jdtcore/maven-metadata.xml" );
594 response.setHeader( "Pragma", "no-cache" );
598 response.setHeader( "Cache-Control", "no-cache" );
602 response.setDateHeader( eq("Last-Modified"), anyLong() );
605 archivaConfigurationControl.replay();
606 repoContentFactoryControl.replay();
607 requestControl.replay();
608 responseControl.replay();
610 resourceFactory.createResource( locator, request, response );
612 archivaConfigurationControl.verify();
613 repoContentFactoryControl.verify();
614 requestControl.verify();
615 responseControl.verify();
617 catch ( DavException e )
620 fail( "A DavException should not have been thrown! "+e.getMessage() );
625 public void testRequestArtifactMetadataTwoPartsRepoHasDefaultLayout()
628 // should not fetch metadata
629 DavResourceLocator locator =
630 new ArchivaDavResourceLocator( "", "/repository/" + INTERNAL_REPO + "/eclipse/maven-metadata.xml",
631 INTERNAL_REPO, new ArchivaDavLocatorFactory() );
633 ManagedRepositoryContent internalRepo = createManagedRepositoryContent( INTERNAL_REPO );
637 archivaConfigurationControl.reset();
639 expect( archivaConfiguration.getConfiguration() ).andReturn( config ).times( 2 );
641 expect( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ) ).andReturn( internalRepo );
643 expect( request.getMethod() ).andReturn( "GET" ).times( 3 );
645 expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 3 );
647 expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 2 );
649 expect( request.getContextPath() ).andReturn( "" ).times( 2 );
651 archivaConfigurationControl.replay();
652 repoContentFactoryControl.replay();
653 requestControl.replay();
655 resourceFactory.createResource( locator, request, response );
657 archivaConfigurationControl.verify();
658 repoContentFactoryControl.verify();
659 requestControl.verify();
661 fail( "A 404 error should have been thrown!" );
663 catch ( DavException e )
665 assertEquals( 404, e.getErrorCode() );
670 public void testRequestMetadataRepoIsLegacy()
673 ManagedRepositoryContent legacyRepo = createManagedRepositoryContent( LEGACY_REPO );
674 ConfigurableListableBeanFactory beanFactory = ((ConfigurableApplicationContext) applicationContext).getBeanFactory();
675 RepositoryContentProvider provider = createRepositoryContentProvider(legacyRepo );
676 beanFactory.registerSingleton("repositoryContentProvider#legacy", provider);
677 RepositoryContentFactory repoContentFactory = applicationContext.getBean( "repositoryContentFactory#default", RepositoryContentFactory.class );
678 repoContentFactory.getRepositoryContentProviders().add(provider);
679 defaultManagedRepositoryAdmin.addManagedRepository(
680 createManagedRepository( LEGACY_REPO, getProjectBase().resolve( "target/test-classes/" + LEGACY_REPO ).toString(),
681 "legacy" ), false, null );
683 DavResourceLocator locator =
684 new ArchivaDavResourceLocator( "", "/repository/" + LEGACY_REPO + "/eclipse/maven-metadata.xml",
685 LEGACY_REPO, new ArchivaDavLocatorFactory() );
690 archivaConfigurationControl.reset();
692 expect( archivaConfiguration.getConfiguration() ).andReturn( config ).times( 2 );
694 expect( repoFactory.getManagedRepositoryContent( LEGACY_REPO ) ).andReturn( legacyRepo );
696 expect( request.getMethod() ).andReturn( "GET" ).times( 3 );
698 expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 3 );
700 expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 2 );
702 expect( request.getContextPath() ).andReturn( "" ).times( 2 );
704 archivaConfigurationControl.replay();
705 repoContentFactoryControl.replay();
706 requestControl.replay();
708 resourceFactory.createResource( locator, request, response );
710 archivaConfigurationControl.verify();
711 repoContentFactoryControl.verify();
712 requestControl.verify();
714 fail( "A 404 error should have been thrown!" );
716 catch ( DavException e )
718 assertEquals( 404, e.getErrorCode() );
722 class OverridingArchivaDavResourceFactory
723 extends ArchivaDavResourceFactory
726 OverridingArchivaDavResourceFactory( ApplicationContext applicationContext,
727 ArchivaConfiguration archivaConfiguration )
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 )