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