1 package org.apache.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.archiva.common.utils.FileUtils;
23 import org.apache.archiva.model.ArtifactReference;
24 import org.apache.archiva.policies.CachedFailuresPolicy;
25 import org.apache.archiva.policies.ChecksumPolicy;
26 import org.apache.archiva.policies.ReleasesPolicy;
27 import org.apache.archiva.policies.SnapshotsPolicy;
28 import org.apache.archiva.repository.BaseRepositoryContentLayout;
29 import org.apache.archiva.repository.storage.StorageAsset;
30 import org.apache.maven.wagon.ResourceDoesNotExistException;
31 import org.easymock.EasyMock;
32 import org.junit.Test;
35 import java.nio.file.Files;
36 import java.nio.file.Path;
37 import java.nio.file.Paths;
38 import java.nio.file.StandardCopyOption;
40 import static org.junit.Assert.assertFalse;
41 import static org.junit.Assert.assertNull;
44 * ChecksumTransferTest
46 public class ChecksumTransferTest
47 extends AbstractProxyTestCase
50 public void testGetChecksumWhenConnectorIsDisabled( )
53 String path = "org/apache/maven/test/get-checksum-both-right/1.0/get-checksum-both-right-1.0.jar";
54 setupTestableManagedRepository( path );
56 Path expectedFile = managedDefaultDir.resolve( path );
58 BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout( BaseRepositoryContentLayout.class );
59 ArtifactReference artifact = layout.toArtifactReference( path );
61 org.apache.archiva.common.utils.FileUtils.deleteDirectory( expectedFile.getParent( ) );
62 assertFalse( Files.exists( expectedFile ) );
64 // Configure Connector (usually done within archiva.xml configuration)
65 saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
66 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, true );
68 StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository( ), artifact );
70 assertNull( downloadedFile );
74 public void testGetChecksumBothCorrect( )
77 String path = "org/apache/maven/test/get-checksum-both-right/1.0/get-checksum-both-right-1.0.jar";
78 setupTestableManagedRepository( path );
80 Path expectedFile = managedDefaultDir.resolve( path );
81 BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout( BaseRepositoryContentLayout.class );
82 ArtifactReference artifact = layout.toArtifactReference( path );
84 org.apache.archiva.common.utils.FileUtils.deleteDirectory( expectedFile.getParent( ) );
85 assertFalse( Files.exists( expectedFile ) );
87 // Configure Connector (usually done within archiva.xml configuration)
88 saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
89 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
91 StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository( ), artifact );
93 Path proxied1File = Paths.get( REPOPATH_PROXIED1, path );
94 assertFileEquals( expectedFile, downloadedFile.getFilePath( ), proxied1File );
95 assertNoTempFiles( expectedFile );
96 assertChecksums( expectedFile, "066d76e459f7782c312c31e8a11b3c0f1e3e43a7 *get-checksum-both-right-1.0.jar",
97 "e58f30c6a150a2e843552438d18e15cb *get-checksum-both-right-1.0.jar" );
101 public void testGetChecksumCorrectSha1NoMd5( )
104 String path = "org/apache/maven/test/get-checksum-sha1-only/1.0/get-checksum-sha1-only-1.0.jar";
105 setupTestableManagedRepository( path );
107 Path expectedFile = managedDefaultDir.resolve( path );
108 BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout( BaseRepositoryContentLayout.class );
109 ArtifactReference artifact = layout.toArtifactReference( path );
111 FileUtils.deleteDirectory( expectedFile.getParent( ) );
112 assertFalse( Files.exists( expectedFile ) );
114 // Configure Connector (usually done within archiva.xml configuration)
115 saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
116 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
118 StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository( ), artifact );
120 Path proxied1File = Paths.get( REPOPATH_PROXIED1, path );
121 assertFileEquals( expectedFile, downloadedFile.getFilePath( ), proxied1File );
122 assertNoTempFiles( expectedFile );
123 assertChecksums( expectedFile, "748a3a013bf5eacf2bbb40a2ac7d37889b728837 *get-checksum-sha1-only-1.0.jar",
128 public void testGetChecksumNoSha1CorrectMd5( )
131 String path = "org/apache/maven/test/get-checksum-md5-only/1.0/get-checksum-md5-only-1.0.jar";
132 setupTestableManagedRepository( path );
134 Path expectedFile = managedDefaultDir.resolve( path );
135 BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout( BaseRepositoryContentLayout.class );
136 ArtifactReference artifact = layout.toArtifactReference( path );
138 FileUtils.deleteDirectory( expectedFile.getParent( ) );
139 assertFalse( Files.exists( expectedFile ) );
141 // Configure Connector (usually done within archiva.xml configuration)
142 saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
143 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
145 StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository( ), artifact );
147 Path proxied1File = Paths.get( REPOPATH_PROXIED1, path );
148 assertFileEquals( expectedFile, downloadedFile.getFilePath( ), proxied1File );
149 assertNoTempFiles( expectedFile );
150 assertChecksums( expectedFile, null, "f3af5201bf8da801da37db8842846e1c *get-checksum-md5-only-1.0.jar" );
154 public void testGetWithNoChecksumsUsingIgnoredSetting( )
157 String path = "org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar";
158 setupTestableManagedRepository( path );
160 Path expectedFile = managedDefaultDir.resolve( path );
161 BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout( BaseRepositoryContentLayout.class );
162 ArtifactReference artifact = layout.toArtifactReference( path );
164 FileUtils.deleteDirectory( expectedFile.getParent( ) );
165 assertFalse( Files.exists( expectedFile ) );
167 // Configure Connector (usually done within archiva.xml configuration)
168 saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
169 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
171 StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository( ), artifact );
173 Path proxied1File = Paths.get( REPOPATH_PROXIED1, path );
174 assertFileEquals( expectedFile, downloadedFile.getFilePath( ), proxied1File );
175 assertNoTempFiles( expectedFile );
176 assertChecksums( expectedFile, null, null );
180 public void testGetChecksumBadSha1BadMd5IgnoredSetting( )
183 String path = "org/apache/maven/test/get-checksum-both-bad/1.0/get-checksum-both-bad-1.0.jar";
184 setupTestableManagedRepository( path );
186 Path expectedFile = managedDefaultDir.resolve( path );
187 BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout( BaseRepositoryContentLayout.class );
188 ArtifactReference artifact = layout.toArtifactReference( path );
190 FileUtils.deleteDirectory( expectedFile.getParent( ) );
191 assertFalse( Files.exists( expectedFile ) );
193 // Configure Connector (usually done within archiva.xml configuration)
194 saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
195 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
197 StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository( ), artifact );
199 Path proxied1File = Paths.get( REPOPATH_PROXIED1, path );
200 assertFileEquals( expectedFile, downloadedFile.getFilePath( ), proxied1File );
201 assertNoTempFiles( expectedFile );
202 assertChecksums( expectedFile, "invalid checksum file", "invalid checksum file" );
206 public void testGetChecksumBadSha1BadMd5FailSetting( )
209 String path = "org/apache/maven/test/get-checksum-both-bad/1.0/get-checksum-both-bad-1.0.jar";
210 setupTestableManagedRepository( path );
212 Path expectedFile = managedDefaultDir.resolve( path );
213 BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout( BaseRepositoryContentLayout.class );
214 ArtifactReference artifact = layout.toArtifactReference( path );
216 FileUtils.deleteDirectory( expectedFile.getParent( ) );
217 assertFalse( Files.exists( expectedFile ) );
219 // Configure Connector (usually done within archiva.xml configuration)
220 saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FAIL, ReleasesPolicy.ALWAYS,
221 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
223 StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository( ), artifact );
225 assertNotDownloaded( downloadedFile );
226 assertChecksums( expectedFile, null, null );
230 public void testGetChecksumBadSha1BadMd5FixSetting( )
233 String path = "org/apache/maven/test/get-checksum-both-bad/1.0/get-checksum-both-bad-1.0.jar";
234 setupTestableManagedRepository( path );
236 Path expectedFile = managedDefaultDir.resolve( path );
237 BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout( BaseRepositoryContentLayout.class );
238 ArtifactReference artifact = layout.toArtifactReference( path );
240 FileUtils.deleteDirectory( expectedFile.getParent( ) );
241 assertFalse( Files.exists( expectedFile ) );
243 // Configure Connector (usually done within archiva.xml configuration)
244 saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
245 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
247 StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository( ), artifact );
249 Path proxied1File = Paths.get( REPOPATH_PROXIED1, path );
250 assertFileEquals( expectedFile, downloadedFile.getFilePath( ), proxied1File );
251 assertNoTempFiles( expectedFile );
252 assertChecksums( expectedFile, "4ec20a12dc91557330bd0b39d1805be5e329ae56 get-checksum-both-bad-1.0.jar",
253 "a292491a35925465e693a44809a078b5 get-checksum-both-bad-1.0.jar" );
257 public void testGetChecksumCorrectSha1BadMd5UsingFailSetting( )
260 String path = "org/apache/maven/test/get-checksum-sha1-bad-md5/1.0/get-checksum-sha1-bad-md5-1.0.jar";
261 setupTestableManagedRepository( path );
263 Path expectedFile = managedDefaultDir.resolve( path );
264 BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout( BaseRepositoryContentLayout.class );
265 ArtifactReference artifact = layout.toArtifactReference( path );
267 FileUtils.deleteDirectory( expectedFile.getParent( ) );
268 assertFalse( Files.exists( expectedFile ) );
270 // Configure Connector (usually done within archiva.xml configuration)
271 saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FAIL, ReleasesPolicy.ALWAYS,
272 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
274 StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository( ), artifact );
276 assertNotDownloaded( downloadedFile );
277 assertChecksums( expectedFile, null, null );
281 public void testGetChecksumNoSha1CorrectMd5UsingFailSetting( )
284 String path = "org/apache/maven/test/get-checksum-md5-only/1.0/get-checksum-md5-only-1.0.jar";
285 setupTestableManagedRepository( path );
287 Path expectedFile = managedDefaultDir.resolve( path );
288 BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout( BaseRepositoryContentLayout.class );
289 ArtifactReference artifact = layout.toArtifactReference( path );
291 FileUtils.deleteDirectory( expectedFile.getParent( ) );
292 assertFalse( Files.exists( expectedFile ) );
294 // Configure Connector (usually done within archiva.xml configuration)
295 saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FAIL, ReleasesPolicy.ALWAYS,
296 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
298 StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository( ), artifact );
300 // This is a success situation. No SHA1 with a Good MD5.
301 Path proxied1File = Paths.get( REPOPATH_PROXIED1, path );
302 assertFileEquals( expectedFile, downloadedFile.getFilePath( ), proxied1File );
303 assertNoTempFiles( expectedFile );
304 assertChecksums( expectedFile, null, "f3af5201bf8da801da37db8842846e1c *get-checksum-md5-only-1.0.jar" );
308 public void testGetWithNoChecksumsUsingFailSetting( )
311 String path = "org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar";
312 setupTestableManagedRepository( path );
314 Path expectedFile = managedDefaultDir.resolve( path );
315 BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout( BaseRepositoryContentLayout.class );
316 ArtifactReference artifact = layout.toArtifactReference( path );
318 FileUtils.deleteDirectory( expectedFile.getParent( ) );
319 assertFalse( Files.exists( expectedFile ) );
321 // Configure Connector (usually done within archiva.xml configuration)
322 saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FAIL, ReleasesPolicy.ALWAYS,
323 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
325 StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository( ), artifact );
327 assertNotDownloaded( downloadedFile );
328 assertChecksums( expectedFile, null, null );
332 public void testGetChecksumCorrectSha1BadMd5UsingIgnoredSetting( )
335 String path = "org/apache/maven/test/get-checksum-sha1-bad-md5/1.0/get-checksum-sha1-bad-md5-1.0.jar";
336 setupTestableManagedRepository( path );
338 Path expectedFile = managedDefaultDir.resolve( path );
339 BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout( BaseRepositoryContentLayout.class );
340 ArtifactReference artifact = layout.toArtifactReference( path );
342 FileUtils.deleteDirectory( expectedFile.getParent( ) );
343 assertFalse( Files.exists( expectedFile ) );
345 // Configure Connector (usually done within archiva.xml configuration)
346 saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
347 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
349 StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository( ), artifact );
351 Path proxied1File = Paths.get( REPOPATH_PROXIED1, path );
352 assertFileEquals( expectedFile, downloadedFile.getFilePath( ), proxied1File );
353 assertNoTempFiles( expectedFile );
354 assertChecksums( expectedFile, "3dd1a3a57b807d3ef3fbc6013d926c891cbb8670 *get-checksum-sha1-bad-md5-1.0.jar",
355 "invalid checksum file" );
359 public void testGetChecksumCorrectSha1BadMd5UsingFixSetting( )
362 String path = "org/apache/maven/test/get-checksum-sha1-bad-md5/1.0/get-checksum-sha1-bad-md5-1.0.jar";
363 setupTestableManagedRepository( path );
365 Path expectedFile = managedDefaultDir.resolve( path );
366 BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout( BaseRepositoryContentLayout.class );
367 ArtifactReference artifact = layout.toArtifactReference( path );
369 FileUtils.deleteDirectory( expectedFile.getParent( ) );
370 assertFalse( Files.exists( expectedFile ) );
372 // Configure Connector (usually done within archiva.xml configuration)
373 saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
374 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
377 StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository( ), artifact );
379 Path proxied1File = Paths.get( REPOPATH_PROXIED1, path );
380 assertFileEquals( expectedFile, downloadedFile.getFilePath( ), proxied1File );
381 assertNoTempFiles( expectedFile );
382 assertChecksums( expectedFile, "3dd1a3a57b807d3ef3fbc6013d926c891cbb8670 *get-checksum-sha1-bad-md5-1.0.jar",
383 "c35f3b76268b73a4ba617f6f275c49ab get-checksum-sha1-bad-md5-1.0.jar" );
387 public void testGetChecksumNoSha1CorrectMd5UsingFixSetting( )
390 String path = "org/apache/maven/test/get-checksum-md5-only/1.0/get-checksum-md5-only-1.0.jar";
391 setupTestableManagedRepository( path );
393 Path expectedFile = managedDefaultDir.resolve( path );
394 BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout( BaseRepositoryContentLayout.class );
395 ArtifactReference artifact = layout.toArtifactReference( path );
397 FileUtils.deleteDirectory( expectedFile.getParent( ) );
398 assertFalse( Files.exists( expectedFile ) );
400 // Configure Connector (usually done within archiva.xml configuration)
401 saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
402 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
404 StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository( ), artifact );
406 Path proxied1File = Paths.get( REPOPATH_PROXIED1, path );
407 assertFileEquals( expectedFile, downloadedFile.getFilePath( ), proxied1File );
408 assertNoTempFiles( expectedFile );
409 assertChecksums( expectedFile, "71f7dc3f72053a3f2d9fdd6fef9db055ef957ffb get-checksum-md5-only-1.0.jar",
410 "f3af5201bf8da801da37db8842846e1c *get-checksum-md5-only-1.0.jar" );
414 public void testGetWithNoChecksumsUsingFixSetting( )
417 String path = "org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar";
418 setupTestableManagedRepository( path );
420 Path expectedFile = managedDefaultDir.resolve( path );
421 BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout( BaseRepositoryContentLayout.class );
422 ArtifactReference artifact = layout.toArtifactReference( path );
424 FileUtils.deleteDirectory( expectedFile.getParent( ) );
425 assertFalse( Files.exists( expectedFile ) );
427 // Configure Connector (usually done within archiva.xml configuration)
428 saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
429 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
431 StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository( ), artifact );
433 Path proxied1File = Paths.get( REPOPATH_PROXIED1, path );
434 assertFileEquals( expectedFile, downloadedFile.getFilePath( ), proxied1File );
435 assertNoTempFiles( expectedFile );
436 assertChecksums( expectedFile, "1f12821c5e43e1a0b76b9564a6ddb0548ccb9486 get-default-layout-1.0.jar",
437 "3f7341545f21226b6f49a3c2704cb9be get-default-layout-1.0.jar" );
441 public void testGetChecksumNotFoundOnRemote( )
444 String path = "org/apache/maven/test/get-checksum-sha1-only/1.0/get-checksum-sha1-only-1.0.jar";
445 setupTestableManagedRepository( path );
447 Path expectedFile = managedDefaultDir.resolve( path );
448 BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout( BaseRepositoryContentLayout.class );
449 ArtifactReference artifact = layout.toArtifactReference( path );
451 FileUtils.deleteDirectory( expectedFile.getParent( ) );
452 assertFalse( Files.exists( expectedFile.getParent( ) ) );
453 assertFalse( Files.exists( expectedFile ) );
455 saveRemoteRepositoryConfig( "badproxied", "Bad Proxied", "http://bad.machine.com/repo/", "default" );
457 // Configure Connector (usually done within archiva.xml configuration)
458 saveConnector( ID_DEFAULT_MANAGED, "badproxied", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
459 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
461 wagonMock.get( EasyMock.eq( path ), EasyMock.anyObject( File.class ) );
462 EasyMock.expectLastCall( ).once( );
464 wagonMock.get( EasyMock.eq( path + ".sha1" ), EasyMock.anyObject( File.class ) );
465 EasyMock.expectLastCall( ).once( );
467 wagonMock.get( EasyMock.eq( path + ".md5" ), EasyMock.anyObject( File.class ) );
468 EasyMock.expectLastCall( ).andThrow( new ResourceDoesNotExistException( "Resource does not exist." ) ).once( );
470 wagonMockControl.replay( );
472 StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository( ), artifact );
474 wagonMockControl.verify( );
476 // Do what the mock doesn't do.
477 Path proxyPath = Paths.get( REPOPATH_PROXIED1, path ).toAbsolutePath( );
478 Path localPath = managedDefaultDir.resolve( path ).toAbsolutePath( );
479 Files.copy( proxyPath, localPath, StandardCopyOption.REPLACE_EXISTING );
480 Files.copy( proxyPath.resolveSibling( proxyPath.getFileName( ) + ".sha1" ),
481 localPath.resolveSibling( localPath.getFileName( ) + ".sha1" ), StandardCopyOption.REPLACE_EXISTING );
484 Path proxied1File = Paths.get( REPOPATH_PROXIED1, path );
485 assertFileEquals( expectedFile, downloadedFile.getFilePath( ), proxied1File );
486 assertNoTempFiles( expectedFile );
487 assertChecksums( expectedFile, "748a3a013bf5eacf2bbb40a2ac7d37889b728837 *get-checksum-sha1-only-1.0.jar",
492 public void testGetAlwaysBadChecksumPresentLocallyAbsentRemoteUsingIgnoredSetting( )
495 String path = "org/apache/maven/test/get-bad-local-checksum/1.0/get-bad-local-checksum-1.0.jar";
496 setupTestableManagedRepository( path );
498 Path expectedFile = managedDefaultDir.resolve( path );
499 Path remoteFile = Paths.get( REPOPATH_PROXIED1, path );
501 setManagedOlderThanRemote( expectedFile, remoteFile );
503 BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout( BaseRepositoryContentLayout.class );
504 ArtifactReference artifact = layout.toArtifactReference( path );
506 // Configure Connector (usually done within archiva.xml configuration)
507 saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
508 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
510 StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository( ), artifact );
512 Path proxied1File = Paths.get( REPOPATH_PROXIED1, path );
513 assertFileEquals( expectedFile, downloadedFile.getFilePath( ), proxied1File );
514 assertNoTempFiles( expectedFile );
515 // There are no hashcodes on the proxy side to download, hence the local ones should remain invalid.
516 assertChecksums( expectedFile, "invalid checksum file", "invalid checksum file" );
520 public void testGetAlwaysBadChecksumPresentLocallyAbsentRemoteUsingFailSetting( )
523 String path = "org/apache/maven/test/get-bad-local-checksum/1.0/get-bad-local-checksum-1.0.jar";
524 setupTestableManagedRepository( path );
526 Path expectedFile = managedDefaultDir.resolve( path );
527 Path remoteFile = Paths.get( REPOPATH_PROXIED1, path );
529 setManagedOlderThanRemote( expectedFile, remoteFile );
531 BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout( BaseRepositoryContentLayout.class );
532 ArtifactReference artifact = layout.toArtifactReference( path );
534 // Configure Connector (usually done within archiva.xml configuration)
535 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FAIL, ReleasesPolicy.ALWAYS,
536 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
538 StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository( ), artifact );
540 assertNotDownloaded( downloadedFile );
541 assertNoTempFiles( expectedFile );
542 // There are no hashcodes on the proxy side to download.
543 // The FAIL policy will delete the checksums as bad.
545 assertChecksums( expectedFile, "invalid checksum file", "invalid checksum file" );
549 public void testGetAlwaysBadChecksumPresentLocallyAbsentRemoteUsingFixSetting( )
552 String path = "org/apache/maven/test/get-bad-local-checksum/1.0/get-bad-local-checksum-1.0.jar";
553 setupTestableManagedRepository( path );
555 Path expectedFile = managedDefaultDir.resolve( path );
556 Path remoteFile = Paths.get( REPOPATH_PROXIED1, path );
558 setManagedOlderThanRemote( expectedFile, remoteFile );
560 BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout( BaseRepositoryContentLayout.class );
561 ArtifactReference artifact = layout.toArtifactReference( path );
563 // Configure Connector (usually done within archiva.xml configuration)
564 saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
565 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
567 StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository( ), artifact );
569 Path proxied1File = Paths.get( REPOPATH_PROXIED1, path );
570 assertFileEquals( expectedFile, downloadedFile.getFilePath( ), proxied1File );
571 assertNoTempFiles( expectedFile );
572 assertChecksums( expectedFile, "96a08dc80a108cba8efd3b20aec91b32a0b2cbd4 get-bad-local-checksum-1.0.jar",
573 "46fdd6ca55bf1d7a7eb0c858f41e0ccd get-bad-local-checksum-1.0.jar" );