1 package org.apache.maven.archiva.proxy;
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
22 import org.apache.commons.io.FileUtils;
23 import org.apache.maven.archiva.model.ArtifactReference;
24 import org.apache.maven.archiva.policies.CachedFailuresPolicy;
25 import org.apache.maven.archiva.policies.ChecksumPolicy;
26 import org.apache.maven.archiva.policies.ReleasesPolicy;
27 import org.apache.maven.archiva.policies.SnapshotsPolicy;
28 import org.apache.maven.wagon.ResourceDoesNotExistException;
33 * ChecksumTransferTest
35 * @author Brett Porter
36 * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
39 public class ChecksumTransferTest
40 extends AbstractProxyTestCase
42 public void testGetChecksumBothCorrect()
45 String path = "org/apache/maven/test/get-checksum-both-right/1.0/get-checksum-both-right-1.0.jar";
46 setupTestableManagedRepository( path );
48 File expectedFile = new File( managedDefaultDir, path );
49 ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
51 FileUtils.deleteDirectory( expectedFile.getParentFile() );
52 assertFalse( expectedFile.exists() );
54 // Configure Connector (usually done within archiva.xml configuration)
55 saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
56 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
58 File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
60 File proxied1File = new File( REPOPATH_PROXIED1, path );
61 assertFileEquals( expectedFile, downloadedFile, proxied1File );
62 assertNoTempFiles( expectedFile );
63 assertChecksums( expectedFile, "066d76e459f7782c312c31e8a11b3c0f1e3e43a7 *get-checksum-both-right-1.0.jar",
64 "e58f30c6a150a2e843552438d18e15cb *get-checksum-both-right-1.0.jar" );
67 public void testGetChecksumCorrectSha1NoMd5()
70 String path = "org/apache/maven/test/get-checksum-sha1-only/1.0/get-checksum-sha1-only-1.0.jar";
71 setupTestableManagedRepository( path );
73 File expectedFile = new File( managedDefaultDir, path );
74 ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
76 FileUtils.deleteDirectory( expectedFile.getParentFile() );
77 assertFalse( expectedFile.exists() );
79 // Configure Connector (usually done within archiva.xml configuration)
80 saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
81 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
83 File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
85 File proxied1File = new File( REPOPATH_PROXIED1, path );
86 assertFileEquals( expectedFile, downloadedFile, proxied1File );
87 assertNoTempFiles( expectedFile );
88 assertChecksums( expectedFile, "748a3a013bf5eacf2bbb40a2ac7d37889b728837 *get-checksum-sha1-only-1.0.jar",
92 public void testGetChecksumNoSha1CorrectMd5()
95 String path = "org/apache/maven/test/get-checksum-md5-only/1.0/get-checksum-md5-only-1.0.jar";
96 setupTestableManagedRepository( path );
98 File expectedFile = new File( managedDefaultDir, path );
99 ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
101 FileUtils.deleteDirectory( expectedFile.getParentFile() );
102 assertFalse( expectedFile.exists() );
104 // Configure Connector (usually done within archiva.xml configuration)
105 saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
106 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
108 File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
110 File proxied1File = new File( REPOPATH_PROXIED1, path );
111 assertFileEquals( expectedFile, downloadedFile, proxied1File );
112 assertNoTempFiles( expectedFile );
113 assertChecksums( expectedFile, null, "f3af5201bf8da801da37db8842846e1c *get-checksum-md5-only-1.0.jar" );
116 public void testGetWithNoChecksumsUsingIgnoredSetting()
119 String path = "org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar";
120 setupTestableManagedRepository( path );
122 File expectedFile = new File( managedDefaultDir, path );
123 ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
125 FileUtils.deleteDirectory( expectedFile.getParentFile() );
126 assertFalse( expectedFile.exists() );
128 // Configure Connector (usually done within archiva.xml configuration)
129 saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
130 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
132 File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
134 File proxied1File = new File( REPOPATH_PROXIED1, path );
135 assertFileEquals( expectedFile, downloadedFile, proxied1File );
136 assertNoTempFiles( expectedFile );
137 assertChecksums( expectedFile, null, null );
140 public void testGetChecksumBadSha1BadMd5IgnoredSetting()
143 String path = "org/apache/maven/test/get-checksum-both-bad/1.0/get-checksum-both-bad-1.0.jar";
144 setupTestableManagedRepository( path );
146 File expectedFile = new File( managedDefaultDir, path );
147 ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
149 FileUtils.deleteDirectory( expectedFile.getParentFile() );
150 assertFalse( expectedFile.exists() );
152 // Configure Connector (usually done within archiva.xml configuration)
153 saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
154 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
156 File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
158 File proxied1File = new File( REPOPATH_PROXIED1, path );
159 assertFileEquals( expectedFile, downloadedFile, proxied1File );
160 assertNoTempFiles( expectedFile );
161 assertChecksums( expectedFile, "invalid checksum file", "invalid checksum file" );
164 public void testGetChecksumBadSha1BadMd5FailSetting()
167 String path = "org/apache/maven/test/get-checksum-both-bad/1.0/get-checksum-both-bad-1.0.jar";
168 setupTestableManagedRepository( path );
170 File expectedFile = new File( managedDefaultDir, path );
171 ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
173 FileUtils.deleteDirectory( expectedFile.getParentFile() );
174 assertFalse( expectedFile.exists() );
176 // Configure Connector (usually done within archiva.xml configuration)
177 saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FAIL, ReleasesPolicy.ALWAYS,
178 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
180 File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
182 assertNotDownloaded( downloadedFile );
183 assertChecksums( expectedFile, null, null );
186 public void testGetChecksumBadSha1BadMd5FixSetting()
189 String path = "org/apache/maven/test/get-checksum-both-bad/1.0/get-checksum-both-bad-1.0.jar";
190 setupTestableManagedRepository( path );
192 File expectedFile = new File( managedDefaultDir, path );
193 ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
195 FileUtils.deleteDirectory( expectedFile.getParentFile() );
196 assertFalse( expectedFile.exists() );
198 // Configure Connector (usually done within archiva.xml configuration)
199 saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
200 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
202 File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
204 File proxied1File = new File( REPOPATH_PROXIED1, path );
205 assertFileEquals( expectedFile, downloadedFile, proxied1File );
206 assertNoTempFiles( expectedFile );
207 assertChecksums( expectedFile, "4ec20a12dc91557330bd0b39d1805be5e329ae56 get-checksum-both-bad-1.0.jar",
208 "a292491a35925465e693a44809a078b5 get-checksum-both-bad-1.0.jar" );
211 public void testGetChecksumCorrectSha1BadMd5UsingFailSetting()
214 String path = "org/apache/maven/test/get-checksum-sha1-bad-md5/1.0/get-checksum-sha1-bad-md5-1.0.jar";
215 setupTestableManagedRepository( path );
217 File expectedFile = new File( managedDefaultDir, path );
218 ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
220 FileUtils.deleteDirectory( expectedFile.getParentFile() );
221 assertFalse( expectedFile.exists() );
223 // Configure Connector (usually done within archiva.xml configuration)
224 saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FAIL, ReleasesPolicy.ALWAYS,
225 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
227 File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
229 assertNotDownloaded( downloadedFile );
230 assertChecksums( expectedFile, null, null );
233 public void testGetChecksumNoSha1CorrectMd5UsingFailSetting()
236 String path = "org/apache/maven/test/get-checksum-md5-only/1.0/get-checksum-md5-only-1.0.jar";
237 setupTestableManagedRepository( path );
239 File expectedFile = new File( managedDefaultDir, path );
240 ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
242 FileUtils.deleteDirectory( expectedFile.getParentFile() );
243 assertFalse( expectedFile.exists() );
245 // Configure Connector (usually done within archiva.xml configuration)
246 saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FAIL, ReleasesPolicy.ALWAYS,
247 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
249 File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
251 // This is a success situation. No SHA1 with a Good MD5.
252 File proxied1File = new File( REPOPATH_PROXIED1, path );
253 assertFileEquals( expectedFile, downloadedFile, proxied1File );
254 assertNoTempFiles( expectedFile );
255 assertChecksums( expectedFile, null, "f3af5201bf8da801da37db8842846e1c *get-checksum-md5-only-1.0.jar" );
258 public void testGetWithNoChecksumsUsingFailSetting()
261 String path = "org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar";
262 setupTestableManagedRepository( path );
264 File expectedFile = new File( managedDefaultDir, path );
265 ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
267 FileUtils.deleteDirectory( expectedFile.getParentFile() );
268 assertFalse( expectedFile.exists() );
270 // Configure Connector (usually done within archiva.xml configuration)
271 saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FAIL, ReleasesPolicy.ALWAYS,
272 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
274 File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
276 assertNotDownloaded( downloadedFile );
277 assertChecksums( expectedFile, null, null );
280 public void testGetChecksumCorrectSha1BadMd5UsingIgnoredSetting()
283 String path = "org/apache/maven/test/get-checksum-sha1-bad-md5/1.0/get-checksum-sha1-bad-md5-1.0.jar";
284 setupTestableManagedRepository( path );
286 File expectedFile = new File( managedDefaultDir, path );
287 ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
289 FileUtils.deleteDirectory( expectedFile.getParentFile() );
290 assertFalse( expectedFile.exists() );
292 // Configure Connector (usually done within archiva.xml configuration)
293 saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
294 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
296 File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
298 File proxied1File = new File( REPOPATH_PROXIED1, path );
299 assertFileEquals( expectedFile, downloadedFile, proxied1File );
300 assertNoTempFiles( expectedFile );
301 assertChecksums( expectedFile, "3dd1a3a57b807d3ef3fbc6013d926c891cbb8670 *get-checksum-sha1-bad-md5-1.0.jar",
302 "invalid checksum file" );
305 public void testGetChecksumCorrectSha1BadMd5UsingFixSetting()
308 String path = "org/apache/maven/test/get-checksum-sha1-bad-md5/1.0/get-checksum-sha1-bad-md5-1.0.jar";
309 setupTestableManagedRepository( path );
311 File expectedFile = new File( managedDefaultDir, path );
312 ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
314 FileUtils.deleteDirectory( expectedFile.getParentFile() );
315 assertFalse( expectedFile.exists() );
317 // Configure Connector (usually done within archiva.xml configuration)
318 saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
319 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
321 File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
323 File proxied1File = new File( REPOPATH_PROXIED1, path );
324 assertFileEquals( expectedFile, downloadedFile, proxied1File );
325 assertNoTempFiles( expectedFile );
326 assertChecksums( expectedFile, "3dd1a3a57b807d3ef3fbc6013d926c891cbb8670 *get-checksum-sha1-bad-md5-1.0.jar",
327 "c35f3b76268b73a4ba617f6f275c49ab get-checksum-sha1-bad-md5-1.0.jar" );
330 public void testGetChecksumNoSha1CorrectMd5UsingFixSetting()
333 String path = "org/apache/maven/test/get-checksum-md5-only/1.0/get-checksum-md5-only-1.0.jar";
334 setupTestableManagedRepository( path );
336 File expectedFile = new File( managedDefaultDir, path );
337 ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
339 FileUtils.deleteDirectory( expectedFile.getParentFile() );
340 assertFalse( expectedFile.exists() );
342 // Configure Connector (usually done within archiva.xml configuration)
343 saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
344 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
346 File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
348 File proxied1File = new File( REPOPATH_PROXIED1, path );
349 assertFileEquals( expectedFile, downloadedFile, proxied1File );
350 assertNoTempFiles( expectedFile );
351 assertChecksums( expectedFile, "71f7dc3f72053a3f2d9fdd6fef9db055ef957ffb get-checksum-md5-only-1.0.jar",
352 "f3af5201bf8da801da37db8842846e1c *get-checksum-md5-only-1.0.jar" );
355 public void testGetWithNoChecksumsUsingFixSetting()
358 String path = "org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar";
359 setupTestableManagedRepository( path );
361 File expectedFile = new File( managedDefaultDir, path );
362 ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
364 FileUtils.deleteDirectory( expectedFile.getParentFile() );
365 assertFalse( expectedFile.exists() );
367 // Configure Connector (usually done within archiva.xml configuration)
368 saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
369 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
371 File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
373 File proxied1File = new File( REPOPATH_PROXIED1, path );
374 assertFileEquals( expectedFile, downloadedFile, proxied1File );
375 assertNoTempFiles( expectedFile );
376 assertChecksums( expectedFile, "1f12821c5e43e1a0b76b9564a6ddb0548ccb9486 get-default-layout-1.0.jar",
377 "3f7341545f21226b6f49a3c2704cb9be get-default-layout-1.0.jar" );
380 public void testGetChecksumNotFoundOnRemote()
383 String path = "org/apache/maven/test/get-checksum-sha1-only/1.0/get-checksum-sha1-only-1.0.jar";
384 setupTestableManagedRepository( path );
386 File expectedFile = new File( managedDefaultDir, path );
387 ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
389 FileUtils.deleteDirectory( expectedFile.getParentFile() );
390 assertFalse( expectedFile.getParentFile().exists() );
391 assertFalse( expectedFile.exists() );
393 saveRemoteRepositoryConfig( "badproxied", "Bad Proxied", "test://bad.machine.com/repo/", "default" );
395 // Configure Connector (usually done within archiva.xml configuration)
396 saveConnector( ID_DEFAULT_MANAGED, "badproxied", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
397 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
399 wagonMock.get( path, new File( expectedFile.getAbsolutePath() + ".tmp" ) );
400 wagonMockControl.setVoidCallable();
401 wagonMock.get( path + ".sha1", new File( expectedFile.getAbsolutePath() + ".sha1.tmp" ) );
402 wagonMockControl.setVoidCallable();
403 wagonMock.get( path + ".md5", new File( expectedFile.getAbsolutePath() + ".md5.tmp" ) );
404 wagonMockControl.setThrowable( new ResourceDoesNotExistException( "Resource does not exist." ) );
405 wagonMockControl.replay();
407 File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
409 wagonMockControl.verify();
411 // Do what the mock doesn't do.
412 String proxyPath = new File( REPOPATH_PROXIED1, path ).getAbsolutePath();
413 String localPath = new File( managedDefaultDir, path ).getAbsolutePath();
414 FileUtils.copyFile( new File( proxyPath ), new File( localPath ) );
415 FileUtils.copyFile( new File( proxyPath + ".sha1" ), new File( localPath + ".sha1" ) );
418 File proxied1File = new File( REPOPATH_PROXIED1, path );
419 assertFileEquals( expectedFile, downloadedFile, proxied1File );
420 assertNoTempFiles( expectedFile );
421 assertChecksums( expectedFile, "748a3a013bf5eacf2bbb40a2ac7d37889b728837 *get-checksum-sha1-only-1.0.jar",
425 public void testGetAlwaysBadChecksumPresentLocallyAbsentRemoteUsingIgnoredSetting()
428 String path = "org/apache/maven/test/get-bad-local-checksum/1.0/get-bad-local-checksum-1.0.jar";
429 setupTestableManagedRepository( path );
431 File expectedFile = new File( managedDefaultDir, path );
432 File remoteFile = new File( REPOPATH_PROXIED1, path );
434 setManagedOlderThanRemote( expectedFile, remoteFile );
436 ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
438 // Configure Connector (usually done within archiva.xml configuration)
439 saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
440 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
442 File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
444 File proxied1File = new File( REPOPATH_PROXIED1, path );
445 assertFileEquals( expectedFile, downloadedFile, proxied1File );
446 assertNoTempFiles( expectedFile );
447 // There are no hashcodes on the proxy side to download, hence the local ones should remain invalid.
448 assertChecksums( expectedFile, "invalid checksum file", "invalid checksum file" );
451 public void testGetAlwaysBadChecksumPresentLocallyAbsentRemoteUsingFailSetting()
454 String path = "org/apache/maven/test/get-bad-local-checksum/1.0/get-bad-local-checksum-1.0.jar";
455 setupTestableManagedRepository( path );
457 File expectedFile = new File( managedDefaultDir, path );
458 File remoteFile = new File( REPOPATH_PROXIED1, path );
460 setManagedOlderThanRemote( expectedFile, remoteFile );
462 ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
464 // Configure Connector (usually done within archiva.xml configuration)
465 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FAIL, ReleasesPolicy.ALWAYS,
466 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
468 File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
470 assertNotDownloaded( downloadedFile );
471 assertNoTempFiles( expectedFile );
472 // There are no hashcodes on the proxy side to download.
473 // The FAIL policy will delete the checksums as bad.
474 assertChecksums( expectedFile, null, null );
477 public void testGetAlwaysBadChecksumPresentLocallyAbsentRemoteUsingFixSetting()
480 String path = "org/apache/maven/test/get-bad-local-checksum/1.0/get-bad-local-checksum-1.0.jar";
481 setupTestableManagedRepository( path );
483 File expectedFile = new File( managedDefaultDir, path );
484 File remoteFile = new File( REPOPATH_PROXIED1, path );
486 setManagedOlderThanRemote( expectedFile, remoteFile );
488 ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
490 // Configure Connector (usually done within archiva.xml configuration)
491 saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
492 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
494 File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
496 File proxied1File = new File( REPOPATH_PROXIED1, path );
497 assertFileEquals( expectedFile, downloadedFile, proxied1File );
498 assertNoTempFiles( expectedFile );
499 assertChecksums( expectedFile, "96a08dc80a108cba8efd3b20aec91b32a0b2cbd4 get-bad-local-checksum-1.0.jar",
500 "46fdd6ca55bf1d7a7eb0c858f41e0ccd get-bad-local-checksum-1.0.jar" );