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