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