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