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