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.plexusbridge.PlexusSisuBridge;
31 import org.apache.archiva.common.plexusbridge.PlexusSisuBridgeException;
32 import org.apache.archiva.configuration.ArchivaConfiguration;
33 import org.apache.archiva.configuration.Configuration;
34 import org.apache.archiva.configuration.RepositoryGroupConfiguration;
35 import org.apache.archiva.proxy.DefaultRepositoryProxyConnectors;
36 import org.apache.archiva.proxy.model.ProxyFetchResult;
37 import org.apache.archiva.repository.EditableManagedRepository;
38 import org.apache.archiva.repository.ManagedRepositoryContent;
39 import org.apache.archiva.repository.RepositoryContentFactory;
40 import org.apache.archiva.repository.RepositoryRegistry;
41 import org.apache.archiva.repository.content.maven2.ManagedDefaultRepositoryContent;
42 import org.apache.archiva.repository.content.maven2.RepositoryRequest;
43 import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
44 import org.apache.commons.io.FileUtils;
45 import org.apache.jackrabbit.webdav.DavException;
46 import org.apache.jackrabbit.webdav.DavResourceLocator;
47 import org.apache.jackrabbit.webdav.DavServletRequest;
48 import org.apache.jackrabbit.webdav.DavServletResponse;
49 import org.easymock.EasyMock;
50 import org.easymock.IMocksControl;
51 import org.junit.After;
52 import org.junit.Before;
53 import org.junit.Test;
54 import org.junit.runner.RunWith;
55 import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
56 import org.springframework.context.ApplicationContext;
57 import org.springframework.context.ConfigurableApplicationContext;
58 import org.springframework.test.context.ContextConfiguration;
60 import javax.inject.Inject;
61 import java.io.IOException;
62 import java.nio.file.Path;
63 import java.nio.file.Paths;
64 import java.util.ArrayList;
65 import java.util.List;
66 import java.util.Locale;
68 import static org.easymock.EasyMock.*;
71 * ArchivaDavResourceFactoryTest
73 @RunWith( ArchivaSpringJUnit4ClassRunner.class )
74 @ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" } )
75 public class ArchivaDavResourceFactoryTest
78 private static final String RELEASES_REPO = "releases";
80 private static final String INTERNAL_REPO = "internal";
82 private static final String LOCAL_MIRROR_REPO = "local-mirror";
84 private static final String LEGACY_REPO = "legacy-repo";
86 private static final String LOCAL_REPO_GROUP = "local";
88 private OverridingArchivaDavResourceFactory resourceFactory;
90 private IMocksControl requestControl;
92 private DavServletRequest request;
94 private IMocksControl repoRequestControl;
96 private RepositoryRequest repoRequest;
98 private IMocksControl responseControl;
100 private DavServletResponse response;
102 private IMocksControl archivaConfigurationControl;
104 private ArchivaConfiguration archivaConfiguration;
106 private Configuration config;
108 private IMocksControl repoContentFactoryControl;
110 private RepositoryContentFactory repoFactory;
113 ApplicationContext applicationContext;
116 PlexusSisuBridge plexusSisuBridge;
119 DefaultManagedRepositoryAdmin defaultManagedRepositoryAdmin;
122 RepositoryRegistry repositoryRegistry;
125 RemoteRepositoryAdmin remoteRepositoryAdmin;
129 DefaultRepositoryGroupAdmin defaultRepositoryGroupAdmin;
139 requestControl = createControl();
140 request = requestControl.createMock( DavServletRequest.class );
142 responseControl = createControl();
143 response = responseControl.createMock( DavServletResponse.class );
144 //responseControl.setDefaultMatcher( MockControl.ALWAYS_MATCHER );
146 archivaConfigurationControl = createControl();
147 archivaConfiguration = archivaConfigurationControl.createMock( ArchivaConfiguration.class );
149 config = new Configuration();
150 expect( archivaConfiguration.getConfiguration() ).andReturn( config ).times( 2, 20 );
151 expect (archivaConfiguration.getDefaultLocale()).andReturn( Locale.getDefault() ).anyTimes();
152 archivaConfiguration.addListener( EasyMock.anyObject( ) );
153 expectLastCall().times(0, 4);
154 archivaConfiguration.save( config );
156 expectLastCall().times( 0, 4 );
157 archivaConfigurationControl.replay();
159 defaultManagedRepositoryAdmin.setArchivaConfiguration( archivaConfiguration );
160 repositoryRegistry.setArchivaConfiguration( archivaConfiguration );
161 repositoryRegistry.reload();
162 ( (DefaultRepositoryCommonValidator) defaultManagedRepositoryAdmin.getRepositoryCommonValidator() ).setArchivaConfiguration(
163 archivaConfiguration );
164 if ( defaultManagedRepositoryAdmin.getManagedRepository( RELEASES_REPO ) == null )
166 defaultManagedRepositoryAdmin.addManagedRepository(
167 createManagedRepository( RELEASES_REPO, Paths.get( "target/test-classes/" + RELEASES_REPO ).toString(),
168 "default" ), false, null );
170 if ( defaultManagedRepositoryAdmin.getManagedRepository( INTERNAL_REPO ) == null )
172 defaultManagedRepositoryAdmin.addManagedRepository(
173 createManagedRepository( INTERNAL_REPO, Paths.get( "target/test-classes/" + INTERNAL_REPO ).toString(),
174 "default" ), false, null );
176 RepositoryGroup repoGroupConfig = new RepositoryGroup();
177 repoGroupConfig.setId( LOCAL_REPO_GROUP );
178 repoGroupConfig.addRepository( RELEASES_REPO );
179 repoGroupConfig.addRepository( INTERNAL_REPO );
181 defaultRepositoryGroupAdmin.setArchivaConfiguration( archivaConfiguration );
182 if ( defaultManagedRepositoryAdmin.getManagedRepository( LOCAL_REPO_GROUP ) == null )
184 defaultRepositoryGroupAdmin.addRepositoryGroup( repoGroupConfig, null );
187 repoContentFactoryControl = createControl();
188 repoFactory = repoContentFactoryControl.createMock( RepositoryContentFactory.class );
190 repoRequestControl = createControl();
191 repoRequest = repoRequestControl.createMock( RepositoryRequest.class );
194 new OverridingArchivaDavResourceFactory( applicationContext, plexusSisuBridge, archivaConfiguration );
195 resourceFactory.setArchivaConfiguration( archivaConfiguration );
196 resourceFactory.setRepositoryFactory( repoFactory );
197 resourceFactory.setRepositoryRequest( repoRequest );
198 resourceFactory.setConnectors( new OverridingRepositoryProxyConnectors() );
199 resourceFactory.setRemoteRepositoryAdmin( remoteRepositoryAdmin );
200 resourceFactory.setManagedRepositoryAdmin( defaultManagedRepositoryAdmin );
201 resourceFactory.setRepositoryRegistry( repositoryRegistry );
204 private ManagedRepository createManagedRepository( String id, String location, String layout )
206 ManagedRepository repoConfig = new ManagedRepository( Locale.getDefault());
207 repoConfig.setId( id );
208 repoConfig.setName( id );
209 repoConfig.setLocation( location );
210 repoConfig.setLayout( layout );
215 private ManagedRepositoryContent createManagedRepositoryContent( String repoId )
216 throws RepositoryAdminException
218 ManagedRepositoryContent repoContent = new ManagedDefaultRepositoryContent();
219 org.apache.archiva.repository.ManagedRepository repo = repositoryRegistry.getManagedRepository( repoId );
220 repoContent.setRepository( repo );
221 if (repo!=null && repo instanceof EditableManagedRepository)
223 ( (EditableManagedRepository) repo ).setContent( repoContent );
230 public void tearDown()
236 // MRM-1232 - Unable to get artifacts from repositories which requires Repository Manager role using repository group
238 public void testRepositoryGroupFirstRepositoryRequiresAuthentication()
241 DavResourceLocator locator = new ArchivaDavResourceLocator( "", "/repository/" + LOCAL_REPO_GROUP
242 + "/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar", LOCAL_REPO_GROUP,
243 new ArchivaDavLocatorFactory() );
245 ManagedRepositoryContent internalRepo = createManagedRepositoryContent( INTERNAL_REPO );
246 ManagedRepositoryContent releasesRepo = createManagedRepositoryContent( RELEASES_REPO );
250 archivaConfigurationControl.reset();
252 expect( archivaConfiguration.getConfiguration() ).andReturn( config ).times( 3 );
254 expect( request.getMethod() ).andReturn( "GET" ).times( 3 );
256 expect( request.getPathInfo() ).andReturn( "org/apache/archiva" ).times( 0, 2 );
258 expect( repoFactory.getManagedRepositoryContent( RELEASES_REPO ) ).andReturn( releasesRepo );
260 expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 2 );
262 expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 2 );
264 expect( request.getContextPath() ).andReturn( "" ).times( 2 );
266 expect( repoRequest.isSupportFile( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( true );
269 repoRequest.isDefault( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn(
272 expect( repoRequest.toArtifactReference(
273 "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( null );
275 expect( repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar",
276 internalRepo ) ).andReturn(
277 Paths.get( config.findManagedRepositoryById( INTERNAL_REPO ).getLocation(),
278 "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).toString());
280 expect( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ) ).andReturn( internalRepo );
282 expect( repoRequest.isArchetypeCatalog(
283 "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( false );
284 archivaConfigurationControl.replay();
285 requestControl.replay();
286 repoContentFactoryControl.replay();
287 repoRequestControl.replay();
289 resourceFactory.createResource( locator, request, response );
291 archivaConfigurationControl.verify();
292 requestControl.verify();
293 repoContentFactoryControl.verify();
294 repoRequestControl.verify();
296 fail( "A DavException with 401 error code should have been thrown." );
298 catch ( DavException e )
300 assertEquals( 401, e.getErrorCode() );
305 public void testRepositoryGroupLastRepositoryRequiresAuthentication()
308 DavResourceLocator locator = new ArchivaDavResourceLocator( "", "/repository/" + LOCAL_REPO_GROUP
309 + "/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar", LOCAL_REPO_GROUP,
310 new ArchivaDavLocatorFactory() );
312 List<RepositoryGroupConfiguration> repoGroups = new ArrayList<>();
313 RepositoryGroupConfiguration repoGroup = new RepositoryGroupConfiguration();
314 repoGroup.setId( LOCAL_REPO_GROUP );
315 repoGroup.addRepository( INTERNAL_REPO );
316 repoGroup.addRepository( RELEASES_REPO );
318 repoGroups.add( repoGroup );
320 config.setRepositoryGroups( repoGroups );
322 ManagedRepositoryContent internalRepo = createManagedRepositoryContent( INTERNAL_REPO );
324 ManagedRepositoryContent releasesRepo = createManagedRepositoryContent( RELEASES_REPO );
328 archivaConfigurationControl.reset();
330 expect( archivaConfiguration.getConfiguration() ).andReturn( config ).times( 3 );
332 expect( request.getMethod() ).andReturn( "GET" ).times( 3 );
334 expect( request.getPathInfo() ).andReturn( "org/apache/archiva" ).times( 0, 2 );
336 expect( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ) ).andReturn( internalRepo );
338 expect( repoFactory.getManagedRepositoryContent( RELEASES_REPO ) ).andReturn( releasesRepo );
340 expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 2 );
342 expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 2 );
344 expect( request.getContextPath() ).andReturn( "" ).times( 2 );
346 expect( repoRequest.isSupportFile( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( false );
349 repoRequest.isDefault( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn(
352 expect( repoRequest.toArtifactReference(
353 "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( null );
355 expect( repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar",
356 internalRepo ) ).andReturn(
357 Paths.get( config.findManagedRepositoryById( INTERNAL_REPO ).getLocation(),
358 "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).toString());
361 expect( repoRequest.isArchetypeCatalog(
362 "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( false );
363 archivaConfigurationControl.replay();
364 requestControl.replay();
365 repoContentFactoryControl.replay();
366 repoRequestControl.replay();
368 resourceFactory.createResource( locator, request, response );
370 archivaConfigurationControl.verify();
371 requestControl.verify();
372 repoContentFactoryControl.verify();
373 repoRequestControl.verify();
375 fail( "A DavException with 401 error code should have been thrown." );
377 catch ( DavException e )
379 assertEquals( 401, e.getErrorCode() );
384 public void testRepositoryGroupArtifactDoesNotExistInAnyOfTheReposAuthenticationDisabled()
387 DavResourceLocator locator = new ArchivaDavResourceLocator( "", "/repository/" + LOCAL_REPO_GROUP
388 + "/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar", LOCAL_REPO_GROUP,
389 new ArchivaDavLocatorFactory() );
391 defaultManagedRepositoryAdmin.addManagedRepository(
392 createManagedRepository( LOCAL_MIRROR_REPO, Paths.get( "target/test-classes/local-mirror" ).toString(),
393 "default" ), false, null );
395 List<RepositoryGroupConfiguration> repoGroups = new ArrayList<>();
396 RepositoryGroupConfiguration repoGroup = new RepositoryGroupConfiguration();
397 repoGroup.setId( LOCAL_REPO_GROUP );
398 repoGroup.addRepository( INTERNAL_REPO );
399 repoGroup.addRepository( LOCAL_MIRROR_REPO );
401 repoGroups.add( repoGroup );
403 config.setRepositoryGroups( repoGroups );
405 ManagedRepositoryContent internalRepo = createManagedRepositoryContent( INTERNAL_REPO );
406 ManagedRepositoryContent localMirrorRepo = createManagedRepositoryContent( LOCAL_MIRROR_REPO );
410 archivaConfigurationControl.reset();
412 expect( archivaConfiguration.getConfiguration() ).andReturn( config ).times( 3 );
414 expect( request.getMethod() ).andReturn( "GET" ).times( 5 );
416 expect( request.getPathInfo() ).andReturn( "org/apache/archiva" ).times( 0, 2 );
418 expect( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ) ).andReturn( internalRepo );
420 expect( repoFactory.getManagedRepositoryContent( LOCAL_MIRROR_REPO ) ).andReturn( localMirrorRepo );
422 expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 4 );
424 expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 4 );
426 expect( request.getContextPath() ).andReturn( "" ).times( 2 );
428 expect( repoRequest.isSupportFile( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( false ).times( 2 );
431 repoRequest.isDefault( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn(
434 expect( repoRequest.toArtifactReference(
435 "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( null ).times( 2 );
437 expect( repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar",
438 internalRepo ) ).andReturn(
439 Paths.get( config.findManagedRepositoryById( INTERNAL_REPO ).getLocation(),
440 "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).toString() );
442 expect( repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar",
444 .andReturn( Paths.get( config.findManagedRepositoryById( LOCAL_MIRROR_REPO ).getLocation(),
445 "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).toString());
447 expect( repoRequest.isArchetypeCatalog( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( false ).times( 2 );
448 archivaConfigurationControl.replay();
449 requestControl.replay();
450 repoContentFactoryControl.replay();
451 repoRequestControl.replay();
453 resourceFactory.createResource( locator, request, response );
455 archivaConfigurationControl.verify();
456 requestControl.verify();
457 repoContentFactoryControl.verify();
458 repoRequestControl.verify();
460 fail( "A DavException with 404 error code should have been thrown." );
462 catch ( DavException e )
464 assertEquals( 404, e.getErrorCode() );
470 public void testRequestArtifactMetadataThreePartsRepoHasDefaultLayout()
473 // should fetch metadata
474 DavResourceLocator locator =
475 new ArchivaDavResourceLocator( "", "/repository/" + INTERNAL_REPO + "/eclipse/jdtcore/maven-metadata.xml",
476 INTERNAL_REPO, new ArchivaDavLocatorFactory() );
478 ManagedRepositoryContent internalRepo = createManagedRepositoryContent( INTERNAL_REPO );
480 // use actual object (this performs the isMetadata, isDefault and isSupportFile check!)
481 RepositoryRequest repoRequest = new RepositoryRequest( );
482 resourceFactory.setRepositoryRequest( repoRequest );
486 archivaConfigurationControl.reset();
488 expect( archivaConfiguration.getConfiguration() ).andReturn( config ).times( 1 );
490 expect( request.getMethod() ).andReturn( "GET" ).times( 4 );
492 expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 3 );
494 expect( request.getContextPath() ).andReturn( "" ).times( 1 );
496 expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 2 );
498 expect( request.getRequestURI() ).andReturn( "http://localhost:8080/archiva/repository/" + INTERNAL_REPO + "/eclipse/jdtcore/maven-metadata.xml" );
499 response.setHeader( "Pragma", "no-cache" );
503 response.setHeader( "Cache-Control", "no-cache" );
507 response.setDateHeader( eq("Last-Modified"), anyLong() );
510 archivaConfigurationControl.replay();
511 repoContentFactoryControl.replay();
512 requestControl.replay();
513 responseControl.replay();
515 resourceFactory.createResource( locator, request, response );
517 archivaConfigurationControl.verify();
518 repoContentFactoryControl.verify();
519 requestControl.verify();
520 responseControl.verify();
522 catch ( DavException e )
524 fail( "A DavException should not have been thrown!" );
529 public void testRequestArtifactMetadataTwoPartsRepoHasDefaultLayout()
532 // should not fetch metadata
533 DavResourceLocator locator =
534 new ArchivaDavResourceLocator( "", "/repository/" + INTERNAL_REPO + "/eclipse/maven-metadata.xml",
535 INTERNAL_REPO, new ArchivaDavLocatorFactory() );
537 ManagedRepositoryContent internalRepo = createManagedRepositoryContent( INTERNAL_REPO );
539 // use actual object (this performs the isMetadata, isDefault and isSupportFile check!)
540 RepositoryRequest repoRequest = new RepositoryRequest( );
541 resourceFactory.setRepositoryRequest( repoRequest );
545 archivaConfigurationControl.reset();
547 expect( archivaConfiguration.getConfiguration() ).andReturn( config ).times( 2 );
549 expect( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ) ).andReturn( internalRepo );
551 expect( request.getMethod() ).andReturn( "GET" ).times( 3 );
553 expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 3 );
555 expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 2 );
557 expect( request.getContextPath() ).andReturn( "" ).times( 2 );
559 archivaConfigurationControl.replay();
560 repoContentFactoryControl.replay();
561 requestControl.replay();
563 resourceFactory.createResource( locator, request, response );
565 archivaConfigurationControl.verify();
566 repoContentFactoryControl.verify();
567 requestControl.verify();
569 fail( "A 404 error should have been thrown!" );
571 catch ( DavException e )
573 assertEquals( 404, e.getErrorCode() );
578 public void testRequestMetadataRepoIsLegacy()
581 ManagedRepositoryContent legacyRepo = createManagedRepositoryContent( LEGACY_REPO );
582 ConfigurableListableBeanFactory beanFactory = ((ConfigurableApplicationContext) applicationContext).getBeanFactory();
583 beanFactory.registerSingleton("managedRepositoryContent#legacy", legacyRepo);
584 defaultManagedRepositoryAdmin.addManagedRepository(
585 createManagedRepository( LEGACY_REPO, Paths.get( "target/test-classes/" + LEGACY_REPO ).toString(),
586 "legacy" ), false, null );
587 DavResourceLocator locator =
588 new ArchivaDavResourceLocator( "", "/repository/" + LEGACY_REPO + "/eclipse/maven-metadata.xml",
589 LEGACY_REPO, new ArchivaDavLocatorFactory() );
592 // use actual object (this performs the isMetadata, isDefault and isSupportFile check!)
593 RepositoryRequest repoRequest = new RepositoryRequest( );
594 resourceFactory.setRepositoryRequest( repoRequest );
598 archivaConfigurationControl.reset();
600 expect( archivaConfiguration.getConfiguration() ).andReturn( config ).times( 2 );
602 expect( repoFactory.getManagedRepositoryContent( LEGACY_REPO ) ).andReturn( legacyRepo );
604 expect( request.getMethod() ).andReturn( "GET" ).times( 3 );
606 expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 3 );
608 expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 2 );
610 expect( request.getContextPath() ).andReturn( "" ).times( 2 );
612 archivaConfigurationControl.replay();
613 repoContentFactoryControl.replay();
614 requestControl.replay();
616 resourceFactory.createResource( locator, request, response );
618 archivaConfigurationControl.verify();
619 repoContentFactoryControl.verify();
620 requestControl.verify();
622 fail( "A 404 error should have been thrown!" );
624 catch ( DavException e )
626 assertEquals( 404, e.getErrorCode() );
630 class OverridingArchivaDavResourceFactory
631 extends ArchivaDavResourceFactory
634 OverridingArchivaDavResourceFactory( ApplicationContext applicationContext, PlexusSisuBridge plexusSisuBridge,
635 ArchivaConfiguration archivaConfiguration )
636 throws PlexusSisuBridgeException
638 super( applicationContext, plexusSisuBridge, archivaConfiguration );
642 protected boolean isAuthorized( DavServletRequest request, String repositoryId )
645 if ( RELEASES_REPO.equals( repositoryId ) )
647 throw new UnauthorizedDavException( repositoryId,
648 "You are not authenticated and authorized to access any repository." );
657 protected String getActivePrincipal( DavServletRequest request )
663 class OverridingRepositoryProxyConnectors
664 extends DefaultRepositoryProxyConnectors
667 public ProxyFetchResult fetchMetadataFromProxies( ManagedRepositoryContent repository, String logicalPath )
669 Path target = Paths.get(repository.getRepoRoot(), logicalPath );
672 FileUtils.copyFile( Paths.get( "target/test-classes/maven-metadata.xml" ).toFile(), target.toFile() );
674 catch ( IOException e )
679 return new ProxyFetchResult( target, true );