]> source.dussan.org Git - archiva.git/blob
3e9981f011b2e958ebd63080136d417505d780d2
[archiva.git] /
1 package org.apache.archiva.webdav;
2
3 /*
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
11  *
12  *  http://www.apache.org/licenses/LICENSE-2.0
13  *
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
19  * under the License.
20  */
21
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.repository.DefaultRepositoryCommonValidator;
27 import org.apache.archiva.admin.repository.group.DefaultRepositoryGroupAdmin;
28 import org.apache.archiva.admin.repository.managed.DefaultManagedRepositoryAdmin;
29 import org.apache.archiva.common.plexusbridge.PlexusSisuBridge;
30 import org.apache.archiva.common.plexusbridge.PlexusSisuBridgeException;
31 import org.apache.archiva.configuration.ArchivaConfiguration;
32 import org.apache.archiva.configuration.Configuration;
33 import org.apache.archiva.configuration.RepositoryGroupConfiguration;
34 import org.apache.archiva.proxy.DefaultRepositoryProxyConnectors;
35 import org.apache.archiva.repository.ManagedRepositoryContent;
36 import org.apache.archiva.repository.RepositoryContentFactory;
37 import org.apache.archiva.repository.content.LegacyPathParser;
38 import org.apache.archiva.repository.content.ManagedDefaultRepositoryContent;
39 import org.apache.archiva.repository.content.RepositoryRequest;
40 import org.apache.commons.io.FileUtils;
41 import org.apache.jackrabbit.webdav.DavException;
42 import org.apache.jackrabbit.webdav.DavResourceLocator;
43 import org.apache.jackrabbit.webdav.DavServletRequest;
44 import org.apache.jackrabbit.webdav.DavServletResponse;
45 import org.easymock.MockControl;
46 import org.easymock.classextension.MockClassControl;
47 import org.junit.After;
48 import org.junit.Before;
49 import org.junit.Test;
50 import org.junit.runner.RunWith;
51 import org.springframework.context.ApplicationContext;
52 import org.springframework.test.context.ContextConfiguration;
53
54 import javax.inject.Inject;
55 import java.io.File;
56 import java.io.IOException;
57 import java.util.ArrayList;
58 import java.util.List;
59 import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
60
61 /**
62  * ArchivaDavResourceFactoryTest
63  */
64 @RunWith( ArchivaSpringJUnit4ClassRunner.class )
65 @ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" } )
66 public class ArchivaDavResourceFactoryTest
67     extends TestCase
68 {
69     private static final String RELEASES_REPO = "releases";
70
71     private static final String INTERNAL_REPO = "internal";
72
73     private static final String LOCAL_MIRROR_REPO = "local-mirror";
74
75     private static final String LEGACY_REPO = "legacy-repo";
76
77     private static final String LOCAL_REPO_GROUP = "local";
78
79     private OverridingArchivaDavResourceFactory resourceFactory;
80
81     private MockControl requestControl;
82
83     private DavServletRequest request;
84
85     private MockControl repoRequestControl;
86
87     private RepositoryRequest repoRequest;
88
89     private MockControl responseControl;
90
91     private DavServletResponse response;
92
93     private MockControl archivaConfigurationControl;
94
95     private ArchivaConfiguration archivaConfiguration;
96
97     private Configuration config;
98
99     private MockControl repoContentFactoryControl;
100
101     private RepositoryContentFactory repoFactory;
102
103     @Inject
104     ApplicationContext applicationContext;
105
106     @Inject
107     PlexusSisuBridge plexusSisuBridge;
108
109     @Inject
110     DefaultManagedRepositoryAdmin defaultManagedRepositoryAdmin;
111
112     @Inject
113     DefaultRepositoryGroupAdmin defaultRepositoryGroupAdmin;
114
115
116     @Before
117     public void setUp()
118         throws Exception
119     {
120         super.setUp();
121
122         requestControl = MockControl.createControl( DavServletRequest.class );
123         request = (DavServletRequest) requestControl.getMock();
124
125         responseControl = MockControl.createControl( DavServletResponse.class );
126         response = (DavServletResponse) responseControl.getMock();
127         responseControl.setDefaultMatcher( MockControl.ALWAYS_MATCHER );
128
129         archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class );
130         archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock();
131
132         config = new Configuration();
133         archivaConfiguration.getConfiguration();
134         archivaConfigurationControl.setReturnValue( config, 5, 20 );
135         archivaConfiguration.save( config );
136         archivaConfigurationControl.setVoidCallable( 1, 4 );
137         archivaConfigurationControl.replay();
138
139         defaultManagedRepositoryAdmin.setArchivaConfiguration( archivaConfiguration );
140         ( (DefaultRepositoryCommonValidator) defaultManagedRepositoryAdmin.getRepositoryCommonValidator() ).setArchivaConfiguration(
141             archivaConfiguration );
142         if ( defaultManagedRepositoryAdmin.getManagedRepository( RELEASES_REPO ) == null )
143         {
144             defaultManagedRepositoryAdmin.addManagedRepository(
145                 createManagedRepository( RELEASES_REPO, new File( "target/test-classes/" + RELEASES_REPO ).getPath(),
146                                          "default" ), false, null );
147         }
148         if ( defaultManagedRepositoryAdmin.getManagedRepository( INTERNAL_REPO ) == null )
149         {
150             defaultManagedRepositoryAdmin.addManagedRepository(
151                 createManagedRepository( INTERNAL_REPO, new File( "target/test-classes/" + INTERNAL_REPO ).getPath(),
152                                          "default" ), false, null );
153         }
154         RepositoryGroup repoGroupConfig = new RepositoryGroup();
155         repoGroupConfig.setId( LOCAL_REPO_GROUP );
156         repoGroupConfig.addRepository( RELEASES_REPO );
157         repoGroupConfig.addRepository( INTERNAL_REPO );
158
159         defaultRepositoryGroupAdmin.setArchivaConfiguration( archivaConfiguration );
160         if ( defaultManagedRepositoryAdmin.getManagedRepository( LOCAL_REPO_GROUP ) == null )
161         {
162             defaultRepositoryGroupAdmin.addRepositoryGroup( repoGroupConfig, null );
163         }
164
165         repoContentFactoryControl = MockClassControl.createControl( RepositoryContentFactory.class );
166         repoFactory = (RepositoryContentFactory) repoContentFactoryControl.getMock();
167
168         repoRequestControl = MockClassControl.createControl( RepositoryRequest.class );
169         repoRequest = (RepositoryRequest) repoRequestControl.getMock();
170
171         resourceFactory =
172             new OverridingArchivaDavResourceFactory( applicationContext, plexusSisuBridge, archivaConfiguration );
173         resourceFactory.setArchivaConfiguration( archivaConfiguration );
174         resourceFactory.setRepositoryFactory( repoFactory );
175         resourceFactory.setRepositoryRequest( repoRequest );
176         resourceFactory.setConnectors( new OverridingRepositoryProxyConnectors() );
177     }
178
179     private ManagedRepository createManagedRepository( String id, String location, String layout )
180     {
181         ManagedRepository repoConfig = new ManagedRepository();
182         repoConfig.setId( id );
183         repoConfig.setName( id );
184         repoConfig.setLocation( location );
185         repoConfig.setLayout( layout );
186
187         return repoConfig;
188     }
189
190     private ManagedRepositoryContent createManagedRepositoryContent( String repoId )
191         throws RepositoryAdminException
192     {
193         ManagedRepositoryContent repoContent = new ManagedDefaultRepositoryContent();
194         repoContent.setRepository( defaultManagedRepositoryAdmin.getManagedRepository( repoId ) );
195
196         return repoContent;
197     }
198
199     @After
200     public void tearDown()
201         throws Exception
202     {
203         super.tearDown();
204     }
205
206     // MRM-1232 - Unable to get artifacts from repositories which requires Repository Manager role using repository group
207     @Test
208     public void testRepositoryGroupFirstRepositoryRequiresAuthentication()
209         throws Exception
210     {
211         DavResourceLocator locator = new ArchivaDavResourceLocator( "", "/repository/" + LOCAL_REPO_GROUP
212             + "/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar", LOCAL_REPO_GROUP,
213                                                                     new ArchivaDavLocatorFactory() );
214
215         ManagedRepositoryContent internalRepo = createManagedRepositoryContent( INTERNAL_REPO );
216         ManagedRepositoryContent releasesRepo = createManagedRepositoryContent( RELEASES_REPO );
217
218         try
219         {
220             archivaConfigurationControl.reset();
221             archivaConfigurationControl.expectAndReturn( archivaConfiguration.getConfiguration(), config );
222             requestControl.expectAndReturn( request.getMethod(), "GET", 2 );
223             requestControl.expectAndReturn( request.getPathInfo(), "org/apache/archiva", 0, 2 );
224             repoContentFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( RELEASES_REPO ),
225                                                        releasesRepo );
226             requestControl.expectAndReturn( request.getRemoteAddr(), "http://localhost:8080", 2 );
227             requestControl.expectAndReturn( request.getDavSession(), new ArchivaDavSession(), 2 );
228
229             repoRequestControl.expectAndReturn(
230                 repoRequest.isSupportFile( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ),
231                 false );
232             repoRequestControl.expectAndReturn(
233                 repoRequest.isDefault( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ), false );
234             repoRequestControl.expectAndReturn(
235                 repoRequest.toArtifactReference( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ),
236                 null );
237             repoRequestControl.expectAndReturn(
238                 repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar",
239                                           internalRepo ),
240                 new File( config.findManagedRepositoryById( INTERNAL_REPO ).getLocation(),
241                           "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).getPath() );
242             repoContentFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ),
243                                                        internalRepo );
244
245             archivaConfigurationControl.replay();
246             requestControl.replay();
247             repoContentFactoryControl.replay();
248             repoRequestControl.replay();
249
250             resourceFactory.createResource( locator, request, response );
251
252             archivaConfigurationControl.verify();
253             requestControl.verify();
254             repoContentFactoryControl.verify();
255             repoRequestControl.verify();
256
257             fail( "A DavException with 401 error code should have been thrown." );
258         }
259         catch ( DavException e )
260         {
261             assertEquals( 401, e.getErrorCode() );
262         }
263     }
264
265     @Test
266     public void testRepositoryGroupLastRepositoryRequiresAuthentication()
267         throws Exception
268     {
269         DavResourceLocator locator = new ArchivaDavResourceLocator( "", "/repository/" + LOCAL_REPO_GROUP
270             + "/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar", LOCAL_REPO_GROUP,
271                                                                     new ArchivaDavLocatorFactory() );
272
273         List<RepositoryGroupConfiguration> repoGroups = new ArrayList<RepositoryGroupConfiguration>();
274         RepositoryGroupConfiguration repoGroup = new RepositoryGroupConfiguration();
275         repoGroup.setId( LOCAL_REPO_GROUP );
276         repoGroup.addRepository( INTERNAL_REPO );
277         repoGroup.addRepository( RELEASES_REPO );
278
279         repoGroups.add( repoGroup );
280
281         config.setRepositoryGroups( repoGroups );
282
283         ManagedRepositoryContent internalRepo = createManagedRepositoryContent( INTERNAL_REPO );
284
285         ManagedRepositoryContent releasesRepo = createManagedRepositoryContent( RELEASES_REPO );
286
287         try
288         {
289             archivaConfigurationControl.reset();
290             archivaConfigurationControl.expectAndReturn( archivaConfiguration.getConfiguration(), config );
291             requestControl.expectAndReturn( request.getMethod(), "GET", 2 );
292             requestControl.expectAndReturn( request.getPathInfo(), "org/apache/archiva", 0, 2 );
293             repoContentFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ),
294                                                        internalRepo );
295             repoContentFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( RELEASES_REPO ),
296                                                        releasesRepo );
297             requestControl.expectAndReturn( request.getRemoteAddr(), "http://localhost:8080", 2 );
298             requestControl.expectAndReturn( request.getDavSession(), new ArchivaDavSession(), 2 );
299             repoRequestControl.expectAndReturn(
300                 repoRequest.isSupportFile( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ),
301                 false );
302             repoRequestControl.expectAndReturn(
303                 repoRequest.isDefault( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ), false );
304             repoRequestControl.expectAndReturn(
305                 repoRequest.toArtifactReference( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ),
306                 null );
307             repoRequestControl.expectAndReturn(
308                 repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar",
309                                           internalRepo ),
310                 new File( config.findManagedRepositoryById( INTERNAL_REPO ).getLocation(),
311                           "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).getPath() );
312
313             archivaConfigurationControl.replay();
314             requestControl.replay();
315             repoContentFactoryControl.replay();
316             repoRequestControl.replay();
317
318             resourceFactory.createResource( locator, request, response );
319
320             archivaConfigurationControl.verify();
321             requestControl.verify();
322             repoContentFactoryControl.verify();
323             repoRequestControl.verify();
324
325             fail( "A DavException with 401 error code should have been thrown." );
326         }
327         catch ( DavException e )
328         {
329             assertEquals( 401, e.getErrorCode() );
330         }
331     }
332
333     @Test
334     public void testRepositoryGroupArtifactDoesNotExistInAnyOfTheReposAuthenticationDisabled()
335         throws Exception
336     {
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() );
340
341         defaultManagedRepositoryAdmin.addManagedRepository(
342             createManagedRepository( LOCAL_MIRROR_REPO, new File( "target/test-classes/local-mirror" ).getPath(),
343                                      "default" ), false, null );
344
345         List<RepositoryGroupConfiguration> repoGroups = new ArrayList<RepositoryGroupConfiguration>();
346         RepositoryGroupConfiguration repoGroup = new RepositoryGroupConfiguration();
347         repoGroup.setId( LOCAL_REPO_GROUP );
348         repoGroup.addRepository( INTERNAL_REPO );
349         repoGroup.addRepository( LOCAL_MIRROR_REPO );
350
351         repoGroups.add( repoGroup );
352
353         config.setRepositoryGroups( repoGroups );
354
355         ManagedRepositoryContent internalRepo = createManagedRepositoryContent( INTERNAL_REPO );
356         ManagedRepositoryContent localMirrorRepo = createManagedRepositoryContent( LOCAL_MIRROR_REPO );
357
358         try
359         {
360             archivaConfigurationControl.reset();
361             archivaConfigurationControl.expectAndReturn( archivaConfiguration.getConfiguration(), config );
362             requestControl.expectAndReturn( request.getMethod(), "GET", 4 );
363             requestControl.expectAndReturn( request.getPathInfo(), "org/apache/archiva", 0, 2 );
364             repoContentFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ),
365                                                        internalRepo );
366             repoContentFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( LOCAL_MIRROR_REPO ),
367                                                        localMirrorRepo );
368             requestControl.expectAndReturn( request.getRemoteAddr(), "http://localhost:8080", 4 );
369             requestControl.expectAndReturn( request.getDavSession(), new ArchivaDavSession(), 4 );
370             repoRequestControl.expectAndReturn(
371                 repoRequest.isSupportFile( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ), false,
372                 2 );
373             repoRequestControl.expectAndReturn(
374                 repoRequest.isDefault( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ), false, 2 );
375             repoRequestControl.expectAndReturn(
376                 repoRequest.toArtifactReference( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ),
377                 null, 2 );
378             repoRequestControl.expectAndReturn(
379                 repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar",
380                                           internalRepo ),
381                 new File( config.findManagedRepositoryById( INTERNAL_REPO ).getLocation(),
382                           "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).getPath() );
383
384             repoRequestControl.expectAndReturn(
385                 repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar",
386                                           localMirrorRepo ),
387                 new File( config.findManagedRepositoryById( LOCAL_MIRROR_REPO ).getLocation(),
388                           "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).getPath() );
389
390             archivaConfigurationControl.replay();
391             requestControl.replay();
392             repoContentFactoryControl.replay();
393             repoRequestControl.replay();
394
395             resourceFactory.createResource( locator, request, response );
396
397             archivaConfigurationControl.verify();
398             requestControl.verify();
399             repoContentFactoryControl.verify();
400             repoRequestControl.verify();
401
402             fail( "A DavException with 404 error code should have been thrown." );
403         }
404         catch ( DavException e )
405         {
406             assertEquals( 404, e.getErrorCode() );
407         }
408     }
409
410     // MRM-1239
411     @Test
412     public void testRequestArtifactMetadataThreePartsRepoHasDefaultLayout()
413         throws Exception
414     {
415         // should fetch metadata 
416         DavResourceLocator locator =
417             new ArchivaDavResourceLocator( "", "/repository/" + INTERNAL_REPO + "/eclipse/jdtcore/maven-metadata.xml",
418                                            INTERNAL_REPO, new ArchivaDavLocatorFactory() );
419
420         ManagedRepositoryContent internalRepo = createManagedRepositoryContent( INTERNAL_REPO );
421
422         // use actual object (this performs the isMetadata, isDefault and isSupportFile check!)
423         RepositoryRequest repoRequest = new RepositoryRequest( new LegacyPathParser( this.archivaConfiguration ) );
424         resourceFactory.setRepositoryRequest( repoRequest );
425
426         try
427         {
428             archivaConfigurationControl.reset();
429             archivaConfigurationControl.expectAndReturn( archivaConfiguration.getConfiguration(), config );
430             repoContentFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ),
431                                                        internalRepo );
432             requestControl.expectAndReturn( request.getMethod(), "GET", 3 );
433             requestControl.expectAndReturn( request.getRemoteAddr(), "http://localhost:8080", 3 );
434             requestControl.expectAndReturn( request.getDavSession(), new ArchivaDavSession(), 2 );
435             requestControl.expectAndReturn( request.getRequestURI(),
436                                             "http://localhost:8080/archiva/repository/" + INTERNAL_REPO
437                                                 + "/eclipse/jdtcore/maven-metadata.xml" );
438             response.setHeader( "Pragma", "no-cache" );
439             responseControl.setVoidCallable();
440
441             response.setHeader( "Cache-Control", "no-cache" );
442             responseControl.setVoidCallable();
443
444             long date = 2039842134;
445             response.setDateHeader( "last-modified", date );
446             responseControl.setVoidCallable();
447
448             archivaConfigurationControl.replay();
449             repoContentFactoryControl.replay();
450             requestControl.replay();
451             responseControl.replay();
452
453             resourceFactory.createResource( locator, request, response );
454
455             archivaConfigurationControl.verify();
456             repoContentFactoryControl.verify();
457             requestControl.verify();
458             responseControl.verify();
459         }
460         catch ( DavException e )
461         {
462             fail( "A DavException should not have been thrown!" );
463         }
464     }
465
466     @Test
467     public void testRequestArtifactMetadataTwoPartsRepoHasDefaultLayout()
468         throws Exception
469     {
470         // should not fetch metadata
471         DavResourceLocator locator =
472             new ArchivaDavResourceLocator( "", "/repository/" + INTERNAL_REPO + "/eclipse/maven-metadata.xml",
473                                            INTERNAL_REPO, new ArchivaDavLocatorFactory() );
474
475         ManagedRepositoryContent internalRepo = createManagedRepositoryContent( INTERNAL_REPO );
476
477         // use actual object (this performs the isMetadata, isDefault and isSupportFile check!)
478         RepositoryRequest repoRequest = new RepositoryRequest( new LegacyPathParser( this.archivaConfiguration ) );
479         resourceFactory.setRepositoryRequest( repoRequest );
480
481         try
482         {
483             archivaConfigurationControl.reset();
484             archivaConfigurationControl.expectAndReturn( archivaConfiguration.getConfiguration(), config );
485             repoContentFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ),
486                                                        internalRepo );
487             requestControl.expectAndReturn( request.getMethod(), "GET", 2 );
488             requestControl.expectAndReturn( request.getRemoteAddr(), "http://localhost:8080", 2 );
489             requestControl.expectAndReturn( request.getDavSession(), new ArchivaDavSession(), 2 );
490
491             archivaConfigurationControl.replay();
492             repoContentFactoryControl.replay();
493             requestControl.replay();
494
495             resourceFactory.createResource( locator, request, response );
496
497             archivaConfigurationControl.verify();
498             repoContentFactoryControl.verify();
499             requestControl.verify();
500
501             fail( "A 404 error should have been thrown!" );
502         }
503         catch ( DavException e )
504         {
505             assertEquals( 404, e.getErrorCode() );
506         }
507     }
508
509     @Test
510     public void testRequestMetadataRepoIsLegacy()
511         throws Exception
512     {
513         defaultManagedRepositoryAdmin.addManagedRepository(
514             createManagedRepository( LEGACY_REPO, new File( "target/test-classes/" + LEGACY_REPO ).getPath(),
515                                      "legacy" ), false, null );
516         DavResourceLocator locator =
517             new ArchivaDavResourceLocator( "", "/repository/" + LEGACY_REPO + "/eclipse/maven-metadata.xml",
518                                            LEGACY_REPO, new ArchivaDavLocatorFactory() );
519
520         ManagedRepositoryContent legacyRepo = createManagedRepositoryContent( LEGACY_REPO );
521
522         // use actual object (this performs the isMetadata, isDefault and isSupportFile check!)
523         RepositoryRequest repoRequest = new RepositoryRequest( new LegacyPathParser( this.archivaConfiguration ) );
524         resourceFactory.setRepositoryRequest( repoRequest );
525
526         try
527         {
528             archivaConfigurationControl.reset();
529             archivaConfigurationControl.expectAndReturn( archivaConfiguration.getConfiguration(), config );
530             repoContentFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( LEGACY_REPO ),
531                                                        legacyRepo );
532             requestControl.expectAndReturn( request.getMethod(), "GET", 2 );
533             requestControl.expectAndReturn( request.getRemoteAddr(), "http://localhost:8080", 2 );
534             requestControl.expectAndReturn( request.getDavSession(), new ArchivaDavSession(), 2 );
535
536             archivaConfigurationControl.replay();
537             repoContentFactoryControl.replay();
538             requestControl.replay();
539
540             resourceFactory.createResource( locator, request, response );
541
542             archivaConfigurationControl.verify();
543             repoContentFactoryControl.verify();
544             requestControl.verify();
545
546             fail( "A 404 error should have been thrown!" );
547         }
548         catch ( DavException e )
549         {
550             assertEquals( 404, e.getErrorCode() );
551         }
552     }
553
554     class OverridingArchivaDavResourceFactory
555         extends ArchivaDavResourceFactory
556     {
557
558         OverridingArchivaDavResourceFactory( ApplicationContext applicationContext, PlexusSisuBridge plexusSisuBridge,
559                                              ArchivaConfiguration archivaConfiguration )
560             throws PlexusSisuBridgeException
561         {
562             super( applicationContext, plexusSisuBridge, archivaConfiguration );
563         }
564
565         protected boolean isAuthorized( DavServletRequest request, String repositoryId )
566             throws DavException
567         {
568             if ( RELEASES_REPO.equals( repositoryId ) )
569             {
570                 throw new UnauthorizedDavException( repositoryId,
571                                                     "You are not authenticated and authorized to access any repository." );
572             }
573             else
574             {
575                 return true;
576             }
577         }
578
579         protected String getActivePrincipal( DavServletRequest request )
580         {
581             return "guest";
582         }
583     }
584
585     class OverridingRepositoryProxyConnectors
586         extends DefaultRepositoryProxyConnectors
587     {
588         public File fetchMetatadaFromProxies( ManagedRepositoryContent repository, String logicalPath )
589         {
590             File target = new File( repository.getRepoRoot(), logicalPath );
591             try
592             {
593                 FileUtils.copyFile( new File( "target/test-classes/maven-metadata.xml" ), target );
594             }
595             catch ( IOException e )
596             {
597
598             }
599
600             return target;
601         }
602     }
603 }