]> source.dussan.org Git - archiva.git/blob
c94ac4a340c5e3c6e4cbf031a1c097cd2a1526aa
[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 com.meterware.httpunit.GetMethodWebRequest;
23 import com.meterware.httpunit.WebRequest;
24 import com.meterware.httpunit.WebResponse;
25 import org.apache.commons.io.FileUtils;
26 import org.apache.archiva.configuration.ProxyConnectorConfiguration;
27 import org.junit.Before;
28 import org.junit.Test;
29
30 import java.io.File;
31 import java.util.ArrayList;
32
33 /**
34  * RepositoryServletTest
35  *
36  * @version $Id$
37  */
38 public class RepositoryServletNoProxyTest
39     extends AbstractRepositoryServletTestCase
40 {
41
42     @Before
43     public void setUp()
44         throws Exception
45     {
46         super.setUp();
47         archivaConfiguration.getConfiguration().setProxyConnectors( new ArrayList<ProxyConnectorConfiguration>() );
48     }
49
50     @Test
51     public void testLastModifiedHeaderExists()
52         throws Exception
53     {
54         String commonsLangSha1 = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar.sha1";
55
56         File checksumFile = new File( repoRootInternal, commonsLangSha1 );
57         checksumFile.getParentFile().mkdirs();
58
59         FileUtils.writeStringToFile( checksumFile, "dummy-checksum", null );
60
61         WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangSha1 );
62         WebResponse response = getServletUnitClient().getResponse( request );
63
64         assertNotNull( response.getHeaderField( "last-modified" ) );
65     }
66
67     @Test
68     public void testGetNoProxyChecksumDefaultLayout()
69         throws Exception
70     {
71         String commonsLangSha1 = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar.sha1";
72
73         File checksumFile = new File( repoRootInternal, commonsLangSha1 );
74         checksumFile.getParentFile().mkdirs();
75
76         FileUtils.writeStringToFile( checksumFile, "dummy-checksum", null );
77
78         WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangSha1 );
79         WebResponse response = getServletUnitClient().getResponse( request );
80         assertResponseOK( response );
81
82         assertEquals( "Expected file contents", "dummy-checksum", response.getText() );
83     }
84
85     @Test
86     public void testGetNoProxyChecksumLegacyLayout()
87         throws Exception
88     {
89         String commonsLangSha1 = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar.sha1";
90
91         File checksumFile = new File( repoRootInternal, commonsLangSha1 );
92         checksumFile.getParentFile().mkdirs();
93
94         FileUtils.writeStringToFile( checksumFile, "dummy-checksum", null );
95
96         WebRequest request = new GetMethodWebRequest(
97             "http://machine.com/repository/internal/" + "commons-lang/jars/commons-lang-2.1.jar.sha1" );
98         WebResponse response = getServletUnitClient().getResponse( request );
99         assertResponseOK( response );
100
101         assertEquals( "Expected file contents", "dummy-checksum", response.getText() );
102     }
103
104     @Test
105     public void testGetNoProxyVersionedMetadataDefaultLayout()
106         throws Exception
107     {
108         String commonsLangMetadata = "commons-lang/commons-lang/2.1/maven-metadata.xml";
109         String expectedMetadataContents = "dummy-versioned-metadata";
110
111         File metadataFile = new File( repoRootInternal, commonsLangMetadata );
112         metadataFile.getParentFile().mkdirs();
113
114         FileUtils.writeStringToFile( metadataFile, expectedMetadataContents, null );
115
116         WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangMetadata );
117         WebResponse response = getServletUnitClient().getResponse( request );
118         assertResponseOK( response );
119
120         assertEquals( "Expected file contents", expectedMetadataContents, response.getText() );
121     }
122
123     @Test
124     public void testGetNoProxyProjectMetadataDefaultLayout()
125         throws Exception
126     {
127         String commonsLangMetadata = "commons-lang/commons-lang/maven-metadata.xml";
128         String expectedMetadataContents = "dummy-project-metadata";
129
130         File metadataFile = new File( repoRootInternal, commonsLangMetadata );
131         metadataFile.getParentFile().mkdirs();
132
133         FileUtils.writeStringToFile( metadataFile, expectedMetadataContents, null );
134
135         WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangMetadata );
136         WebResponse response = getServletUnitClient().getResponse( request );
137         assertResponseOK( response );
138
139         assertEquals( "Expected file contents", expectedMetadataContents, response.getText() );
140     }
141
142     @Test
143     public void testGetNoProxyGroupMetadataDefaultLayout()
144         throws Exception
145     {
146         String commonsLangMetadata = "commons-lang/maven-metadata.xml";
147         String expectedMetadataContents = "dummy-group-metadata";
148
149         File metadataFile = new File( repoRootInternal, commonsLangMetadata );
150         metadataFile.getParentFile().mkdirs();
151
152         FileUtils.writeStringToFile( metadataFile, expectedMetadataContents, null );
153
154         WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangMetadata );
155         WebResponse response = getServletUnitClient().getResponse( request );
156         assertResponseOK( response );
157
158         assertEquals( "Expected file contents", expectedMetadataContents, response.getText() );
159     }
160
161     @Test
162     public void testGetNoProxyArtifactDefaultLayout()
163         throws Exception
164     {
165         String commonsLangJar = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar";
166         String expectedArtifactContents = "dummy-commons-lang-artifact";
167
168         File artifactFile = new File( repoRootInternal, commonsLangJar );
169         artifactFile.getParentFile().mkdirs();
170
171         FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null );
172
173         WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangJar );
174         WebResponse response = getServletUnitClient().getResponse( request );
175         assertResponseOK( response );
176
177         assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
178     }
179
180     @Test
181     public void testGetNoProxyArtifactLegacyLayout()
182         throws Exception
183     {
184         String commonsLangJar = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar";
185         String expectedArtifactContents = "dummy-commons-lang-artifact";
186
187         File artifactFile = new File( repoRootInternal, commonsLangJar );
188         artifactFile.getParentFile().mkdirs();
189
190         FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null );
191
192         WebRequest request = new GetMethodWebRequest(
193             "http://machine.com/repository/internal/" + "commons-lang/jars/commons-lang-2.1.jar" );
194         WebResponse response = getServletUnitClient().getResponse( request );
195         assertResponseOK( response );
196
197         assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
198     }
199
200     @Test
201     public void testGetNoProxySnapshotArtifactDefaultLayout()
202         throws Exception
203     {
204         String commonsLangJar = "commons-lang/commons-lang/2.1-SNAPSHOT/commons-lang-2.1-SNAPSHOT.jar";
205         String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
206
207         File artifactFile = new File( repoRootInternal, commonsLangJar );
208         artifactFile.getParentFile().mkdirs();
209
210         FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null );
211
212         WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangJar );
213         WebResponse response = getServletUnitClient().getResponse( request );
214         assertResponseOK( response );
215
216         assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
217     }
218
219     @Test
220     public void testGetNoProxySnapshotArtifactLegacyLayout()
221         throws Exception
222     {
223         String commonsLangJar = "commons-lang/commons-lang/2.1-SNAPSHOT/commons-lang-2.1-SNAPSHOT.jar";
224         String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
225
226         File artifactFile = new File( repoRootInternal, commonsLangJar );
227         artifactFile.getParentFile().mkdirs();
228
229         FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null );
230
231         WebRequest request = new GetMethodWebRequest(
232             "http://machine.com/repository/internal/" + "commons-lang/jars/commons-lang-2.1-SNAPSHOT.jar" );
233         WebResponse response = getServletUnitClient().getResponse( request );
234         assertResponseOK( response );
235
236         assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
237     }
238
239     @Test
240     public void testGetNoProxyTimestampedSnapshotArtifactDefaultLayout()
241         throws Exception
242     {
243         String commonsLangJar = "commons-lang/commons-lang/2.1-SNAPSHOT/commons-lang-2.1-20050821.023400-1.jar";
244         String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
245
246         File artifactFile = new File( repoRootInternal, commonsLangJar );
247         artifactFile.getParentFile().mkdirs();
248
249         FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null );
250
251         WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangJar );
252         WebResponse response = getServletUnitClient().getResponse( request );
253         assertResponseOK( response );
254
255         assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
256     }
257
258     @Test
259     public void testGetNoProxyTimestampedSnapshotArtifactLegacyLayout()
260         throws Exception
261     {
262         String commonsLangJar = "commons-lang/commons-lang/2.1-SNAPSHOT/commons-lang-2.1-20050821.023400-1.jar";
263         String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
264
265         File artifactFile = new File( repoRootInternal, commonsLangJar );
266         artifactFile.getParentFile().mkdirs();
267
268         FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null );
269
270         WebRequest request = new GetMethodWebRequest(
271             "http://machine.com/repository/internal/" + "commons-lang/jars/commons-lang-2.1-20050821.023400-1.jar" );
272         WebResponse response = getServletUnitClient().getResponse( request );
273         assertResponseOK( response );
274
275         assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
276     }
277
278     /**
279      * [MRM-481] Artifact requests with a .xml.zip extension fail with a 404 Error
280      */
281     @Test
282     public void testGetNoProxyDualExtensionDefaultLayout()
283         throws Exception
284     {
285         String expectedContents = "the-contents-of-the-dual-extension";
286         String dualExtensionPath = "org/project/example-presentation/3.2/example-presentation-3.2.xml.zip";
287
288         File checksumFile = new File( repoRootInternal, dualExtensionPath );
289         checksumFile.getParentFile().mkdirs();
290
291         FileUtils.writeStringToFile( checksumFile, expectedContents, null );
292
293         WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + dualExtensionPath );
294         WebResponse response = getServletUnitClient().getResponse( request );
295         assertResponseOK( response );
296
297         assertEquals( "Expected file contents", expectedContents, response.getText() );
298     }
299
300     @Test
301     public void testGetNoProxyDistributionLegacyLayout()
302         throws Exception
303     {
304         String expectedContents = "the-contents-of-the-dual-extension";
305         String dualExtensionPath = "org/project/example-presentation/3.2/example-presentation-3.2.zip";
306
307         File checksumFile = new File( repoRootInternal, dualExtensionPath );
308         checksumFile.getParentFile().mkdirs();
309
310         FileUtils.writeStringToFile( checksumFile, expectedContents, null );
311
312         WebRequest request = new GetMethodWebRequest(
313             "http://machine.com/repository/internal/" + "org.project/distributions/example-presentation-3.2.zip" );
314         WebResponse response = getServletUnitClient().getResponse( request );
315         assertResponseOK( response );
316
317         assertEquals( "Expected file contents", expectedContents, response.getText() );
318     }
319
320     @Test
321     public void testGetNoProxyChecksumDefaultLayoutManagedLegacy()
322         throws Exception
323     {
324         String commonsLangSha1 = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar.sha1";
325
326         File checksumFile = new File( repoRootLegacy, "commons-lang/jars/commons-lang-2.1.jar.sha1" );
327         checksumFile.getParentFile().mkdirs();
328
329         FileUtils.writeStringToFile( checksumFile, "dummy-checksum", null );
330
331         WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangSha1 );
332         WebResponse response = getServletUnitClient().getResponse( request );
333         assertResponseOK( response );
334
335         assertEquals( "Expected file contents", "dummy-checksum", response.getText() );
336     }
337
338     @Test
339     public void testGetNoProxyChecksumLegacyLayoutManagedLegacy()
340         throws Exception
341     {
342         String commonsLangSha1 = "commons-lang/jars/commons-lang-2.1.jar.sha1";
343         File checksumFile = new File( repoRootLegacy, commonsLangSha1 );
344         checksumFile.getParentFile().mkdirs();
345
346         FileUtils.writeStringToFile( checksumFile, "dummy-checksum", null );
347
348         WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangSha1 );
349         WebResponse response = getServletUnitClient().getResponse( request );
350         assertResponseOK( response );
351
352         assertEquals( "Expected file contents", "dummy-checksum", response.getText() );
353     }
354
355     @Test
356     public void testGetNoProxyVersionedMetadataDefaultLayoutManagedLegacy()
357         throws Exception
358     {
359         String commonsLangMetadata = "commons-lang/commons-lang/2.1/maven-metadata.xml";
360         String expectedMetadataContents = "dummy-versioned-metadata";
361
362         // TODO: find out what this should be from maven-artifact
363         File metadataFile = new File( repoRootLegacy, commonsLangMetadata );
364         metadataFile.getParentFile().mkdirs();
365
366         FileUtils.writeStringToFile( metadataFile, expectedMetadataContents, null );
367
368         WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangMetadata );
369         WebResponse response = getServletUnitClient().getResponse( request );
370         assertResponseOK( response );
371
372         assertEquals( "Expected file contents", expectedMetadataContents, response.getText() );
373     }
374
375     @Test
376     public void testGetNoProxyProjectMetadataDefaultLayoutManagedLegacy()
377         throws Exception
378     {
379         // TODO: find out what it is meant to be from maven-artifact
380         String commonsLangMetadata = "commons-lang/commons-lang/maven-metadata.xml";
381         String expectedMetadataContents = "dummy-project-metadata";
382
383         File metadataFile = new File( repoRootLegacy, commonsLangMetadata );
384         metadataFile.getParentFile().mkdirs();
385
386         FileUtils.writeStringToFile( metadataFile, expectedMetadataContents, null );
387
388         WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangMetadata );
389         WebResponse response = getServletUnitClient().getResponse( request );
390         assertResponseOK( response );
391
392         assertEquals( "Expected file contents", expectedMetadataContents, response.getText() );
393     }
394
395     @Test
396     public void testGetNoProxyGroupMetadataDefaultLayoutManagedLegacy()
397         throws Exception
398     {
399         String commonsLangMetadata = "commons-lang/maven-metadata.xml";
400         String expectedMetadataContents = "dummy-group-metadata";
401
402         File metadataFile = new File( repoRootLegacy, commonsLangMetadata );
403         metadataFile.getParentFile().mkdirs();
404
405         FileUtils.writeStringToFile( metadataFile, expectedMetadataContents, null );
406
407         WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangMetadata );
408         WebResponse response = getServletUnitClient().getResponse( request );
409         assertResponseOK( response );
410
411         assertEquals( "Expected file contents", expectedMetadataContents, response.getText() );
412     }
413
414     @Test
415     public void testGetNoProxyArtifactDefaultLayoutManagedLegacy()
416         throws Exception
417     {
418         String commonsLangJar = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar";
419         String expectedArtifactContents = "dummy-commons-lang-artifact";
420
421         File artifactFile = new File( repoRootLegacy, "commons-lang/jars/commons-lang-2.1.jar" );
422         artifactFile.getParentFile().mkdirs();
423
424         FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null );
425
426         WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangJar );
427         WebResponse response = getServletUnitClient().getResponse( request );
428         assertResponseOK( response );
429
430         assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
431     }
432
433     @Test
434     public void testGetNoProxyArtifactLegacyLayoutManagedLegacy()
435         throws Exception
436     {
437         String commonsLangJar = "commons-lang/jars/commons-lang-2.1.jar";
438         String expectedArtifactContents = "dummy-commons-lang-artifact";
439
440         File artifactFile = new File( repoRootLegacy, commonsLangJar );
441         artifactFile.getParentFile().mkdirs();
442
443         FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null );
444
445         WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangJar );
446         WebResponse response = getServletUnitClient().getResponse( request );
447         assertResponseOK( response );
448
449         assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
450     }
451
452     @Test
453     public void testGetNoProxySnapshotArtifactDefaultLayoutManagedLegacy()
454         throws Exception
455     {
456         String commonsLangJar = "commons-lang/commons-lang/2.1-SNAPSHOT/commons-lang-2.1-SNAPSHOT.jar";
457         String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
458
459         File artifactFile = new File( repoRootLegacy, "commons-lang/jars/commons-lang-2.1-SNAPSHOT.jar" );
460         artifactFile.getParentFile().mkdirs();
461
462         FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null );
463
464         WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangJar );
465         WebResponse response = getServletUnitClient().getResponse( request );
466         assertResponseOK( response );
467
468         assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
469     }
470
471     @Test
472     public void testGetNoProxySnapshotArtifactLegacyLayoutManagedLegacy()
473         throws Exception
474     {
475         String commonsLangJar = "commons-lang/jars/commons-lang-2.1-SNAPSHOT.jar";
476         String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
477
478         File artifactFile = new File( repoRootLegacy, commonsLangJar );
479         artifactFile.getParentFile().mkdirs();
480
481         FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null );
482
483         WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangJar );
484         WebResponse response = getServletUnitClient().getResponse( request );
485         assertResponseOK( response );
486
487         assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
488     }
489
490     @Test
491     public void testGetNoProxyTimestampedSnapshotArtifactDefaultLayoutManagedLegacy()
492         throws Exception
493     {
494         String filename = "commons-lang-2.1-20050821.023400-1.jar";
495         String commonsLangJar = "commons-lang/commons-lang/2.1-SNAPSHOT/" + filename;
496         String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
497
498         File artifactFile = new File( repoRootLegacy, "commons-lang/jars/" + filename );
499         artifactFile.getParentFile().mkdirs();
500
501         FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null );
502
503         WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangJar );
504         WebResponse response = getServletUnitClient().getResponse( request );
505         assertResponseOK( response );
506
507         assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
508     }
509
510     @Test
511     public void testGetNoProxyTimestampedSnapshotArtifactLegacyLayoutManagedLegacy()
512         throws Exception
513     {
514         String commonsLangJar = "commons-lang/jars/commons-lang-2.1-20050821.023400-1.jar";
515         String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
516
517         File artifactFile = new File( repoRootLegacy, commonsLangJar );
518         artifactFile.getParentFile().mkdirs();
519
520         FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null );
521
522         WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangJar );
523         WebResponse response = getServletUnitClient().getResponse( request );
524         assertResponseOK( response );
525
526         assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
527     }
528
529     /**
530      * [MRM-481] Artifact requests with a .xml.zip extension fail with a 404 Error
531      */
532     @Test
533     public void testGetNoProxyDualExtensionDefaultLayoutManagedLegacy()
534         throws Exception
535     {
536         String expectedContents = "the-contents-of-the-dual-extension";
537         String dualExtensionPath = "org/project/example-presentation/3.2/example-presentation-3.2.xml.zip";
538
539         File checksumFile = new File( repoRootLegacy, "org.project/distributions/example-presentation-3.2.xml.zip" );
540         checksumFile.getParentFile().mkdirs();
541
542         FileUtils.writeStringToFile( checksumFile, expectedContents, null );
543
544         WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + dualExtensionPath );
545         WebResponse response = getServletUnitClient().getResponse( request );
546         assertResponseOK( response );
547
548         assertEquals( "Expected file contents", expectedContents, response.getText() );
549     }
550
551     @Test
552     public void testGetNoProxyDistributionLegacyLayoutManagedLegacy()
553         throws Exception
554     {
555         String expectedContents = "the-contents-of-the-dual-extension";
556         String dualExtensionPath = "org.project/distributions/example-presentation-3.2.zip";
557
558         File checksumFile = new File( repoRootLegacy, dualExtensionPath );
559         checksumFile.getParentFile().mkdirs();
560
561         FileUtils.writeStringToFile( checksumFile, expectedContents, null );
562
563         WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + dualExtensionPath );
564         WebResponse response = getServletUnitClient().getResponse( request );
565         assertResponseOK( response );
566
567         assertEquals( "Expected file contents", expectedContents, response.getText() );
568     }
569
570 }