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
37 public class RepositoryServletNoProxyTest
38 extends AbstractRepositoryServletTestCase
47 archivaConfiguration.getConfiguration().setProxyConnectors( new ArrayList<ProxyConnectorConfiguration>() );
52 public void testLastModifiedHeaderExists()
55 String commonsLangSha1 = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar.sha1";
57 File checksumFile = new File( repoRootInternal, commonsLangSha1 );
58 checksumFile.getParentFile().mkdirs();
60 FileUtils.writeStringToFile( checksumFile, "dummy-checksum", Charset.defaultCharset() );
62 //WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangSha1 );
63 WebResponse response = getWebResponse( "/repository/internal/" + commonsLangSha1 );
64 assertNotNull( response.getResponseHeaderValue( "Last-Modified" ) );
68 public void testGetNoProxyChecksumDefaultLayout()
71 String commonsLangSha1 = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar.sha1";
73 File checksumFile = new File( repoRootInternal, commonsLangSha1 );
74 checksumFile.getParentFile().mkdirs();
76 FileUtils.writeStringToFile( checksumFile, "dummy-checksum", Charset.defaultCharset() );
78 //WebRequest request = new WebRequest( "http://machine.com/repository/internal/" + commonsLangSha1 );
79 WebResponse response = getWebResponse( "/repository/internal/" + commonsLangSha1 );
80 assertResponseOK( response );
82 assertEquals( "Expected file contents", "dummy-checksum", response.getContentAsString() );
86 public void testGetNoProxyChecksumLegacyLayout()
89 String commonsLangSha1 = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar.sha1";
91 File checksumFile = new File( repoRootInternal, commonsLangSha1 );
92 checksumFile.getParentFile().mkdirs();
94 FileUtils.writeStringToFile( checksumFile, "dummy-checksum", Charset.defaultCharset() );
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 );
104 public void testGetNoProxyVersionedMetadataDefaultLayout()
107 String commonsLangMetadata = "commons-lang/commons-lang/2.1/maven-metadata.xml";
108 String expectedMetadataContents = "dummy-versioned-metadata";
110 File metadataFile = new File( repoRootInternal, commonsLangMetadata );
111 metadataFile.getParentFile().mkdirs();
113 FileUtils.writeStringToFile( metadataFile, expectedMetadataContents, Charset.defaultCharset() );
115 //WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangMetadata );
116 WebResponse response = getWebResponse( "/repository/internal/" + commonsLangMetadata );
117 assertResponseOK( response );
119 assertEquals( "Expected file contents", expectedMetadataContents, response.getContentAsString() );
123 public void testGetNoProxyProjectMetadataDefaultLayout()
126 String commonsLangMetadata = "commons-lang/commons-lang/maven-metadata.xml";
127 String expectedMetadataContents = "dummy-project-metadata";
129 File metadataFile = new File( repoRootInternal, commonsLangMetadata );
130 metadataFile.getParentFile().mkdirs();
132 FileUtils.writeStringToFile( metadataFile, expectedMetadataContents, Charset.defaultCharset() );
134 //WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangMetadata );
135 WebResponse response = getWebResponse( "/repository/internal/" + commonsLangMetadata );
136 assertResponseOK( response );
138 assertEquals( "Expected file contents", expectedMetadataContents, response.getContentAsString() );
142 public void testGetNoProxyGroupMetadataDefaultLayout()
145 String commonsLangMetadata = "commons-lang/maven-metadata.xml";
146 String expectedMetadataContents = "dummy-group-metadata";
148 File metadataFile = new File( repoRootInternal, commonsLangMetadata );
149 metadataFile.getParentFile().mkdirs();
151 FileUtils.writeStringToFile( metadataFile, expectedMetadataContents, Charset.defaultCharset() );
153 //WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangMetadata );
154 WebResponse response = getWebResponse( "/repository/internal/" + commonsLangMetadata );
155 assertResponseOK( response );
157 assertEquals( "Expected file contents", expectedMetadataContents, response.getContentAsString() );
161 public void testGetNoProxyArtifactDefaultLayout()
164 String commonsLangJar = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar";
165 String expectedArtifactContents = "dummy-commons-lang-artifact";
167 File artifactFile = new File( repoRootInternal, commonsLangJar );
168 artifactFile.getParentFile().mkdirs();
170 FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, Charset.defaultCharset() );
172 //WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangJar );
173 WebResponse response = getWebResponse( "/repository/internal/" + commonsLangJar );
174 assertResponseOK( response );
176 assertEquals( "Expected file contents", expectedArtifactContents, response.getContentAsString() );
180 public void testGetNoProxyArtifactLegacyLayout()
183 String commonsLangJar = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar";
184 String expectedArtifactContents = "dummy-commons-lang-artifact";
186 File artifactFile = new File( repoRootInternal, commonsLangJar );
187 artifactFile.getParentFile().mkdirs();
189 FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, Charset.defaultCharset() );
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 );
199 public void testGetNoProxySnapshotArtifactDefaultLayout()
202 String commonsLangJar = "commons-lang/commons-lang/2.1-SNAPSHOT/commons-lang-2.1-SNAPSHOT.jar";
203 String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
205 File artifactFile = new File( repoRootInternal, commonsLangJar );
206 artifactFile.getParentFile().mkdirs();
208 FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, Charset.defaultCharset() );
210 //WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangJar );
211 WebResponse response = getWebResponse( "/repository/internal/" + commonsLangJar );
212 assertResponseOK( response );
214 assertEquals( "Expected file contents", expectedArtifactContents, response.getContentAsString() );
218 public void testGetNoProxySnapshotArtifactLegacyLayout()
221 String commonsLangJar = "commons-lang/commons-lang/2.1-SNAPSHOT/commons-lang-2.1-SNAPSHOT.jar";
222 String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
224 File artifactFile = new File( repoRootInternal, commonsLangJar );
225 artifactFile.getParentFile().mkdirs();
227 FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, Charset.defaultCharset() );
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 );
234 assertEquals( "Expected file contents", expectedArtifactContents, response.getContentAsString() );
238 public void testGetNoProxyTimestampedSnapshotArtifactDefaultLayout()
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";
244 File artifactFile = new File( repoRootInternal, commonsLangJar );
245 artifactFile.getParentFile().mkdirs();
247 FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, Charset.defaultCharset() );
249 //WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangJar );
250 WebResponse response = getWebResponse( "/repository/internal/" + commonsLangJar );
251 assertResponseOK( response );
253 assertEquals( "Expected file contents", expectedArtifactContents, response.getContentAsString() );
257 public void testGetNoProxyTimestampedSnapshotArtifactLegacyLayout()
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";
263 File artifactFile = new File( repoRootInternal, commonsLangJar );
264 artifactFile.getParentFile().mkdirs();
266 FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, Charset.defaultCharset() );
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 );
275 * [MRM-481] Artifact requests with a .xml.zip extension fail with a 404 Error
278 public void testGetNoProxyDualExtensionDefaultLayout()
281 String expectedContents = "the-contents-of-the-dual-extension";
282 String dualExtensionPath = "org/project/example-presentation/3.2/example-presentation-3.2.xml.zip";
284 File checksumFile = new File( repoRootInternal, dualExtensionPath );
285 checksumFile.getParentFile().mkdirs();
287 FileUtils.writeStringToFile( checksumFile, expectedContents, Charset.defaultCharset() );
289 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + dualExtensionPath );
290 WebResponse response = getServletUnitClient().getResponse( request );
291 assertResponseOK( response );
293 assertEquals( "Expected file contents", expectedContents, response.getContentAsString() );
297 public void testGetNoProxyDistributionLegacyLayout()
300 String expectedContents = "the-contents-of-the-dual-extension";
301 String dualExtensionPath = "org/project/example-presentation/3.2/example-presentation-3.2.zip";
303 File checksumFile = new File( repoRootInternal, dualExtensionPath );
304 checksumFile.getParentFile().mkdirs();
306 FileUtils.writeStringToFile( checksumFile, expectedContents, Charset.defaultCharset() );
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 );
316 public void testGetNoProxyChecksumDefaultLayoutManagedLegacy()
319 String commonsLangSha1 = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar.sha1";
321 File checksumFile = new File( repoRootLegacy, "commons-lang/jars/commons-lang-2.1.jar.sha1" );
322 checksumFile.getParentFile().mkdirs();
324 FileUtils.writeStringToFile( checksumFile, "dummy-checksum", Charset.defaultCharset() );
326 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangSha1 );
327 WebResponse response = getServletUnitClient().getResponse( request );
328 assertResponseNotFound( response );
332 public void testGetNoProxyChecksumLegacyLayoutManagedLegacy()
335 String commonsLangSha1 = "commons-lang/jars/commons-lang-2.1.jar.sha1";
336 File checksumFile = new File( repoRootLegacy, commonsLangSha1 );
337 checksumFile.getParentFile().mkdirs();
339 FileUtils.writeStringToFile( checksumFile, "dummy-checksum", Charset.defaultCharset() );
341 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangSha1 );
342 WebResponse response = getServletUnitClient().getResponse( request );
343 assertResponseNotFound( response );
347 public void testGetNoProxyVersionedMetadataDefaultLayoutManagedLegacy()
350 String commonsLangMetadata = "commons-lang/commons-lang/2.1/maven-metadata.xml";
351 String expectedMetadataContents = "dummy-versioned-metadata";
353 // TODO: find out what this should be from maven-artifact
354 File metadataFile = new File( repoRootLegacy, commonsLangMetadata );
355 metadataFile.getParentFile().mkdirs();
357 FileUtils.writeStringToFile( metadataFile, expectedMetadataContents, Charset.defaultCharset() );
359 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangMetadata );
360 WebResponse response = getServletUnitClient().getResponse( request );
361 assertResponseNotFound( response );
365 public void testGetNoProxyProjectMetadataDefaultLayoutManagedLegacy()
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";
372 File metadataFile = new File( repoRootLegacy, commonsLangMetadata );
373 metadataFile.getParentFile().mkdirs();
375 FileUtils.writeStringToFile( metadataFile, expectedMetadataContents, Charset.defaultCharset() );
377 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangMetadata );
378 WebResponse response = getServletUnitClient().getResponse( request );
379 assertResponseNotFound( response );
383 public void testGetNoProxyGroupMetadataDefaultLayoutManagedLegacy()
386 String commonsLangMetadata = "commons-lang/maven-metadata.xml";
387 String expectedMetadataContents = "dummy-group-metadata";
389 File metadataFile = new File( repoRootLegacy, commonsLangMetadata );
390 metadataFile.getParentFile().mkdirs();
392 FileUtils.writeStringToFile( metadataFile, expectedMetadataContents, Charset.defaultCharset() );
394 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangMetadata );
395 WebResponse response = getServletUnitClient().getResponse( request );
396 assertResponseNotFound( response );
400 public void testGetNoProxyArtifactDefaultLayoutManagedLegacy()
403 String commonsLangJar = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar";
404 String expectedArtifactContents = "dummy-commons-lang-artifact";
406 File artifactFile = new File( repoRootLegacy, "commons-lang/jars/commons-lang-2.1.jar" );
407 artifactFile.getParentFile().mkdirs();
409 FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, Charset.defaultCharset() );
411 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangJar );
412 WebResponse response = getServletUnitClient().getResponse( request );
413 assertResponseNotFound( response );
417 public void testGetNoProxyArtifactLegacyLayoutManagedLegacy()
420 String commonsLangJar = "commons-lang/jars/commons-lang-2.1.jar";
421 String expectedArtifactContents = "dummy-commons-lang-artifact";
423 File artifactFile = new File( repoRootLegacy, commonsLangJar );
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 assertResponseNotFound( response );
434 public void testGetNoProxySnapshotArtifactDefaultLayoutManagedLegacy()
437 String commonsLangJar = "commons-lang/commons-lang/2.1-SNAPSHOT/commons-lang-2.1-SNAPSHOT.jar";
438 String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
440 File artifactFile = new File( repoRootLegacy, "commons-lang/jars/commons-lang-2.1-SNAPSHOT.jar" );
441 artifactFile.getParentFile().mkdirs();
443 FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, Charset.defaultCharset() );
445 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangJar );
446 WebResponse response = getServletUnitClient().getResponse( request );
447 assertResponseNotFound( response );
451 public void testGetNoProxySnapshotArtifactLegacyLayoutManagedLegacy()
454 String commonsLangJar = "commons-lang/jars/commons-lang-2.1-SNAPSHOT.jar";
455 String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
457 File artifactFile = new File( repoRootLegacy, commonsLangJar );
458 artifactFile.getParentFile().mkdirs();
460 FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, Charset.defaultCharset() );
462 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangJar );
463 WebResponse response = getServletUnitClient().getResponse( request );
464 assertResponseNotFound( response );
468 public void testGetNoProxyTimestampedSnapshotArtifactDefaultLayoutManagedLegacy()
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";
475 File artifactFile = new File( repoRootLegacy, "commons-lang/jars/" + filename );
476 artifactFile.getParentFile().mkdirs();
478 FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, Charset.defaultCharset() );
480 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangJar );
481 WebResponse response = getServletUnitClient().getResponse( request );
482 assertResponseNotFound( response );
486 public void testGetNoProxyTimestampedSnapshotArtifactLegacyLayoutManagedLegacy()
489 String commonsLangJar = "commons-lang/jars/commons-lang-2.1-20050821.023400-1.jar";
490 String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
492 File artifactFile = new File( repoRootLegacy, commonsLangJar );
493 artifactFile.getParentFile().mkdirs();
495 FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, Charset.defaultCharset() );
497 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangJar );
498 WebResponse response = getServletUnitClient().getResponse( request );
499 assertResponseNotFound( response );
503 * [MRM-481] Artifact requests with a .xml.zip extension fail with a 404 Error
506 public void testGetNoProxyDualExtensionDefaultLayoutManagedLegacy()
509 String expectedContents = "the-contents-of-the-dual-extension";
510 String dualExtensionPath = "org/project/example-presentation/3.2/example-presentation-3.2.xml.zip";
512 File checksumFile = new File( repoRootLegacy, "org.project/distributions/example-presentation-3.2.xml.zip" );
513 checksumFile.getParentFile().mkdirs();
515 FileUtils.writeStringToFile( checksumFile, expectedContents, Charset.defaultCharset() );
517 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + dualExtensionPath );
518 WebResponse response = getServletUnitClient().getResponse( request );
519 assertResponseNotFound( response );
523 public void testGetNoProxyDistributionLegacyLayoutManagedLegacy()
526 String expectedContents = "the-contents-of-the-dual-extension";
527 String dualExtensionPath = "org.project/distributions/example-presentation-3.2.zip";
529 File checksumFile = new File( repoRootLegacy, dualExtensionPath );
530 checksumFile.getParentFile().mkdirs();
532 FileUtils.writeStringToFile( checksumFile, expectedContents, Charset.defaultCharset() );
534 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + dualExtensionPath );
535 WebResponse response = getServletUnitClient().getResponse( request );
536 assertResponseNotFound( response );