1 package org.apache.maven.wagon.providers.ssh.external;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.commons.io.FileUtils;
23 import org.apache.maven.wagon.Streams;
24 import org.apache.maven.wagon.Wagon;
25 import org.apache.maven.wagon.authentication.AuthenticationInfo;
26 import org.apache.maven.wagon.providers.ssh.AbstractEmbeddedScpWagonWithKeyTest;
27 import org.codehaus.plexus.util.cli.CommandLineUtils;
28 import org.codehaus.plexus.util.cli.Commandline;
29
30 import java.io.File;
31
32
33
34
35
36 public class EmbeddedScpExternalWagonWithKeyTest
37 extends AbstractEmbeddedScpWagonWithKeyTest
38 {
39
40
41 @Override
42 protected Wagon getWagon()
43 throws Exception
44 {
45 ScpExternalWagon scpWagon = (ScpExternalWagon) super.getWagon();
46 scpWagon.setInteractive( false );
47 File dummyKnowHostsFile = new File( "target/dummy_knowhost" );
48 if ( dummyKnowHostsFile.exists() )
49 {
50 dummyKnowHostsFile.delete();
51 }
52 scpWagon.setScpArgs(
53 "-o StrictHostKeyChecking=no -o UserKnownHostsFile=" + dummyKnowHostsFile.getCanonicalPath() );
54 scpWagon.setSshArgs(
55 "-o StrictHostKeyChecking=no -o UserKnownHostsFile=" + dummyKnowHostsFile.getCanonicalPath() );
56 dummyKnowHostsFile.deleteOnExit();
57 return scpWagon;
58 }
59
60
61 protected String getProtocol()
62 {
63 return "scpexe";
64 }
65
66
67 protected AuthenticationInfo getAuthInfo()
68 {
69 try
70 {
71 AuthenticationInfo authInfo = super.getAuthInfo();
72
73 authInfo.setUserName( "guest" );
74 File sshKeysTarget = new File( "target/ssh-keys" );
75 FileUtils.copyDirectory( new File( "src/test/ssh-keys" ), sshKeysTarget );
76
77
78 Commandline commandline = new Commandline( "chmod" );
79 commandline.createArg().setValue( "-R" );
80 commandline.createArg().setValue( "700" );
81 commandline.createArg().setValue( sshKeysTarget.getCanonicalPath() );
82 CommandLineUtils.StringStreamConsumer out = new CommandLineUtils.StringStreamConsumer();
83 CommandLineUtils.StringStreamConsumer err = new CommandLineUtils.StringStreamConsumer();
84 int exitCode = CommandLineUtils.executeCommandLine( commandline, out, err );
85 Streams streams = new Streams();
86 streams.setOut( out.getOutput() );
87 streams.setErr( err.getOutput() );
88 if ( exitCode != 0 )
89 {
90 throw new RuntimeException(
91 "fail to chmod exit code " + exitCode + ", error" + streams.getErr() + ", out "
92 + streams.getOut() );
93 }
94
95 authInfo.setPrivateKey( new File( sshKeysTarget, "id_rsa" ).getCanonicalPath() );
96
97 return authInfo;
98 }
99 catch ( Exception e )
100 {
101 throw new RuntimeException( e.getMessage(), e );
102
103 }
104 }
105
106 public void testFailedGetToStream()
107 throws Exception
108 {
109
110 }
111
112
113 }