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.metadata.storage.ArtifactMappingProvider;
39 import org.apache.archiva.proxy.ProxyRegistry;
40 import org.apache.archiva.repository.EditableManagedRepository;
41 import org.apache.archiva.repository.BaseRepositoryContentLayout;
42 import org.apache.archiva.repository.RemoteRepository;
43 import org.apache.archiva.repository.RemoteRepositoryContent;
44 import org.apache.archiva.repository.Repository;
45 import org.apache.archiva.repository.RepositoryContent;
46 import org.apache.archiva.repository.RepositoryContentFactory;
47 import org.apache.archiva.repository.RepositoryContentProvider;
48 import org.apache.archiva.repository.RepositoryException;
49 import org.apache.archiva.repository.RepositoryRegistry;
50 import org.apache.archiva.repository.RepositoryType;
51 import org.apache.archiva.repository.maven.content.ManagedDefaultRepositoryContent;
52 import org.apache.archiva.repository.maven.content.MavenRepositoryRequestInfo;
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 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 PlexusSisuBridge plexusSisuBridge;
133 DefaultManagedRepositoryAdmin defaultManagedRepositoryAdmin;
136 RepositoryRegistry repositoryRegistry;
139 RemoteRepositoryAdmin remoteRepositoryAdmin;
142 ProxyRegistry proxyRegistry;
146 DefaultRepositoryGroupAdmin defaultRepositoryGroupAdmin;
149 List<? extends ArtifactMappingProvider> artifactMappingProviders;
152 FileLockManager fileLockManager;
157 public Path getProjectBase() {
158 if (this.projectBase.get()==null) {
159 String pathVal = System.getProperty("mvn.project.base.dir");
161 if (StringUtils.isEmpty(pathVal)) {
162 baseDir= Paths.get("").toAbsolutePath();
164 baseDir = Paths.get(pathVal).toAbsolutePath();
166 this.projectBase.compareAndSet(null, baseDir);
168 return this.projectBase.get();
178 requestControl = createControl();
179 request = requestControl.createMock( DavServletRequest.class );
181 responseControl = createControl();
182 response = responseControl.createMock( DavServletResponse.class );
183 //responseControl.setDefaultMatcher( MockControl.ALWAYS_MATCHER );
185 archivaConfigurationControl = createControl();
186 archivaConfiguration = archivaConfigurationControl.createMock( ArchivaConfiguration.class );
188 config = new Configuration();
189 expect( archivaConfiguration.getConfiguration() ).andReturn( config ).times( 2, 20 );
190 expect (archivaConfiguration.getDefaultLocale()).andReturn( Locale.getDefault() ).anyTimes();
191 archivaConfiguration.addListener( EasyMock.anyObject( ) );
192 expectLastCall().times(0, 4);
193 archivaConfiguration.save( config );
195 expectLastCall().times( 0, 5 );
196 archivaConfigurationControl.replay();
198 defaultManagedRepositoryAdmin.setArchivaConfiguration( archivaConfiguration );
199 repositoryRegistry.setArchivaConfiguration( archivaConfiguration );
200 repositoryRegistry.reload();
201 ( (DefaultRepositoryCommonValidator) defaultManagedRepositoryAdmin.getRepositoryCommonValidator() ).setArchivaConfiguration(
202 archivaConfiguration );
203 if ( defaultManagedRepositoryAdmin.getManagedRepository( RELEASES_REPO ) == null )
205 defaultManagedRepositoryAdmin.addManagedRepository(
206 createManagedRepository( RELEASES_REPO, getProjectBase().resolve( "target/test-classes/" + RELEASES_REPO ).toString(),
207 "default" ), false, null );
209 if ( defaultManagedRepositoryAdmin.getManagedRepository( INTERNAL_REPO ) == null )
211 defaultManagedRepositoryAdmin.addManagedRepository(
212 createManagedRepository( INTERNAL_REPO, getProjectBase().resolve( "target/test-classes/" + INTERNAL_REPO ).toString(),
213 "default" ), false, null );
215 RepositoryGroup repoGroupConfig = new RepositoryGroup();
216 repoGroupConfig.setId( LOCAL_REPO_GROUP );
217 repoGroupConfig.addRepository( RELEASES_REPO );
218 repoGroupConfig.addRepository( INTERNAL_REPO );
220 defaultRepositoryGroupAdmin.setArchivaConfiguration( archivaConfiguration );
221 if ( defaultManagedRepositoryAdmin.getManagedRepository( LOCAL_REPO_GROUP ) == null )
223 defaultRepositoryGroupAdmin.addRepositoryGroup( repoGroupConfig, null );
226 repoContentFactoryControl = createControl();
227 repoFactory = repoContentFactoryControl.createMock( RepositoryContentFactory.class );
229 repoRequestControl = createControl();
230 repoRequest = repoRequestControl.createMock( MavenRepositoryRequestInfo.class );
233 new OverridingArchivaDavResourceFactory( applicationContext, plexusSisuBridge, archivaConfiguration );
234 resourceFactory.setArchivaConfiguration( archivaConfiguration );
235 proxyRegistry.getAllHandler().get(RepositoryType.MAVEN).clear();
236 proxyRegistry.getAllHandler().get(RepositoryType.MAVEN).add(new OverridingRepositoryProxyHandler(this));
237 resourceFactory.setProxyRegistry(proxyRegistry);
238 resourceFactory.setRemoteRepositoryAdmin( remoteRepositoryAdmin );
239 resourceFactory.setManagedRepositoryAdmin( defaultManagedRepositoryAdmin );
240 resourceFactory.setRepositoryRegistry( repositoryRegistry );
243 private ManagedRepository createManagedRepository( String id, String location, String layout )
245 ManagedRepository repoConfig = new ManagedRepository( Locale.getDefault());
246 repoConfig.setId( id );
247 repoConfig.setName( id );
248 repoConfig.setLocation( location );
249 repoConfig.setLayout( layout );
254 private ManagedRepositoryContent createManagedRepositoryContent( String repoId )
255 throws RepositoryAdminException
257 org.apache.archiva.repository.ManagedRepository repo = repositoryRegistry.getManagedRepository( repoId );
258 ManagedRepositoryContent repoContent = new ManagedDefaultRepositoryContent(repo, artifactMappingProviders, fileTypes, fileLockManager);
259 if (repo!=null && repo instanceof EditableManagedRepository)
261 ( (EditableManagedRepository) repo ).setContent( repoContent );
266 private RepositoryContentProvider createRepositoryContentProvider( ManagedRepositoryContent content) {
267 Set<RepositoryType> TYPES = new HashSet<>( );
268 TYPES.add(RepositoryType.MAVEN);
269 return new RepositoryContentProvider( )
274 public boolean supportsLayout( String layout )
280 public Set<RepositoryType> getSupportedRepositoryTypes( )
286 public boolean supports( RepositoryType type )
292 public RemoteRepositoryContent createRemoteContent( RemoteRepository repository ) throws RepositoryException
298 public ManagedRepositoryContent createManagedContent( org.apache.archiva.repository.ManagedRepository repository ) throws RepositoryException
300 content.setRepository( repository );
305 public <T extends RepositoryContent, V extends Repository> T createContent( Class<T> clazz, V repository ) throws RepositoryException
314 public void tearDown()
318 String appserverBase = System.getProperty( "appserver.base" );
319 if ( StringUtils.isNotEmpty( appserverBase ) )
321 org.apache.archiva.common.utils.FileUtils.deleteDirectory( Paths.get( appserverBase ) );
325 // MRM-1232 - Unable to get artifacts from repositories which requires Repository Manager role using repository group
327 public void testRepositoryGroupFirstRepositoryRequiresAuthentication()
330 DavResourceLocator locator = new ArchivaDavResourceLocator( "", "/repository/" + LOCAL_REPO_GROUP
331 + "/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar", LOCAL_REPO_GROUP,
332 new ArchivaDavLocatorFactory() );
334 ManagedRepositoryContent internalRepo = createManagedRepositoryContent( INTERNAL_REPO );
335 ManagedRepositoryContent releasesRepo = createManagedRepositoryContent( RELEASES_REPO );
339 archivaConfigurationControl.reset();
341 expect( archivaConfiguration.getConfiguration() ).andReturn( config ).times( 3 );
343 expect( request.getMethod() ).andReturn( "GET" ).times( 3 );
345 expect( request.getPathInfo() ).andReturn( "org/apache/archiva" ).times( 0, 2 );
347 expect( repoFactory.getManagedRepositoryContent( RELEASES_REPO ) ).andReturn( releasesRepo );
349 expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 2 );
351 expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 2 );
353 expect( request.getContextPath() ).andReturn( "" ).times( 2 );
355 expect( repoRequest.isSupportFile( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( true );
358 repoRequest.getLayout( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn(
361 expect( repoRequest.toArtifactReference(
362 "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( null );
364 expect( repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar"
366 Paths.get( config.findManagedRepositoryById( INTERNAL_REPO ).getLocation(),
367 "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).toString());
369 expect( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ) ).andReturn( internalRepo );
371 expect( repoRequest.isArchetypeCatalog(
372 "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( false );
373 archivaConfigurationControl.replay();
374 requestControl.replay();
375 repoContentFactoryControl.replay();
376 repoRequestControl.replay();
378 resourceFactory.createResource( locator, request, response );
380 archivaConfigurationControl.verify();
381 requestControl.verify();
382 repoContentFactoryControl.verify();
383 repoRequestControl.verify();
385 fail( "A DavException with 401 error code should have been thrown." );
387 catch ( DavException e )
389 assertEquals( 401, e.getErrorCode() );
394 public void testRepositoryGroupLastRepositoryRequiresAuthentication()
397 DavResourceLocator locator = new ArchivaDavResourceLocator( "", "/repository/" + LOCAL_REPO_GROUP
398 + "/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar", LOCAL_REPO_GROUP,
399 new ArchivaDavLocatorFactory() );
401 List<RepositoryGroupConfiguration> repoGroups = new ArrayList<>();
402 RepositoryGroupConfiguration repoGroup = new RepositoryGroupConfiguration();
403 repoGroup.setId( LOCAL_REPO_GROUP );
404 repoGroup.addRepository( INTERNAL_REPO );
405 repoGroup.addRepository( RELEASES_REPO );
407 repoGroups.add( repoGroup );
409 config.setRepositoryGroups( repoGroups );
411 ManagedRepositoryContent internalRepo = createManagedRepositoryContent( INTERNAL_REPO );
413 ManagedRepositoryContent releasesRepo = createManagedRepositoryContent( RELEASES_REPO );
417 archivaConfigurationControl.reset();
419 expect( archivaConfiguration.getConfiguration() ).andReturn( config ).times( 3 );
421 expect( request.getMethod() ).andReturn( "GET" ).times( 3 );
423 expect( request.getPathInfo() ).andReturn( "org/apache/archiva" ).times( 0, 2 );
425 expect( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ) ).andReturn( internalRepo );
427 expect( repoFactory.getManagedRepositoryContent( RELEASES_REPO ) ).andReturn( releasesRepo );
429 expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 2 );
431 expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 2 );
433 expect( request.getContextPath() ).andReturn( "" ).times( 2 );
435 expect( repoRequest.isSupportFile( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( false );
438 repoRequest.getLayout( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn(
441 expect( repoRequest.toArtifactReference(
442 "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( null );
444 expect( repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar"
446 Paths.get( config.findManagedRepositoryById( INTERNAL_REPO ).getLocation(),
447 "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).toString());
450 expect( repoRequest.isArchetypeCatalog(
451 "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( false );
452 archivaConfigurationControl.replay();
453 requestControl.replay();
454 repoContentFactoryControl.replay();
455 repoRequestControl.replay();
457 resourceFactory.createResource( locator, request, response );
459 archivaConfigurationControl.verify();
460 requestControl.verify();
461 repoContentFactoryControl.verify();
462 repoRequestControl.verify();
464 fail( "A DavException with 401 error code should have been thrown." );
466 catch ( DavException e )
468 assertEquals( 401, e.getErrorCode() );
473 public void testRepositoryGroupArtifactDoesNotExistInAnyOfTheReposAuthenticationDisabled()
476 DavResourceLocator locator = new ArchivaDavResourceLocator( "", "/repository/" + LOCAL_REPO_GROUP
477 + "/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar", LOCAL_REPO_GROUP,
478 new ArchivaDavLocatorFactory() );
480 defaultManagedRepositoryAdmin.addManagedRepository(
481 createManagedRepository( LOCAL_MIRROR_REPO, Paths.get( "target/test-classes/local-mirror" ).toString(),
482 "default" ), false, null );
484 List<RepositoryGroupConfiguration> repoGroups = new ArrayList<>();
485 RepositoryGroupConfiguration repoGroup = new RepositoryGroupConfiguration();
486 repoGroup.setId( LOCAL_REPO_GROUP );
487 repoGroup.addRepository( INTERNAL_REPO );
488 repoGroup.addRepository( LOCAL_MIRROR_REPO );
490 repoGroups.add( repoGroup );
492 config.setRepositoryGroups( repoGroups );
494 ManagedRepositoryContent internalRepo = createManagedRepositoryContent( INTERNAL_REPO );
495 ManagedRepositoryContent localMirrorRepo = createManagedRepositoryContent( LOCAL_MIRROR_REPO );
497 repositoryRegistry.putRepositoryGroup( repoGroup );
501 archivaConfigurationControl.reset();
503 expect( archivaConfiguration.getConfiguration() ).andReturn( config ).times( 3 );
505 expect( request.getMethod() ).andReturn( "GET" ).times( 5 );
507 expect( request.getPathInfo() ).andReturn( "org/apache/archiva" ).times( 0, 2 );
509 expect( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ) ).andReturn( internalRepo );
511 expect( repoFactory.getManagedRepositoryContent( LOCAL_MIRROR_REPO ) ).andReturn( localMirrorRepo );
513 expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 4 );
515 expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 4 );
517 expect( request.getContextPath() ).andReturn( "" ).times( 2 );
519 expect( repoRequest.isSupportFile( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( false ).times( 2 );
522 repoRequest.getLayout( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn(
523 "legacy" ).times( 2 );
525 expect( repoRequest.toArtifactReference(
526 "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( null ).times( 2 );
528 expect( repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar"
530 Paths.get( config.findManagedRepositoryById( INTERNAL_REPO ).getLocation(),
531 "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).toString() );
533 expect( repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar"
535 .andReturn( Paths.get( config.findManagedRepositoryById( LOCAL_MIRROR_REPO ).getLocation(),
536 "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).toString());
538 expect( repoRequest.isArchetypeCatalog( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( false ).times( 2 );
539 archivaConfigurationControl.replay();
540 requestControl.replay();
541 repoContentFactoryControl.replay();
542 repoRequestControl.replay();
544 resourceFactory.createResource( locator, request, response );
546 archivaConfigurationControl.verify();
547 requestControl.verify();
548 repoContentFactoryControl.verify();
549 repoRequestControl.verify();
551 fail( "A DavException with 404 error code should have been thrown." );
553 catch ( DavException e )
555 assertEquals( 404, e.getErrorCode() );
561 public void testRequestArtifactMetadataThreePartsRepoHasDefaultLayout()
564 // should fetch metadata
565 DavResourceLocator locator =
566 new ArchivaDavResourceLocator( "", "/repository/" + INTERNAL_REPO + "/eclipse/jdtcore/maven-metadata.xml",
567 INTERNAL_REPO, new ArchivaDavLocatorFactory() );
569 ManagedRepositoryContent internalRepo = createManagedRepositoryContent( INTERNAL_REPO );
571 // use actual object (this performs the isMetadata, isDefault and isSupportFile check!)
572 MavenRepositoryRequestInfo repoRequest = new MavenRepositoryRequestInfo(internalRepo.getRepository() );
576 archivaConfigurationControl.reset();
578 expect( request.getMethod() ).andReturn( "GET" ).times( 4 );
580 expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 3 );
582 expect( request.getContextPath() ).andReturn( "" ).times( 1 );
584 expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 2 );
586 expect( request.getRequestURI() ).andReturn( "http://localhost:8080/archiva/repository/" + INTERNAL_REPO + "/eclipse/jdtcore/maven-metadata.xml" );
587 response.setHeader( "Pragma", "no-cache" );
591 response.setHeader( "Cache-Control", "no-cache" );
595 response.setDateHeader( eq("Last-Modified"), anyLong() );
598 archivaConfigurationControl.replay();
599 repoContentFactoryControl.replay();
600 requestControl.replay();
601 responseControl.replay();
603 resourceFactory.createResource( locator, request, response );
605 archivaConfigurationControl.verify();
606 repoContentFactoryControl.verify();
607 requestControl.verify();
608 responseControl.verify();
610 catch ( DavException e )
613 fail( "A DavException should not have been thrown! "+e.getMessage() );
618 public void testRequestArtifactMetadataTwoPartsRepoHasDefaultLayout()
621 // should not fetch metadata
622 DavResourceLocator locator =
623 new ArchivaDavResourceLocator( "", "/repository/" + INTERNAL_REPO + "/eclipse/maven-metadata.xml",
624 INTERNAL_REPO, new ArchivaDavLocatorFactory() );
626 ManagedRepositoryContent internalRepo = createManagedRepositoryContent( INTERNAL_REPO );
630 archivaConfigurationControl.reset();
632 expect( archivaConfiguration.getConfiguration() ).andReturn( config ).times( 2 );
634 expect( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ) ).andReturn( internalRepo );
636 expect( request.getMethod() ).andReturn( "GET" ).times( 3 );
638 expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 3 );
640 expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 2 );
642 expect( request.getContextPath() ).andReturn( "" ).times( 2 );
644 archivaConfigurationControl.replay();
645 repoContentFactoryControl.replay();
646 requestControl.replay();
648 resourceFactory.createResource( locator, request, response );
650 archivaConfigurationControl.verify();
651 repoContentFactoryControl.verify();
652 requestControl.verify();
654 fail( "A 404 error should have been thrown!" );
656 catch ( DavException e )
658 assertEquals( 404, e.getErrorCode() );
663 public void testRequestMetadataRepoIsLegacy()
666 ManagedRepositoryContent legacyRepo = createManagedRepositoryContent( LEGACY_REPO );
667 ConfigurableListableBeanFactory beanFactory = ((ConfigurableApplicationContext) applicationContext).getBeanFactory();
668 RepositoryContentProvider provider = createRepositoryContentProvider(legacyRepo );
669 beanFactory.registerSingleton("repositoryContentProvider#legacy", provider);
670 RepositoryContentFactory repoContentFactory = applicationContext.getBean( "repositoryContentFactory#default", RepositoryContentFactory.class );
671 repoContentFactory.getRepositoryContentProviders().add(provider);
672 defaultManagedRepositoryAdmin.addManagedRepository(
673 createManagedRepository( LEGACY_REPO, getProjectBase().resolve( "target/test-classes/" + LEGACY_REPO ).toString(),
674 "legacy" ), false, null );
676 DavResourceLocator locator =
677 new ArchivaDavResourceLocator( "", "/repository/" + LEGACY_REPO + "/eclipse/maven-metadata.xml",
678 LEGACY_REPO, new ArchivaDavLocatorFactory() );
683 archivaConfigurationControl.reset();
685 expect( archivaConfiguration.getConfiguration() ).andReturn( config ).times( 2 );
687 expect( repoFactory.getManagedRepositoryContent( LEGACY_REPO ) ).andReturn( legacyRepo );
689 expect( request.getMethod() ).andReturn( "GET" ).times( 3 );
691 expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 3 );
693 expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 2 );
695 expect( request.getContextPath() ).andReturn( "" ).times( 2 );
697 archivaConfigurationControl.replay();
698 repoContentFactoryControl.replay();
699 requestControl.replay();
701 resourceFactory.createResource( locator, request, response );
703 archivaConfigurationControl.verify();
704 repoContentFactoryControl.verify();
705 requestControl.verify();
707 fail( "A 404 error should have been thrown!" );
709 catch ( DavException e )
711 assertEquals( 404, e.getErrorCode() );
715 class OverridingArchivaDavResourceFactory
716 extends ArchivaDavResourceFactory
719 OverridingArchivaDavResourceFactory( ApplicationContext applicationContext, PlexusSisuBridge plexusSisuBridge,
720 ArchivaConfiguration archivaConfiguration )
721 throws PlexusSisuBridgeException
723 super( applicationContext, archivaConfiguration );
727 protected boolean isAuthorized( DavServletRequest request, String repositoryId )
730 if ( RELEASES_REPO.equals( repositoryId ) )
732 throw new UnauthorizedDavException( repositoryId,
733 "You are not authenticated and authorized to access any repository." );
742 protected String getActivePrincipal( DavServletRequest request )