0

Does anyone have a working example project where you use the Citrus Framework to act as an SSH client to connect to a real server to send a command and validate what it returns?

I've tried to follow the documentation and my project builds and attempts to connect but hangs up on what appears to be a user Prompt asking for the what user to connect with. I found a different SO topic that looks exactly like what I'm experiencing but I don't have the desire to modify or overload the framework's classes since I'm developing this to hand off to a different team and want to stick to the core classes for future compatibility.

Here's the topic that resembles my issue: Skipping Kerberos authentication prompts with JSch

I think it would work if Citrus just exposed a config parameter to turn this option on/off if needed.

session.setConfig(
"PreferredAuthentications", 
"publickey,keyboard-interactive,password");

A working example would be very beneficial.

Community
  • 1
  • 1
smo
  • 3
  • 2

1 Answers1

1

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>
gucce
  • 597
  • 4
  • 12