1 package org.apache.archiva.maven.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
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
21 import org.apache.archiva.common.utils.FileUtils;
22 import org.apache.archiva.policies.CachedFailuresPolicy;
23 import org.apache.archiva.policies.ChecksumPolicy;
24 import org.apache.archiva.policies.ReleasesPolicy;
25 import org.apache.archiva.policies.SnapshotsPolicy;
26 import org.apache.archiva.repository.content.BaseRepositoryContentLayout;
27 import org.apache.archiva.repository.content.Artifact;
28 import org.apache.archiva.repository.storage.StorageAsset;
29 import org.apache.maven.wagon.ResourceDoesNotExistException;
30 import org.easymock.EasyMock;
31 import org.junit.Test;
34 import java.nio.file.Files;
35 import java.nio.file.Path;
36 import java.nio.file.Paths;
37 import java.nio.file.StandardCopyOption;
39 import static org.junit.Assert.assertFalse;
40 import static org.junit.Assert.assertNull;
43 * ChecksumTransferTest
45 public class ChecksumTransferTest
46 extends AbstractProxyTestCase
49 public void testGetChecksumWhenConnectorIsDisabled( )
52 String path = "org/apache/maven/test/get-checksum-both-right/1.0/get-checksum-both-right-1.0.jar";
53 setupTestableManagedRepository( path );
55 Path expectedFile = managedDefaultDir.resolve( path );
57 BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout( BaseRepositoryContentLayout.class );
58 Artifact artifact = layout.getArtifact( path );
60 org.apache.archiva.common.utils.FileUtils.deleteDirectory( expectedFile.getParent( ) );
61 assertFalse( Files.exists( expectedFile ) );
63 // Configure Connector (usually done within archiva.xml configuration)
64 saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
65 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, true );
67 StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository( ), artifact );
69 assertNull( downloadedFile );
73 public void testGetChecksumBothCorrect( )
76 String path = "org/apache/maven/test/get-checksum-both-right/1.0/get-checksum-both-right-1.0.jar";
77 setupTestableManagedRepository( path );
79 Path expectedFile = managedDefaultDir.resolve( path );
80 BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout( BaseRepositoryContentLayout.class );
81 Artifact artifact = layout.getArtifact( path );
83 org.apache.archiva.common.utils.FileUtils.deleteDirectory( expectedFile.getParent( ) );
84 assertFalse( Files.exists( expectedFile ) );
86 // Configure Connector (usually done within archiva.xml configuration)
87 saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
88 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
90 StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository( ), artifact );
92 Path proxied1File = Paths.get( REPOPATH_PROXIED1, path );
93 assertFileEquals( expectedFile, downloadedFile.getFilePath( ), proxied1File );
94 assertNoTempFiles( expectedFile );
95 assertChecksums( expectedFile, "066d76e459f7782c312c31e8a11b3c0f1e3e43a7 *get-checksum-both-right-1.0.jar",
96 "e58f30c6a150a2e843552438d18e15cb *get-checksum-both-right-1.0.jar" );
100 public void testGetChecksumCorrectSha1NoMd5( )
103 String path = "org/apache/maven/test/get-checksum-sha1-only/1.0/get-checksum-sha1-only-1.0.jar";
104 setupTestableManagedRepository( path );
106 Path expectedFile = managedDefaultDir.resolve( path );
107 BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout( BaseRepositoryContentLayout.class );
108 Artifact artifact = layout.getArtifact( path );
110 FileUtils.deleteDirectory( expectedFile.getParent( ) );
111 assertFalse( Files.exists( expectedFile ) );
113 // Configure Connector (usually done within archiva.xml configuration)
114 saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
115 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
117 StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository( ), artifact );
119 Path proxied1File = Paths.get( REPOPATH_PROXIED1, path );
120 assertFileEquals( expectedFile, downloadedFile.getFilePath( ), proxied1File );
121 assertNoTempFiles( expectedFile );
122 assertChecksums( expectedFile, "748a3a013bf5eacf2bbb40a2ac7d37889b728837 *get-checksum-sha1-only-1.0.jar",
127 public void testGetChecksumNoSha1CorrectMd5( )
130 String path = "org/apache/maven/test/get-checksum-md5-only/1.0/get-checksum-md5-only-1.0.jar";
131 setupTestableManagedRepository( path );
133 Path expectedFile = managedDefaultDir.resolve( path );
134 BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout( BaseRepositoryContentLayout.class );
135 Artifact artifact = layout.getArtifact( path );
137 FileUtils.deleteDirectory( expectedFile.getParent( ) );
138 assertFalse( Files.exists( expectedFile ) );
140 // Configure Connector (usually done within archiva.xml configuration)
141 saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
142 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
144 StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository( ), artifact );
146 Path proxied1File = Paths.get( REPOPATH_PROXIED1, path );
147 assertFileEquals( expectedFile, downloadedFile.getFilePath( ), proxied1File );
148 assertNoTempFiles( expectedFile );
149 assertChecksums( expectedFile, null, "f3af5201bf8da801da37db8842846e1c *get-checksum-md5-only-1.0.jar" );
153 public void testGetWithNoChecksumsUsingIgnoredSetting( )
156 String path = "org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar";
157 setupTestableManagedRepository( path );
159 Path expectedFile = managedDefaultDir.resolve( path );
160 BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout( BaseRepositoryContentLayout.class );
161 Artifact artifact = layout.getArtifact( path );
163 FileUtils.deleteDirectory( expectedFile.getParent( ) );
164 assertFalse( Files.exists( expectedFile ) );
166 // Configure Connector (usually done within archiva.xml configuration)
167 saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
168 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
170 StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository( ), artifact );
172 Path proxied1File = Paths.get( REPOPATH_PROXIED1, path );
173 assertFileEquals( expectedFile, downloadedFile.getFilePath( ), proxied1File );
174 assertNoTempFiles( expectedFile );
175 assertChecksums( expectedFile, null, null );
179 public void testGetChecksumBadSha1BadMd5IgnoredSetting( )
182 String path = "org/apache/maven/test/get-checksum-both-bad/1.0/get-checksum-both-bad-1.0.jar";
183 setupTestableManagedRepository( path );
185 Path expectedFile = managedDefaultDir.resolve( path );
186 BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout( BaseRepositoryContentLayout.class );
187 Artifact artifact = layout.getArtifact( path );
189 FileUtils.deleteDirectory( expectedFile.getParent( ) );
190 assertFalse( Files.exists( expectedFile ) );
192 // Configure Connector (usually done within archiva.xml configuration)
193 saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
194 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
196 StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository( ), artifact );
198 Path proxied1File = Paths.get( REPOPATH_PROXIED1, path );
199 assertFileEquals( expectedFile, downloadedFile.getFilePath( ), proxied1File );
200 assertNoTempFiles( expectedFile );
201 assertChecksums( expectedFile, "invalid checksum file", "invalid checksum file" );
205 public void testGetChecksumBadSha1BadMd5FailSetting( )
208 String path = "org/apache/maven/test/get-checksum-both-bad/1.0/get-checksum-both-bad-1.0.jar";
209 setupTestableManagedRepository( path );
211 Path expectedFile = managedDefaultDir.resolve( path );
212 BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout( BaseRepositoryContentLayout.class );
213 Artifact artifact = layout.getArtifact( path );
215 FileUtils.deleteDirectory( expectedFile.getParent( ) );
216 assertFalse( Files.exists( expectedFile ) );
218 // Configure Connector (usually done within archiva.xml configuration)
219 saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FAIL, ReleasesPolicy.ALWAYS,
220 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
222 StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository( ), artifact );
224 assertNotDownloaded( downloadedFile );
225 assertChecksums( expectedFile, null, null );
229 public void testGetChecksumBadSha1BadMd5FixSetting( )
232 String path = "org/apache/maven/test/get-checksum-both-bad/1.0/get-checksum-both-bad-1.0.jar";
233 setupTestableManagedRepository( path );
235 Path expectedFile = managedDefaultDir.resolve( path );
236 BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout( BaseRepositoryContentLayout.class );
237 Artifact artifact = layout.getArtifact( path );
239 FileUtils.deleteDirectory( expectedFile.getParent( ) );
240 assertFalse( Files.exists( expectedFile ) );
242 // Configure Connector (usually done within archiva.xml configuration)
243 saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
244 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
246 StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository( ), artifact );
248 Path proxied1File = Paths.get( REPOPATH_PROXIED1, path );
249 assertFileEquals( expectedFile, downloadedFile.getFilePath( ), proxied1File );
250 assertNoTempFiles( expectedFile );
251 assertChecksums( expectedFile, "4ec20a12dc91557330bd0b39d1805be5e329ae56 get-checksum-both-bad-1.0.jar",
252 "a292491a35925465e693a44809a078b5 get-checksum-both-bad-1.0.jar" );
256 public void testGetChecksumCorrectSha1BadMd5UsingFailSetting( )
259 String path = "org/apache/maven/test/get-checksum-sha1-bad-md5/1.0/get-checksum-sha1-bad-md5-1.0.jar";
260 setupTestableManagedRepository( path );
262 Path expectedFile = managedDefaultDir.resolve( path );
263 BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout( BaseRepositoryContentLayout.class );
264 Artifact artifact = layout.getArtifact( path );
266 FileUtils.deleteDirectory( expectedFile.getParent( ) );
267 assertFalse( Files.exists( expectedFile ) );
269 // Configure Connector (usually done within archiva.xml configuration)
270 saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FAIL, ReleasesPolicy.ALWAYS,
271 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
273 StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository( ), artifact );
275 assertNotDownloaded( downloadedFile );
276 assertChecksums( expectedFile, null, null );
280 public void testGetChecksumNoSha1CorrectMd5UsingFailSetting( )
283 String path = "org/apache/maven/test/get-checksum-md5-only/1.0/get-checksum-md5-only-1.0.jar";
284 setupTestableManagedRepository( path );
286 Path expectedFile = managedDefaultDir.resolve( path );
287 BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout( BaseRepositoryContentLayout.class );
288 Artifact artifact = layout.getArtifact( path );
290 FileUtils.deleteDirectory( expectedFile.getParent( ) );
291 assertFalse( Files.exists( expectedFile ) );
293 // Configure Connector (usually done within archiva.xml configuration)
294 saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FAIL, ReleasesPolicy.ALWAYS,
295 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
297 StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository( ), artifact );
299 // This is a success situation. No SHA1 with a Good MD5.
300 Path proxied1File = Paths.get( REPOPATH_PROXIED1, path );
301 assertFileEquals( expectedFile, downloadedFile.getFilePath( ), proxied1File );
302 assertNoTempFiles( expectedFile );
303 assertChecksums( expectedFile, null, "f3af5201bf8da801da37db8842846e1c *get-checksum-md5-only-1.0.jar" );
307 public void testGetWithNoChecksumsUsingFailSetting( )
310 String path = "org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar";
311 setupTestableManagedRepository( path );
313 Path expectedFile = managedDefaultDir.resolve( path );
314 BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout( BaseRepositoryContentLayout.class );
315 Artifact artifact = layout.getArtifact( path );
317 FileUtils.deleteDirectory( expectedFile.getParent( ) );
318 assertFalse( Files.exists( expectedFile ) );
320 // Configure Connector (usually done within archiva.xml configuration)
321 saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FAIL, ReleasesPolicy.ALWAYS,
322 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
324 StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository( ), artifact );
326 assertNotDownloaded( downloadedFile );
327 assertChecksums( expectedFile, null, null );
331 public void testGetChecksumCorrectSha1BadMd5UsingIgnoredSetting( )
334 String path = "org/apache/maven/test/get-checksum-sha1-bad-md5/1.0/get-checksum-sha1-bad-md5-1.0.jar";
335 setupTestableManagedRepository( path );
337 Path expectedFile = managedDefaultDir.resolve( path );
338 BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout( BaseRepositoryContentLayout.class );
339 Artifact artifact = layout.getArtifact( path );
341 FileUtils.deleteDirectory( expectedFile.getParent( ) );
342 assertFalse( Files.exists( expectedFile ) );
344 // Configure Connector (usually done within archiva.xml configuration)
345 saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
346 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
348 StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository( ), artifact );
350 Path proxied1File = Paths.get( REPOPATH_PROXIED1, path );
351 assertFileEquals( expectedFile, downloadedFile.getFilePath( ), proxied1File );
352 assertNoTempFiles( expectedFile );
353 assertChecksums( expectedFile, "3dd1a3a57b807d3ef3fbc6013d926c891cbb8670 *get-checksum-sha1-bad-md5-1.0.jar",
354 "invalid checksum file" );
358 public void testGetChecksumCorrectSha1BadMd5UsingFixSetting( )
361 String path = "org/apache/maven/test/get-checksum-sha1-bad-md5/1.0/get-checksum-sha1-bad-md5-1.0.jar";
362 setupTestableManagedRepository( path );
364 Path expectedFile = managedDefaultDir.resolve( path );
365 BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout( BaseRepositoryContentLayout.class );
366 Artifact artifact = layout.getArtifact( path );
368 FileUtils.deleteDirectory( expectedFile.getParent( ) );
369 assertFalse( Files.exists( expectedFile ) );
371 // Configure Connector (usually done within archiva.xml configuration)
372 saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
373 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
376 StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository( ), artifact );
378 Path proxied1File = Paths.get( REPOPATH_PROXIED1, path );
379 assertFileEquals( expectedFile, downloadedFile.getFilePath( ), proxied1File );
380 assertNoTempFiles( expectedFile );
381 assertChecksums( expectedFile, "3dd1a3a57b807d3ef3fbc6013d926c891cbb8670 *get-checksum-sha1-bad-md5-1.0.jar",
382 "c35f3b76268b73a4ba617f6f275c49ab get-checksum-sha1-bad-md5-1.0.jar" );
386 public void testGetChecksumNoSha1CorrectMd5UsingFixSetting( )
389 String path = "org/apache/maven/test/get-checksum-md5-only/1.0/get-checksum-md5-only-1.0.jar";
390 setupTestableManagedRepository( path );
392 Path expectedFile = managedDefaultDir.resolve( path );
393 BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout( BaseRepositoryContentLayout.class );
394 Artifact artifact = layout.getArtifact( path );
396 FileUtils.deleteDirectory( expectedFile.getParent( ) );
397 assertFalse( Files.exists( expectedFile ) );
399 // Configure Connector (usually done within archiva.xml configuration)
400 saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
401 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
403 StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository( ), artifact );
405 Path proxied1File = Paths.get( REPOPATH_PROXIED1, path );
406 assertFileEquals( expectedFile, downloadedFile.getFilePath( ), proxied1File );
407 assertNoTempFiles( expectedFile );
408 assertChecksums( expectedFile, "71f7dc3f72053a3f2d9fdd6fef9db055ef957ffb get-checksum-md5-only-1.0.jar",
409 "f3af5201bf8da801da37db8842846e1c *get-checksum-md5-only-1.0.jar" );
413 public void testGetWithNoChecksumsUsingFixSetting( )
416 String path = "org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar";
417 setupTestableManagedRepository( path );
419 Path expectedFile = managedDefaultDir.resolve( path );
420 BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout( BaseRepositoryContentLayout.class );
421 Artifact artifact = layout.getArtifact( path );
423 FileUtils.deleteDirectory( expectedFile.getParent( ) );
424 assertFalse( Files.exists( expectedFile ) );
426 // Configure Connector (usually done within archiva.xml configuration)
427 saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
428 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
430 StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository( ), artifact );
432 Path proxied1File = Paths.get( REPOPATH_PROXIED1, path );
433 assertFileEquals( expectedFile, downloadedFile.getFilePath( ), proxied1File );
434 assertNoTempFiles( expectedFile );
435 assertChecksums( expectedFile, "1f12821c5e43e1a0b76b9564a6ddb0548ccb9486 get-default-layout-1.0.jar",
436 "3f7341545f21226b6f49a3c2704cb9be get-default-layout-1.0.jar" );
440 public void testGetChecksumNotFoundOnRemote( )
443 String path = "org/apache/maven/test/get-checksum-sha1-only/1.0/get-checksum-sha1-only-1.0.jar";
444 setupTestableManagedRepository( path );
446 Path expectedFile = managedDefaultDir.resolve( path );
447 BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout( BaseRepositoryContentLayout.class );
448 Artifact artifact = layout.getArtifact( path );
450 FileUtils.deleteDirectory( expectedFile.getParent( ) );
451 assertFalse( Files.exists( expectedFile.getParent( ) ) );
452 assertFalse( Files.exists( expectedFile ) );
454 saveRemoteRepositoryConfig( "badproxied", "Bad Proxied", "http://bad.machine.com/repo/", "default" );
456 // Configure Connector (usually done within archiva.xml configuration)
457 saveConnector( ID_DEFAULT_MANAGED, "badproxied", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
458 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
460 wagonMock.get( EasyMock.eq( path ), EasyMock.anyObject( File.class ) );
461 EasyMock.expectLastCall( ).once( );
463 wagonMock.get( EasyMock.eq( path + ".sha1" ), EasyMock.anyObject( File.class ) );
464 EasyMock.expectLastCall( ).once( );
466 wagonMock.get( EasyMock.eq( path + ".md5" ), EasyMock.anyObject( File.class ) );
467 EasyMock.expectLastCall( ).andThrow( new ResourceDoesNotExistException( "Resource does not exist." ) ).once( );
469 wagonMockControl.replay( );
471 StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository( ), artifact );
473 wagonMockControl.verify( );
475 // Do what the mock doesn't do.
476 Path proxyPath = Paths.get( REPOPATH_PROXIED1, path ).toAbsolutePath( );
477 Path localPath = managedDefaultDir.resolve( path ).toAbsolutePath( );
478 Files.copy( proxyPath, localPath, StandardCopyOption.REPLACE_EXISTING );
479 Files.copy( proxyPath.resolveSibling( proxyPath.getFileName( ) + ".sha1" ),
480 localPath.resolveSibling( localPath.getFileName( ) + ".sha1" ), StandardCopyOption.REPLACE_EXISTING );
483 Path proxied1File = Paths.get( REPOPATH_PROXIED1, path );
484 assertFileEquals( expectedFile, downloadedFile.getFilePath( ), proxied1File );
485 assertNoTempFiles( expectedFile );
486 assertChecksums( expectedFile, "748a3a013bf5eacf2bbb40a2ac7d37889b728837 *get-checksum-sha1-only-1.0.jar",
491 public void testGetAlwaysBadChecksumPresentLocallyAbsentRemoteUsingIgnoredSetting( )
494 String path = "org/apache/maven/test/get-bad-local-checksum/1.0/get-bad-local-checksum-1.0.jar";
495 setupTestableManagedRepository( path );
497 Path expectedFile = managedDefaultDir.resolve( path );
498 Path remoteFile = Paths.get( REPOPATH_PROXIED1, path );
500 setManagedOlderThanRemote( expectedFile, remoteFile );
502 BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout( BaseRepositoryContentLayout.class );
503 Artifact artifact = layout.getArtifact( path );
505 // Configure Connector (usually done within archiva.xml configuration)
506 saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
507 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
509 StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository( ), artifact );
511 Path proxied1File = Paths.get( REPOPATH_PROXIED1, path );
512 assertFileEquals( expectedFile, downloadedFile.getFilePath( ), proxied1File );
513 assertNoTempFiles( expectedFile );
514 // There are no hashcodes on the proxy side to download, hence the local ones should remain invalid.
515 assertChecksums( expectedFile, "invalid checksum file", "invalid checksum file" );
519 public void testGetAlwaysBadChecksumPresentLocallyAbsentRemoteUsingFailSetting( )
522 String path = "org/apache/maven/test/get-bad-local-checksum/1.0/get-bad-local-checksum-1.0.jar";
523 setupTestableManagedRepository( path );
525 Path expectedFile = managedDefaultDir.resolve( path );
526 Path remoteFile = Paths.get( REPOPATH_PROXIED1, path );
528 setManagedOlderThanRemote( expectedFile, remoteFile );
530 BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout( BaseRepositoryContentLayout.class );
531 Artifact artifact = layout.getArtifact( path );
533 // Configure Connector (usually done within archiva.xml configuration)
534 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FAIL, ReleasesPolicy.ALWAYS,
535 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
537 StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository( ), artifact );
539 assertNotDownloaded( downloadedFile );
540 assertNoTempFiles( expectedFile );
541 // There are no hashcodes on the proxy side to download.
542 // The FAIL policy will delete the checksums as bad.
544 assertChecksums( expectedFile, "invalid checksum file", "invalid checksum file" );
548 public void testGetAlwaysBadChecksumPresentLocallyAbsentRemoteUsingFixSetting( )
551 String path = "org/apache/maven/test/get-bad-local-checksum/1.0/get-bad-local-checksum-1.0.jar";
552 setupTestableManagedRepository( path );
554 Path expectedFile = managedDefaultDir.resolve( path );
555 Path remoteFile = Paths.get( REPOPATH_PROXIED1, path );
557 setManagedOlderThanRemote( expectedFile, remoteFile );
559 BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout( BaseRepositoryContentLayout.class );
560 Artifact artifact = layout.getArtifact( path );
562 // Configure Connector (usually done within archiva.xml configuration)
563 saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
564 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
566 StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository( ), artifact );
568 Path proxied1File = Paths.get( REPOPATH_PROXIED1, path );
569 assertFileEquals( expectedFile, downloadedFile.getFilePath( ), proxied1File );
570 assertNoTempFiles( expectedFile );
571 assertChecksums( expectedFile, "96a08dc80a108cba8efd3b20aec91b32a0b2cbd4 get-bad-local-checksum-1.0.jar",
572 "46fdd6ca55bf1d7a7eb0c858f41e0ccd get-bad-local-checksum-1.0.jar" );