1 | |
package org.apache.maven.wagon.providers.ssh.knownhost; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
import org.apache.maven.wagon.Wagon; |
23 | |
import org.apache.maven.wagon.providers.ssh.SshWagon; |
24 | |
import org.apache.maven.wagon.providers.ssh.TestData; |
25 | |
import org.apache.maven.wagon.repository.Repository; |
26 | |
import org.codehaus.plexus.PlexusTestCase; |
27 | |
|
28 | 0 | public class KnownHostsProviderTestCase |
29 | |
extends PlexusTestCase |
30 | |
{ |
31 | |
protected KnownHostsProvider okHostsProvider; |
32 | |
|
33 | |
protected KnownHostsProvider failHostsProvider; |
34 | |
|
35 | |
protected KnownHostsProvider changedHostsProvider; |
36 | |
|
37 | |
private SshWagon wagon; |
38 | |
|
39 | |
private Repository source; |
40 | |
|
41 | 0 | private static final String CORRECT_KEY = TestData.getHostKey(); |
42 | |
|
43 | |
private static final String CHANGED_KEY = |
44 | |
"AAAAB3NzaC1yc2EAAAABIwAAAQEA8VLKkfHl2CNqW+m0603z07dyweWzzdVGQlMPUX4z1264E7M/h+6lPKiOo+u49CL7eQVA+FtW" |
45 | |
+ "TZoJ3oBAMABcKnHx41TnSpQUkbdR6rzyC6IG1lXiVtEjG2w7DUnxpCtVo5PaQuJobwoXv5NNL3vx03THPgcDJquLPWvGnDWhnXoEh" |
46 | |
+ "3/6c7rprwT+PrjZ6LIT35ZCUGajoehhF151oNbFMQHllfR6EAiZIP0z0nIVI+Jiv6g+XZapumVPVYjdOfxvLKQope1H9HJamT3bDI" |
47 | |
+ "m8mkebUB10DzQJYxFt4/0wiNH3L4jsIFn+CiW1/IQm5yyff1CUO87OqVbtp9BlaXZNmw=="; |
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
public void testIncorrectKey() |
56 | |
throws Exception |
57 | |
{ |
58 | 0 | wagon.setKnownHostsProvider( failHostsProvider ); |
59 | |
|
60 | |
try |
61 | |
{ |
62 | 0 | wagon.connect( source ); |
63 | |
|
64 | 0 | fail( "Should not have successfully connected - host is not known" ); |
65 | |
} |
66 | 0 | catch ( UnknownHostException e ) |
67 | |
{ |
68 | |
|
69 | 0 | } |
70 | 0 | } |
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
public void testChangedKey() |
78 | |
throws Exception |
79 | |
{ |
80 | 0 | wagon.setKnownHostsProvider( changedHostsProvider ); |
81 | |
|
82 | |
try |
83 | |
{ |
84 | 0 | wagon.connect( source ); |
85 | |
|
86 | 0 | fail( "Should not have successfully connected - host is changed" ); |
87 | |
} |
88 | 0 | catch ( KnownHostChangedException e ) |
89 | |
{ |
90 | |
|
91 | 0 | } |
92 | 0 | } |
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
public void testCorrectKey() |
100 | |
throws Exception |
101 | |
{ |
102 | 0 | wagon.setKnownHostsProvider( okHostsProvider ); |
103 | |
|
104 | 0 | wagon.connect( source ); |
105 | |
|
106 | 0 | assertTrue( true ); |
107 | 0 | } |
108 | |
|
109 | |
protected void setUp() |
110 | |
throws Exception |
111 | |
{ |
112 | 0 | super.setUp(); |
113 | 0 | source = |
114 | |
new Repository( "test", "scp://" + TestData.getUserName() + "@" + TestData.getHostname() + "/tmp/foo" ); |
115 | |
|
116 | 0 | wagon = (SshWagon) lookup( Wagon.ROLE, "scp" ); |
117 | 0 | wagon.setInteractive( false ); |
118 | |
|
119 | 0 | this.okHostsProvider = new SingleKnownHostProvider( TestData.getHostname(), CORRECT_KEY ); |
120 | 0 | this.failHostsProvider = new SingleKnownHostProvider( "beaver.codehaus.org", CORRECT_KEY ); |
121 | 0 | this.changedHostsProvider = new SingleKnownHostProvider( TestData.getHostname(), CHANGED_KEY ); |
122 | 0 | } |
123 | |
} |