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 @Override
46 protected int getTestRepositoryPort() {
47 return 0;
48 }
49
50 public String getTestRepositoryUrl()
51 {
52 return TestData.getTestRepositoryUrl(0);
53 }
54
55 protected AuthenticationInfo getAuthInfo()
56 {
57 AuthenticationInfo authInfo = super.getAuthInfo();
58
59 authInfo.setUserName( TestData.getUserName() );
60
61 authInfo.setPassphrase( "" );
62
63 return authInfo;
64 }
65
66 protected long getExpectedLastModifiedOnGet( Repository repository, Resource resource )
67 {
68 return new File( repository.getBasedir(), resource.getName() ).lastModified();
69 }
70
71 public void testMissingPrivateKey()
72 throws Exception
73 {
74 File file = File.createTempFile( "wagon", "tmp" );
75 file.delete();
76
77 AuthenticationInfo authInfo = new AuthenticationInfo();
78 authInfo.setPrivateKey( file.getAbsolutePath() );
79
80 try
81 {
82 getWagon().connect( new Repository(), authInfo );
83 fail();
84 }
85 catch ( AuthenticationException e )
86 {
87 assertTrue( true );
88 }
89 }
90
91 public void testBadPrivateKey()
92 throws Exception
93 {
94 File file = File.createTempFile( "wagon", "tmp" );
95 file.deleteOnExit();
96
97 AuthenticationInfo authInfo = new AuthenticationInfo();
98 authInfo.setPrivateKey( file.getAbsolutePath() );
99
100 try
101 {
102 getWagon().connect( new Repository(), authInfo );
103 fail();
104 }
105 catch ( AuthenticationException e )
106 {
107 assertTrue( true );
108 }
109 finally
110 {
111 file.delete();
112 }
113 }
114 }