这是 Citrus 中 SSH 客户端的工作示例2.7.2
。
我使用 SSH 密钥身份验证和密码身份验证对其进行了测试。该示例显示了 SSH 密钥版本。对于仅密码身份验证,您需要用private-key-path
和private-key-password
替换password="some_password"
。
柑橘上下文.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>
柑橘属性
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>