1 package org.apache.maven.wagon.providers.ssh.jsch;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23 import java.io.IOException;
24
25 import org.apache.maven.wagon.ConnectionException;
26 import org.apache.maven.wagon.StreamingWagonTestCase;
27 import org.apache.maven.wagon.authentication.AuthenticationException;
28 import org.apache.maven.wagon.authentication.AuthenticationInfo;
29 import org.apache.maven.wagon.providers.ssh.TestData;
30 import org.apache.maven.wagon.repository.Repository;
31 import org.apache.maven.wagon.resource.Resource;
32
33
34
35
36
37 public class ScpWagonWithSshPrivateKeySearchTest
38 extends StreamingWagonTestCase
39 {
40 protected String getProtocol()
41 {
42 return "scp";
43 }
44
45 public String getTestRepositoryUrl()
46 {
47 return TestData.getTestRepositoryUrl(0);
48 }
49
50 protected AuthenticationInfo getAuthInfo()
51 {
52 AuthenticationInfo authInfo = super.getAuthInfo();
53
54 authInfo.setUserName( TestData.getUserName() );
55
56 authInfo.setPassphrase( "" );
57
58 return authInfo;
59 }
60
61 protected long getExpectedLastModifiedOnGet( Repository repository, Resource resource )
62 {
63 return new File( repository.getBasedir(), resource.getName() ).lastModified();
64 }
65
66 public void testMissingPrivateKey()
67 throws Exception
68 {
69 File file = File.createTempFile( "wagon", "tmp" );
70 file.delete();
71
72 AuthenticationInfo authInfo = new AuthenticationInfo();
73 authInfo.setPrivateKey( file.getAbsolutePath() );
74
75 try
76 {
77 getWagon().connect( new Repository(), authInfo );
78 fail();
79 }
80 catch ( AuthenticationException e )
81 {
82 assertTrue( true );
83 }
84 }
85
86 public void testBadPrivateKey()
87 throws Exception
88 {
89 File file = File.createTempFile( "wagon", "tmp" );
90 file.deleteOnExit();
91
92 AuthenticationInfo authInfo = new AuthenticationInfo();
93 authInfo.setPrivateKey( file.getAbsolutePath() );
94
95 try
96 {
97 getWagon().connect( new Repository(), authInfo );
98 fail();
99 }
100 catch ( AuthenticationException e )
101 {
102 assertTrue( true );
103 }
104 finally
105 {
106 file.delete();
107 }
108 }
109 }