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