Here is a working example of a SSH client in Citrus 2.7.2
.
I tested it with both SSH key authentication, and password authentication. The example shows the SSH key version. For the password-only authentication you need to substitute private-key-path
and private-key-password
with password="some_password"
.
citrus-context.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:citrus-ssh="http://www.citrusframework.org/schema/ssh/config"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.citrusframework.org/schema/ssh/config
http://www.citrusframework.org/schema/ssh/config/citrus-ssh-config.xsd">
<context:property-placeholder location="classpath:citrus.properties"/>
<citrus-ssh:client id="sshClient"
user="${ssh.user}"
host="${ssh.host}"
port="22"
private-key-path="${ssh.private.key.path}"
private-key-password="${ssh.private.key.password}"/>
</beans>
citrus.properties
ssh.user=some_user
ssh.host=some.host
ssh.private.key.path=/home/some_user/.ssh/id_rsa
ssh.private.key.password=secret_password
SshTest_IT.xml
<?xml version="1.0" encoding="UTF-8"?>
<spring:beans xmlns="http://www.citrusframework.org/schema/testcase"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:sshmsg="http://www.citrusframework.org/schema/ssh/message"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.citrusframework.org/schema/testcase
http://www.citrusframework.org/schema/testcase/citrus-testcase.xsd
http://www.citrusframework.org/schema/ssh/message
http://citrusframework.org/schema/ssh/message/citrus-ssh-message.xsd">
<testcase name="SshTest_IT">
<actions>
<send endpoint="sshClient">
<message>
<payload>
<sshmsg:ssh-request>
<sshmsg:command>ls -la</sshmsg:command>
<sshmsg:stdin></sshmsg:stdin>
</sshmsg:ssh-request>
</payload>
</message>
</send>
<receive endpoint="sshClient">
<message validator="">
<payload>
<sshmsg:ssh-response>
<sshmsg:stdout>@contains('.bashrc')@</sshmsg:stdout>
<sshmsg:stderr></sshmsg:stderr>
<sshmsg:exit>0</sshmsg:exit>
</sshmsg:ssh-response>
</payload>
</message>
</receive>
</actions>
</testcase>
</spring:beans>