1 package org.apache.archiva.webdav;
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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
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;
31 import java.nio.charset.Charset;
32 import java.util.ArrayList;
35 * RepositoryServletTest
39 public class RepositoryServletNoProxyTest
40 extends AbstractRepositoryServletTestCase
49 archivaConfiguration.getConfiguration().setProxyConnectors( new ArrayList<ProxyConnectorConfiguration>() );
54 public void testLastModifiedHeaderExists()
57 String commonsLangSha1 = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar.sha1";
59 File checksumFile = new File( repoRootInternal, commonsLangSha1 );
60 checksumFile.getParentFile().mkdirs();
62 FileUtils.writeStringToFile( checksumFile, "dummy-checksum", Charset.defaultCharset() );
64 //WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangSha1 );
65 WebResponse response = getWebResponse( "/repository/internal/" + commonsLangSha1 );
66 assertNotNull( response.getResponseHeaderValue( "Last-Modified" ) );
70 public void testGetNoProxyChecksumDefaultLayout()
73 String commonsLangSha1 = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar.sha1";
75 File checksumFile = new File( repoRootInternal, commonsLangSha1 );
76 checksumFile.getParentFile().mkdirs();
78 FileUtils.writeStringToFile( checksumFile, "dummy-checksum", Charset.defaultCharset() );
80 //WebRequest request = new WebRequest( "http://machine.com/repository/internal/" + commonsLangSha1 );
81 WebResponse response = getWebResponse( "/repository/internal/" + commonsLangSha1 );
82 assertResponseOK( response );
84 assertEquals( "Expected file contents", "dummy-checksum", response.getContentAsString() );
88 public void testGetNoProxyChecksumLegacyLayout()
91 String commonsLangSha1 = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar.sha1";
93 File checksumFile = new File( repoRootInternal, commonsLangSha1 );
94 checksumFile.getParentFile().mkdirs();
96 FileUtils.writeStringToFile( checksumFile, "dummy-checksum", Charset.defaultCharset() );
98 //WebRequest request = new GetMethodWebRequest(
99 // "http://machine.com/repository/internal/" + "commons-lang/jars/commons-lang-2.1.jar.sha1" );
100 WebResponse response = getWebResponse( "/repository/internal/" + "commons-lang/jars/commons-lang-2.1.jar.sha1" );
101 assertResponseOK( response );
103 assertEquals( "Expected file contents", "dummy-checksum", response.getContentAsString() );
107 public void testGetNoProxyVersionedMetadataDefaultLayout()
110 String commonsLangMetadata = "commons-lang/commons-lang/2.1/maven-metadata.xml";
111 String expectedMetadataContents = "dummy-versioned-metadata";
113 File metadataFile = new File( repoRootInternal, commonsLangMetadata );
114 metadataFile.getParentFile().mkdirs();
116 FileUtils.writeStringToFile( metadataFile, expectedMetadataContents, Charset.defaultCharset() );
118 //WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangMetadata );
119 WebResponse response = getWebResponse( "/repository/internal/" + commonsLangMetadata );
120 assertResponseOK( response );
122 assertEquals( "Expected file contents", expectedMetadataContents, response.getContentAsString() );
126 public void testGetNoProxyProjectMetadataDefaultLayout()
129 String commonsLangMetadata = "commons-lang/commons-lang/maven-metadata.xml";
130 String expectedMetadataContents = "dummy-project-metadata";
132 File metadataFile = new File( repoRootInternal, commonsLangMetadata );
133 metadataFile.getParentFile().mkdirs();
135 FileUtils.writeStringToFile( metadataFile, expectedMetadataContents, Charset.defaultCharset() );
137 //WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangMetadata );
138 WebResponse response = getWebResponse( "/repository/internal/" + commonsLangMetadata );
139 assertResponseOK( response );
141 assertEquals( "Expected file contents", expectedMetadataContents, response.getContentAsString() );
145 public void testGetNoProxyGroupMetadataDefaultLayout()
148 String commonsLangMetadata = "commons-lang/maven-metadata.xml";
149 String expectedMetadataContents = "dummy-group-metadata";
151 File metadataFile = new File( repoRootInternal, commonsLangMetadata );
152 metadataFile.getParentFile().mkdirs();
154 FileUtils.writeStringToFile( metadataFile, expectedMetadataContents, Charset.defaultCharset() );
156 //WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangMetadata );
157 WebResponse response = getWebResponse( "/repository/internal/" + commonsLangMetadata );
158 assertResponseOK( response );
160 assertEquals( "Expected file contents", expectedMetadataContents, response.getContentAsString() );
164 public void testGetNoProxyArtifactDefaultLayout()
167 String commonsLangJar = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar";
168 String expectedArtifactContents = "dummy-commons-lang-artifact";
170 File artifactFile = new File( repoRootInternal, commonsLangJar );
171 artifactFile.getParentFile().mkdirs();
173 FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, Charset.defaultCharset() );
175 //WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangJar );
176 WebResponse response = getWebResponse( "/repository/internal/" + commonsLangJar );
177 assertResponseOK( response );
179 assertEquals( "Expected file contents", expectedArtifactContents, response.getContentAsString() );
183 public void testGetNoProxyArtifactLegacyLayout()
186 String commonsLangJar = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar";
187 String expectedArtifactContents = "dummy-commons-lang-artifact";
189 File artifactFile = new File( repoRootInternal, commonsLangJar );
190 artifactFile.getParentFile().mkdirs();
192 FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, Charset.defaultCharset() );
194 //WebRequest request = new GetMethodWebRequest(
195 // "http://machine.com/repository/internal/" + "commons-lang/jars/commons-lang-2.1.jar" );
196 WebResponse response = getWebResponse( "/repository/internal/" + "commons-lang/jars/commons-lang-2.1.jar" );
197 assertResponseOK( response );
199 assertEquals( "Expected file contents", expectedArtifactContents, response.getContentAsString() );
203 public void testGetNoProxySnapshotArtifactDefaultLayout()
206 String commonsLangJar = "commons-lang/commons-lang/2.1-SNAPSHOT/commons-lang-2.1-SNAPSHOT.jar";
207 String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
209 File artifactFile = new File( repoRootInternal, commonsLangJar );
210 artifactFile.getParentFile().mkdirs();
212 FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, Charset.defaultCharset() );
214 //WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangJar );
215 WebResponse response = getWebResponse( "/repository/internal/" + commonsLangJar );
216 assertResponseOK( response );
218 assertEquals( "Expected file contents", expectedArtifactContents, response.getContentAsString() );
222 public void testGetNoProxySnapshotArtifactLegacyLayout()
225 String commonsLangJar = "commons-lang/commons-lang/2.1-SNAPSHOT/commons-lang-2.1-SNAPSHOT.jar";
226 String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
228 File artifactFile = new File( repoRootInternal, commonsLangJar );
229 artifactFile.getParentFile().mkdirs();
231 FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, Charset.defaultCharset() );
233 //WebRequest request = new GetMethodWebRequest(
234 // "http://machine.com/repository/internal/" + "commons-lang/jars/commons-lang-2.1-SNAPSHOT.jar" );
235 WebResponse response = getWebResponse( "/repository/internal/commons-lang/jars/commons-lang-2.1-SNAPSHOT.jar" );
236 assertResponseOK( response );
238 assertEquals( "Expected file contents", expectedArtifactContents, response.getContentAsString() );
242 public void testGetNoProxyTimestampedSnapshotArtifactDefaultLayout()
245 String commonsLangJar = "commons-lang/commons-lang/2.1-SNAPSHOT/commons-lang-2.1-20050821.023400-1.jar";
246 String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
248 File artifactFile = new File( repoRootInternal, commonsLangJar );
249 artifactFile.getParentFile().mkdirs();
251 FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, Charset.defaultCharset() );
253 //WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangJar );
254 WebResponse response = getWebResponse( "/repository/internal/" + commonsLangJar );
255 assertResponseOK( response );
257 assertEquals( "Expected file contents", expectedArtifactContents, response.getContentAsString() );
261 public void testGetNoProxyTimestampedSnapshotArtifactLegacyLayout()
264 String commonsLangJar = "commons-lang/commons-lang/2.1-SNAPSHOT/commons-lang-2.1-20050821.023400-1.jar";
265 String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
267 File artifactFile = new File( repoRootInternal, commonsLangJar );
268 artifactFile.getParentFile().mkdirs();
270 FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, Charset.defaultCharset() );
272 WebRequest request = new GetMethodWebRequest(
273 "http://machine.com/repository/internal/" + "commons-lang/jars/commons-lang-2.1-20050821.023400-1.jar" );
274 WebResponse response = getServletUnitClient().getResponse( request );
275 assertResponseOK( response );
277 assertEquals( "Expected file contents", expectedArtifactContents, response.getContentAsString() );
281 * [MRM-481] Artifact requests with a .xml.zip extension fail with a 404 Error
284 public void testGetNoProxyDualExtensionDefaultLayout()
287 String expectedContents = "the-contents-of-the-dual-extension";
288 String dualExtensionPath = "org/project/example-presentation/3.2/example-presentation-3.2.xml.zip";
290 File checksumFile = new File( repoRootInternal, dualExtensionPath );
291 checksumFile.getParentFile().mkdirs();
293 FileUtils.writeStringToFile( checksumFile, expectedContents, Charset.defaultCharset() );
295 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + dualExtensionPath );
296 WebResponse response = getServletUnitClient().getResponse( request );
297 assertResponseOK( response );
299 assertEquals( "Expected file contents", expectedContents, response.getContentAsString() );
303 public void testGetNoProxyDistributionLegacyLayout()
306 String expectedContents = "the-contents-of-the-dual-extension";
307 String dualExtensionPath = "org/project/example-presentation/3.2/example-presentation-3.2.zip";
309 File checksumFile = new File( repoRootInternal, dualExtensionPath );
310 checksumFile.getParentFile().mkdirs();
312 FileUtils.writeStringToFile( checksumFile, expectedContents, Charset.defaultCharset() );
314 WebRequest request = new GetMethodWebRequest(
315 "http://machine.com/repository/internal/" + "org.project/distributions/example-presentation-3.2.zip" );
316 WebResponse response = getServletUnitClient().getResponse( request );
317 assertResponseOK( response );
319 assertEquals( "Expected file contents", expectedContents, response.getContentAsString() );
323 public void testGetNoProxyChecksumDefaultLayoutManagedLegacy()
326 String commonsLangSha1 = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar.sha1";
328 File checksumFile = new File( repoRootLegacy, "commons-lang/jars/commons-lang-2.1.jar.sha1" );
329 checksumFile.getParentFile().mkdirs();
331 FileUtils.writeStringToFile( checksumFile, "dummy-checksum", Charset.defaultCharset() );
333 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangSha1 );
334 WebResponse response = getServletUnitClient().getResponse( request );
335 assertResponseOK( response );
337 assertEquals( "Expected file contents", "dummy-checksum", response.getContentAsString() );
341 public void testGetNoProxyChecksumLegacyLayoutManagedLegacy()
344 String commonsLangSha1 = "commons-lang/jars/commons-lang-2.1.jar.sha1";
345 File checksumFile = new File( repoRootLegacy, commonsLangSha1 );
346 checksumFile.getParentFile().mkdirs();
348 FileUtils.writeStringToFile( checksumFile, "dummy-checksum", Charset.defaultCharset() );
350 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangSha1 );
351 WebResponse response = getServletUnitClient().getResponse( request );
352 assertResponseOK( response );
354 assertEquals( "Expected file contents", "dummy-checksum", response.getContentAsString() );
358 public void testGetNoProxyVersionedMetadataDefaultLayoutManagedLegacy()
361 String commonsLangMetadata = "commons-lang/commons-lang/2.1/maven-metadata.xml";
362 String expectedMetadataContents = "dummy-versioned-metadata";
364 // TODO: find out what this should be from maven-artifact
365 File metadataFile = new File( repoRootLegacy, commonsLangMetadata );
366 metadataFile.getParentFile().mkdirs();
368 FileUtils.writeStringToFile( metadataFile, expectedMetadataContents, Charset.defaultCharset() );
370 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangMetadata );
371 WebResponse response = getServletUnitClient().getResponse( request );
372 assertResponseOK( response );
374 assertEquals( "Expected file contents", expectedMetadataContents, response.getContentAsString() );
378 public void testGetNoProxyProjectMetadataDefaultLayoutManagedLegacy()
381 // TODO: find out what it is meant to be from maven-artifact
382 String commonsLangMetadata = "commons-lang/commons-lang/maven-metadata.xml";
383 String expectedMetadataContents = "dummy-project-metadata";
385 File metadataFile = new File( repoRootLegacy, commonsLangMetadata );
386 metadataFile.getParentFile().mkdirs();
388 FileUtils.writeStringToFile( metadataFile, expectedMetadataContents, Charset.defaultCharset() );
390 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangMetadata );
391 WebResponse response = getServletUnitClient().getResponse( request );
392 assertResponseOK( response );
394 assertEquals( "Expected file contents", expectedMetadataContents, response.getContentAsString() );
398 public void testGetNoProxyGroupMetadataDefaultLayoutManagedLegacy()
401 String commonsLangMetadata = "commons-lang/maven-metadata.xml";
402 String expectedMetadataContents = "dummy-group-metadata";
404 File metadataFile = new File( repoRootLegacy, commonsLangMetadata );
405 metadataFile.getParentFile().mkdirs();
407 FileUtils.writeStringToFile( metadataFile, expectedMetadataContents, Charset.defaultCharset() );
409 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangMetadata );
410 WebResponse response = getServletUnitClient().getResponse( request );
411 assertResponseOK( response );
413 assertEquals( "Expected file contents", expectedMetadataContents, response.getContentAsString() );
417 public void testGetNoProxyArtifactDefaultLayoutManagedLegacy()
420 String commonsLangJar = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar";
421 String expectedArtifactContents = "dummy-commons-lang-artifact";
423 File artifactFile = new File( repoRootLegacy, "commons-lang/jars/commons-lang-2.1.jar" );
424 artifactFile.getParentFile().mkdirs();
426 FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, Charset.defaultCharset() );
428 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangJar );
429 WebResponse response = getServletUnitClient().getResponse( request );
430 assertResponseOK( response );
432 assertEquals( "Expected file contents", expectedArtifactContents, response.getContentAsString() );
436 public void testGetNoProxyArtifactLegacyLayoutManagedLegacy()
439 String commonsLangJar = "commons-lang/jars/commons-lang-2.1.jar";
440 String expectedArtifactContents = "dummy-commons-lang-artifact";
442 File artifactFile = new File( repoRootLegacy, commonsLangJar );
443 artifactFile.getParentFile().mkdirs();
445 FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, Charset.defaultCharset() );
447 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangJar );
448 WebResponse response = getServletUnitClient().getResponse( request );
449 assertResponseOK( response );
451 assertEquals( "Expected file contents", expectedArtifactContents, response.getContentAsString() );
455 public void testGetNoProxySnapshotArtifactDefaultLayoutManagedLegacy()
458 String commonsLangJar = "commons-lang/commons-lang/2.1-SNAPSHOT/commons-lang-2.1-SNAPSHOT.jar";
459 String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
461 File artifactFile = new File( repoRootLegacy, "commons-lang/jars/commons-lang-2.1-SNAPSHOT.jar" );
462 artifactFile.getParentFile().mkdirs();
464 FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, Charset.defaultCharset() );
466 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangJar );
467 WebResponse response = getServletUnitClient().getResponse( request );
468 assertResponseOK( response );
470 assertEquals( "Expected file contents", expectedArtifactContents, response.getContentAsString() );
474 public void testGetNoProxySnapshotArtifactLegacyLayoutManagedLegacy()
477 String commonsLangJar = "commons-lang/jars/commons-lang-2.1-SNAPSHOT.jar";
478 String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
480 File artifactFile = new File( repoRootLegacy, commonsLangJar );
481 artifactFile.getParentFile().mkdirs();
483 FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, Charset.defaultCharset() );
485 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangJar );
486 WebResponse response = getServletUnitClient().getResponse( request );
487 assertResponseOK( response );
489 assertEquals( "Expected file contents", expectedArtifactContents, response.getContentAsString() );
493 public void testGetNoProxyTimestampedSnapshotArtifactDefaultLayoutManagedLegacy()
496 String filename = "commons-lang-2.1-20050821.023400-1.jar";
497 String commonsLangJar = "commons-lang/commons-lang/2.1-SNAPSHOT/" + filename;
498 String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
500 File artifactFile = new File( repoRootLegacy, "commons-lang/jars/" + filename );
501 artifactFile.getParentFile().mkdirs();
503 FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, Charset.defaultCharset() );
505 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangJar );
506 WebResponse response = getServletUnitClient().getResponse( request );
507 assertResponseOK( response );
509 assertEquals( "Expected file contents", expectedArtifactContents, response.getContentAsString() );
513 public void testGetNoProxyTimestampedSnapshotArtifactLegacyLayoutManagedLegacy()
516 String commonsLangJar = "commons-lang/jars/commons-lang-2.1-20050821.023400-1.jar";
517 String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
519 File artifactFile = new File( repoRootLegacy, commonsLangJar );
520 artifactFile.getParentFile().mkdirs();
522 FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, Charset.defaultCharset() );
524 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangJar );
525 WebResponse response = getServletUnitClient().getResponse( request );
526 assertResponseOK( response );
528 assertEquals( "Expected file contents", expectedArtifactContents, response.getContentAsString() );
532 * [MRM-481] Artifact requests with a .xml.zip extension fail with a 404 Error
535 public void testGetNoProxyDualExtensionDefaultLayoutManagedLegacy()
538 String expectedContents = "the-contents-of-the-dual-extension";
539 String dualExtensionPath = "org/project/example-presentation/3.2/example-presentation-3.2.xml.zip";
541 File checksumFile = new File( repoRootLegacy, "org.project/distributions/example-presentation-3.2.xml.zip" );
542 checksumFile.getParentFile().mkdirs();
544 FileUtils.writeStringToFile( checksumFile, expectedContents, Charset.defaultCharset() );
546 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + dualExtensionPath );
547 WebResponse response = getServletUnitClient().getResponse( request );
548 assertResponseOK( response );
550 assertEquals( "Expected file contents", expectedContents, response.getContentAsString() );
554 public void testGetNoProxyDistributionLegacyLayoutManagedLegacy()
557 String expectedContents = "the-contents-of-the-dual-extension";
558 String dualExtensionPath = "org.project/distributions/example-presentation-3.2.zip";
560 File checksumFile = new File( repoRootLegacy, dualExtensionPath );
561 checksumFile.getParentFile().mkdirs();
563 FileUtils.writeStringToFile( checksumFile, expectedContents, Charset.defaultCharset() );
565 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + dualExtensionPath );
566 WebResponse response = getServletUnitClient().getResponse( request );
567 assertResponseOK( response );
569 assertEquals( "Expected file contents", expectedContents, response.getContentAsString() );