]> source.dussan.org Git - archiva.git/blob
e9ade0479dc7c83bbbf903212304d1d07ee0b22e
[archiva.git] /
1 package org.apache.archiva.proxy;
2
3 /*
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
11  *
12  *  http://www.apache.org/licenses/LICENSE-2.0
13  *
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
19  * under the License.
20  */
21
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.maven.wagon.ResourceDoesNotExistException;
29 import org.easymock.EasyMock;
30 import org.junit.Test;
31
32 import java.io.File;
33 import java.nio.file.Files;
34 import java.nio.file.Path;
35 import java.nio.file.Paths;
36 import java.nio.file.StandardCopyOption;
37
38 import static org.junit.Assert.assertFalse;
39 import static org.junit.Assert.assertNull;
40
41 /**
42  * ChecksumTransferTest
43  *
44  *
45  */
46 public class ChecksumTransferTest
47     extends AbstractProxyTestCase
48 {
49     @Test
50     public void testGetChecksumWhenConnectorIsDisabled()
51         throws Exception
52     {
53         String path = "org/apache/maven/test/get-checksum-both-right/1.0/get-checksum-both-right-1.0.jar";
54         setupTestableManagedRepository( path );
55
56         Path expectedFile = managedDefaultDir.resolve( path );
57         ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
58
59         org.apache.archiva.common.utils.FileUtils.deleteDirectory( expectedFile.getParent() );
60         assertFalse( Files.exists(expectedFile) );
61
62         // Configure Connector (usually done within archiva.xml configuration)
63         saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
64                        SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, true );
65
66         Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
67
68         assertNull( downloadedFile );
69     }
70
71     @Test
72     public void testGetChecksumBothCorrect()
73         throws Exception
74     {
75         String path = "org/apache/maven/test/get-checksum-both-right/1.0/get-checksum-both-right-1.0.jar";
76         setupTestableManagedRepository( path );
77
78         Path expectedFile = managedDefaultDir.resolve( path );
79         ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
80
81         org.apache.archiva.common.utils.FileUtils.deleteDirectory( expectedFile.getParent() );
82         assertFalse( Files.exists(expectedFile) );
83
84         // Configure Connector (usually done within archiva.xml configuration)
85         saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
86                        SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
87
88         Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
89
90         Path proxied1File = Paths.get( REPOPATH_PROXIED1, path );
91         assertFileEquals( expectedFile, downloadedFile, proxied1File );
92         assertNoTempFiles( expectedFile );
93         assertChecksums( expectedFile, "066d76e459f7782c312c31e8a11b3c0f1e3e43a7 *get-checksum-both-right-1.0.jar",
94                          "e58f30c6a150a2e843552438d18e15cb *get-checksum-both-right-1.0.jar" );
95     }
96
97     @Test
98     public void testGetChecksumCorrectSha1NoMd5()
99         throws Exception
100     {
101         String path = "org/apache/maven/test/get-checksum-sha1-only/1.0/get-checksum-sha1-only-1.0.jar";
102         setupTestableManagedRepository( path );
103
104         Path expectedFile = managedDefaultDir.resolve( path );
105         ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
106
107         FileUtils.deleteDirectory( expectedFile.getParent() );
108         assertFalse( Files.exists(expectedFile) );
109
110         // Configure Connector (usually done within archiva.xml configuration)
111         saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
112                        SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
113
114         Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
115
116         Path proxied1File = Paths.get( REPOPATH_PROXIED1, path );
117         assertFileEquals( expectedFile, downloadedFile, proxied1File );
118         assertNoTempFiles( expectedFile );
119         assertChecksums( expectedFile, "748a3a013bf5eacf2bbb40a2ac7d37889b728837 *get-checksum-sha1-only-1.0.jar",
120                          null );
121     }
122
123     @Test
124     public void testGetChecksumNoSha1CorrectMd5()
125         throws Exception
126     {
127         String path = "org/apache/maven/test/get-checksum-md5-only/1.0/get-checksum-md5-only-1.0.jar";
128         setupTestableManagedRepository( path );
129
130         Path expectedFile = managedDefaultDir.resolve( path );
131         ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
132
133         FileUtils.deleteDirectory( expectedFile.getParent() );
134         assertFalse( Files.exists(expectedFile) );
135
136         // Configure Connector (usually done within archiva.xml configuration)
137         saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
138                        SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
139
140         Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
141
142         Path proxied1File = Paths.get( REPOPATH_PROXIED1, path );
143         assertFileEquals( expectedFile, downloadedFile, proxied1File );
144         assertNoTempFiles( expectedFile );
145         assertChecksums( expectedFile, null, "f3af5201bf8da801da37db8842846e1c *get-checksum-md5-only-1.0.jar" );
146     }
147
148     @Test
149     public void testGetWithNoChecksumsUsingIgnoredSetting()
150         throws Exception
151     {
152         String path = "org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar";
153         setupTestableManagedRepository( path );
154
155         Path expectedFile = managedDefaultDir.resolve( path );
156         ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
157
158         FileUtils.deleteDirectory( expectedFile.getParent() );
159         assertFalse( Files.exists(expectedFile) );
160
161         // Configure Connector (usually done within archiva.xml configuration)
162         saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
163                        SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
164
165         Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
166
167         Path proxied1File = Paths.get( REPOPATH_PROXIED1, path );
168         assertFileEquals( expectedFile, downloadedFile, proxied1File );
169         assertNoTempFiles( expectedFile );
170         assertChecksums( expectedFile, null, null );
171     }
172
173     @Test
174     public void testGetChecksumBadSha1BadMd5IgnoredSetting()
175         throws Exception
176     {
177         String path = "org/apache/maven/test/get-checksum-both-bad/1.0/get-checksum-both-bad-1.0.jar";
178         setupTestableManagedRepository( path );
179
180         Path expectedFile = managedDefaultDir.resolve( path );
181         ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
182
183         FileUtils.deleteDirectory( expectedFile.getParent() );
184         assertFalse( Files.exists(expectedFile) );
185
186         // Configure Connector (usually done within archiva.xml configuration)
187         saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
188                        SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
189
190         Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
191
192         Path proxied1File = Paths.get( REPOPATH_PROXIED1, path );
193         assertFileEquals( expectedFile, downloadedFile, proxied1File );
194         assertNoTempFiles( expectedFile );
195         assertChecksums( expectedFile, "invalid checksum file", "invalid checksum file" );
196     }
197
198     @Test
199     public void testGetChecksumBadSha1BadMd5FailSetting()
200         throws Exception
201     {
202         String path = "org/apache/maven/test/get-checksum-both-bad/1.0/get-checksum-both-bad-1.0.jar";
203         setupTestableManagedRepository( path );
204
205         Path expectedFile = managedDefaultDir.resolve( path );
206         ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
207
208         FileUtils.deleteDirectory( expectedFile.getParent() );
209         assertFalse( Files.exists(expectedFile) );
210
211         // Configure Connector (usually done within archiva.xml configuration)
212         saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FAIL, ReleasesPolicy.ALWAYS,
213                        SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
214
215         Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
216
217         assertNotDownloaded( downloadedFile );
218         assertChecksums( expectedFile, null, null );
219     }
220
221     @Test
222     public void testGetChecksumBadSha1BadMd5FixSetting()
223         throws Exception
224     {
225         String path = "org/apache/maven/test/get-checksum-both-bad/1.0/get-checksum-both-bad-1.0.jar";
226         setupTestableManagedRepository( path );
227
228         Path expectedFile = managedDefaultDir.resolve( path );
229         ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
230
231         FileUtils.deleteDirectory( expectedFile.getParent() );
232         assertFalse( Files.exists(expectedFile) );
233
234         // Configure Connector (usually done within archiva.xml configuration)
235         saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
236                        SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
237
238         Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
239
240         Path proxied1File = Paths.get( REPOPATH_PROXIED1, path );
241         assertFileEquals( expectedFile, downloadedFile, proxied1File );
242         assertNoTempFiles( expectedFile );
243         assertChecksums( expectedFile, "4ec20a12dc91557330bd0b39d1805be5e329ae56  get-checksum-both-bad-1.0.jar",
244                          "a292491a35925465e693a44809a078b5  get-checksum-both-bad-1.0.jar" );
245     }
246
247     @Test
248     public void testGetChecksumCorrectSha1BadMd5UsingFailSetting()
249         throws Exception
250     {
251         String path = "org/apache/maven/test/get-checksum-sha1-bad-md5/1.0/get-checksum-sha1-bad-md5-1.0.jar";
252         setupTestableManagedRepository( path );
253
254         Path expectedFile = managedDefaultDir.resolve(path);
255         ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
256
257         FileUtils.deleteDirectory( expectedFile.getParent() );
258         assertFalse( Files.exists(expectedFile) );
259
260         // Configure Connector (usually done within archiva.xml configuration)
261         saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FAIL, ReleasesPolicy.ALWAYS,
262                        SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
263
264         Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
265
266         assertNotDownloaded( downloadedFile );
267         assertChecksums( expectedFile, null, null );
268     }
269
270     @Test
271     public void testGetChecksumNoSha1CorrectMd5UsingFailSetting()
272         throws Exception
273     {
274         String path = "org/apache/maven/test/get-checksum-md5-only/1.0/get-checksum-md5-only-1.0.jar";
275         setupTestableManagedRepository( path );
276
277         Path expectedFile = managedDefaultDir.resolve(path);
278         ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
279
280         FileUtils.deleteDirectory( expectedFile.getParent() );
281         assertFalse( Files.exists(expectedFile) );
282
283         // Configure Connector (usually done within archiva.xml configuration)
284         saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FAIL, ReleasesPolicy.ALWAYS,
285                        SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
286
287         Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
288
289         // This is a success situation. No SHA1 with a Good MD5.
290         Path proxied1File = Paths.get(REPOPATH_PROXIED1, path);
291         assertFileEquals( expectedFile, downloadedFile, proxied1File );
292         assertNoTempFiles( expectedFile );
293         assertChecksums( expectedFile, null, "f3af5201bf8da801da37db8842846e1c *get-checksum-md5-only-1.0.jar" );
294     }
295
296     @Test
297     public void testGetWithNoChecksumsUsingFailSetting()
298         throws Exception
299     {
300         String path = "org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar";
301         setupTestableManagedRepository( path );
302
303         Path expectedFile = managedDefaultDir.resolve(path);
304         ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
305
306         FileUtils.deleteDirectory( expectedFile.getParent() );
307         assertFalse( Files.exists(expectedFile) );
308
309         // Configure Connector (usually done within archiva.xml configuration)
310         saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FAIL, ReleasesPolicy.ALWAYS,
311                        SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
312
313         Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
314
315         assertNotDownloaded( downloadedFile );
316         assertChecksums( expectedFile, null, null );
317     }
318
319     @Test
320     public void testGetChecksumCorrectSha1BadMd5UsingIgnoredSetting()
321         throws Exception
322     {
323         String path = "org/apache/maven/test/get-checksum-sha1-bad-md5/1.0/get-checksum-sha1-bad-md5-1.0.jar";
324         setupTestableManagedRepository( path );
325
326         Path expectedFile = managedDefaultDir.resolve(path);
327         ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
328
329         FileUtils.deleteDirectory( expectedFile.getParent() );
330         assertFalse( Files.exists(expectedFile) );
331
332         // Configure Connector (usually done within archiva.xml configuration)
333         saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
334                        SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
335
336         Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
337
338         Path proxied1File = Paths.get(REPOPATH_PROXIED1, path);
339         assertFileEquals( expectedFile, downloadedFile, proxied1File );
340         assertNoTempFiles( expectedFile );
341         assertChecksums( expectedFile, "3dd1a3a57b807d3ef3fbc6013d926c891cbb8670 *get-checksum-sha1-bad-md5-1.0.jar",
342                          "invalid checksum file" );
343     }
344
345     @Test
346     public void testGetChecksumCorrectSha1BadMd5UsingFixSetting()
347         throws Exception
348     {
349         String path = "org/apache/maven/test/get-checksum-sha1-bad-md5/1.0/get-checksum-sha1-bad-md5-1.0.jar";
350         setupTestableManagedRepository( path );
351
352         Path expectedFile = managedDefaultDir.resolve(path);
353         ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
354
355         FileUtils.deleteDirectory( expectedFile.getParent() );
356         assertFalse( Files.exists(expectedFile) );
357
358         // Configure Connector (usually done within archiva.xml configuration)
359         saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
360                        SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
361
362
363         Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
364
365         Path proxied1File = Paths.get(REPOPATH_PROXIED1, path);
366         assertFileEquals( expectedFile, downloadedFile, proxied1File );
367         assertNoTempFiles( expectedFile );
368         assertChecksums( expectedFile, "3dd1a3a57b807d3ef3fbc6013d926c891cbb8670 *get-checksum-sha1-bad-md5-1.0.jar",
369                          "c35f3b76268b73a4ba617f6f275c49ab  get-checksum-sha1-bad-md5-1.0.jar" );
370     }
371
372     @Test
373     public void testGetChecksumNoSha1CorrectMd5UsingFixSetting()
374         throws Exception
375     {
376         String path = "org/apache/maven/test/get-checksum-md5-only/1.0/get-checksum-md5-only-1.0.jar";
377         setupTestableManagedRepository( path );
378
379         Path expectedFile = managedDefaultDir.resolve(path);
380         ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
381
382         FileUtils.deleteDirectory( expectedFile.getParent() );
383         assertFalse( Files.exists(expectedFile) );
384
385         // Configure Connector (usually done within archiva.xml configuration)
386         saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
387                        SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
388
389         Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
390
391         Path proxied1File = Paths.get(REPOPATH_PROXIED1, path);
392         assertFileEquals( expectedFile, downloadedFile, proxied1File );
393         assertNoTempFiles( expectedFile );
394         assertChecksums( expectedFile, "71f7dc3f72053a3f2d9fdd6fef9db055ef957ffb  get-checksum-md5-only-1.0.jar",
395                          "f3af5201bf8da801da37db8842846e1c *get-checksum-md5-only-1.0.jar" );
396     }
397
398     @Test
399     public void testGetWithNoChecksumsUsingFixSetting()
400         throws Exception
401     {
402         String path = "org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar";
403         setupTestableManagedRepository( path );
404
405         Path expectedFile = managedDefaultDir.resolve(path);
406         ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
407
408         FileUtils.deleteDirectory( expectedFile.getParent() );
409         assertFalse( Files.exists(expectedFile) );
410
411         // Configure Connector (usually done within archiva.xml configuration)
412         saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
413                        SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
414
415         Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
416
417         Path proxied1File = Paths.get(REPOPATH_PROXIED1, path);
418         assertFileEquals( expectedFile, downloadedFile, proxied1File );
419         assertNoTempFiles( expectedFile );
420         assertChecksums( expectedFile, "1f12821c5e43e1a0b76b9564a6ddb0548ccb9486  get-default-layout-1.0.jar",
421                          "3f7341545f21226b6f49a3c2704cb9be  get-default-layout-1.0.jar" );
422     }
423
424     @Test
425     public void testGetChecksumNotFoundOnRemote()
426         throws Exception
427     {
428         String path = "org/apache/maven/test/get-checksum-sha1-only/1.0/get-checksum-sha1-only-1.0.jar";
429         setupTestableManagedRepository( path );
430
431         Path expectedFile = managedDefaultDir.resolve( path );
432         ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
433
434         FileUtils.deleteDirectory( expectedFile.getParent() );
435         assertFalse( Files.exists(expectedFile.getParent()) );
436         assertFalse( Files.exists(expectedFile) );
437
438         saveRemoteRepositoryConfig( "badproxied", "Bad Proxied", "test://bad.machine.com/repo/", "default" );
439
440         // Configure Connector (usually done within archiva.xml configuration)
441         saveConnector( ID_DEFAULT_MANAGED, "badproxied", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
442                        SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
443
444         wagonMock.get( EasyMock.eq( path ), EasyMock.anyObject( File.class ));
445         EasyMock.expectLastCall().once();
446
447         wagonMock.get( EasyMock.eq( path + ".sha1" ), EasyMock.anyObject( File.class ));
448         EasyMock.expectLastCall().once();
449
450         wagonMock.get( EasyMock.eq( path + ".md5" ), EasyMock.anyObject( File.class ));
451         EasyMock.expectLastCall().andThrow( new ResourceDoesNotExistException( "Resource does not exist." ) ).once();
452
453         wagonMockControl.replay();
454
455         Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
456
457         wagonMockControl.verify();
458
459         // Do what the mock doesn't do.
460         Path proxyPath = Paths.get( REPOPATH_PROXIED1, path ).toAbsolutePath();
461         Path localPath = managedDefaultDir.resolve( path ).toAbsolutePath();
462         Files.copy( proxyPath, localPath, StandardCopyOption.REPLACE_EXISTING);
463         Files.copy( proxyPath.resolveSibling( proxyPath.getFileName() + ".sha1" ),
464             localPath.resolveSibling(  localPath.getFileName() + ".sha1" ), StandardCopyOption.REPLACE_EXISTING );
465
466         // Test results.
467         Path proxied1File = Paths.get( REPOPATH_PROXIED1, path );
468         assertFileEquals( expectedFile, downloadedFile, proxied1File );
469         assertNoTempFiles( expectedFile );
470         assertChecksums( expectedFile, "748a3a013bf5eacf2bbb40a2ac7d37889b728837 *get-checksum-sha1-only-1.0.jar",
471                          null );
472     }
473
474     @Test
475     public void testGetAlwaysBadChecksumPresentLocallyAbsentRemoteUsingIgnoredSetting()
476         throws Exception
477     {
478         String path = "org/apache/maven/test/get-bad-local-checksum/1.0/get-bad-local-checksum-1.0.jar";
479         setupTestableManagedRepository( path );
480
481         Path expectedFile = managedDefaultDir.resolve( path );
482         Path remoteFile = Paths.get( REPOPATH_PROXIED1, path );
483
484         setManagedOlderThanRemote( expectedFile, remoteFile );
485
486         ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
487
488         // Configure Connector (usually done within archiva.xml configuration)
489         saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
490                        SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
491
492         Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
493
494         Path proxied1File = Paths.get( REPOPATH_PROXIED1, path );
495         assertFileEquals( expectedFile, downloadedFile, proxied1File );
496         assertNoTempFiles( expectedFile );
497         // There are no hashcodes on the proxy side to download, hence the local ones should remain invalid.
498         assertChecksums( expectedFile, "invalid checksum file", "invalid checksum file" );
499     }
500
501     @Test
502     public void testGetAlwaysBadChecksumPresentLocallyAbsentRemoteUsingFailSetting()
503         throws Exception
504     {
505         String path = "org/apache/maven/test/get-bad-local-checksum/1.0/get-bad-local-checksum-1.0.jar";
506         setupTestableManagedRepository( path );
507
508         Path expectedFile = managedDefaultDir.resolve( path );
509         Path remoteFile = Paths.get( REPOPATH_PROXIED1, path );
510
511         setManagedOlderThanRemote( expectedFile, remoteFile );
512
513         ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
514
515         // Configure Connector (usually done within archiva.xml configuration)
516         saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FAIL, ReleasesPolicy.ALWAYS,
517                        SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
518
519         Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
520
521         assertNotDownloaded( downloadedFile );
522         assertNoTempFiles( expectedFile );
523         // There are no hashcodes on the proxy side to download.
524         // The FAIL policy will delete the checksums as bad.
525
526         assertChecksums( expectedFile, "invalid checksum file", "invalid checksum file" );
527     }
528
529     @Test
530     public void testGetAlwaysBadChecksumPresentLocallyAbsentRemoteUsingFixSetting()
531         throws Exception
532     {
533         String path = "org/apache/maven/test/get-bad-local-checksum/1.0/get-bad-local-checksum-1.0.jar";
534         setupTestableManagedRepository( path );
535
536         Path expectedFile = managedDefaultDir.resolve(path);
537         Path remoteFile = Paths.get(REPOPATH_PROXIED1, path);
538
539         setManagedOlderThanRemote( expectedFile, remoteFile );
540
541         ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
542
543         // Configure Connector (usually done within archiva.xml configuration)
544         saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
545                        SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
546
547         Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
548
549         Path proxied1File = Paths.get(REPOPATH_PROXIED1, path);
550         assertFileEquals( expectedFile, downloadedFile, proxied1File );
551         assertNoTempFiles( expectedFile );
552         assertChecksums( expectedFile, "96a08dc80a108cba8efd3b20aec91b32a0b2cbd4  get-bad-local-checksum-1.0.jar",
553                          "46fdd6ca55bf1d7a7eb0c858f41e0ccd  get-bad-local-checksum-1.0.jar" );
554     }
555 }