NAME
Net::SSH::Any::Test - Test SSH modules
SYNOPSIS
use Net::SSH::Any::Test;
my $tssh = Net::SSH::Any::Test->new;
$tssh->error and die "Unable to get a working SSH service";
my $ssh = My::SSH::Module->new($tssh->uri);
...
DESCRIPTION
Net::SSH::Any::Test
is a module that tries hard to provide a working SSH service that can be used for testing SSH client packages as Net::SSH::Any.
It has several backends implementing different strategies that range from finding an already working SSH server to installing, setting up and running a new temporary one.
The backends are tried in turn until one is found able to provide a working SSH service.
API
- $tssh = Net::SSH::Any::Test->new(%opts)
-
This method creates and returns a new object.
It accepts the following options:
- backends => \@backends
-
Array with the names of the backends which the module should try in order to provide the working SSH service.
For instance:
my $tssh = Net::SSH::Any::Test->new(..., backends => ['Cygwin']);
- run_server => 0
-
Disables backends that may start a new SSH server in any way on the local machine.
- test_commands => \@cmds
-
A set of commands that are executed on the remote server in order to determine if it is working properly or not. The server is considered good when any of the commands completes successfully.
The default set includes commands for common Linux, UNIX and MS Windows systems.
- working_dir => $path
-
Path to a directory where to write temporary files and logs.
- timeout => $timeout
-
The given value is later honoured by methods doing network IO.
- logger => sub { ... }
-
A logging function that will be used for reporting information to the user. The function is called with the logging file handle and the message as arguments.
For instance, using
diag
from Test::More:use Test::More; ... sub my_logger { my ($fh, $msg) = @_; # note that $fh is just not used! diag $msg; } my $tssh = Net::SSH::Any::Test->new(..., logger => \&my_logger);
The default logger prints the messages to the logger file handle.
- logger_fh => $fh
-
Sets the logger file handle. Defaults to
STDERR
. - target => $uri
- targets => \@uris
-
Set of server targets to be used by the Remote backend.
The information in the targets is combined with that passed in other options. For instance:
my $tssh = Net::SSH::Any::Test->new(target => 'ssh://leo_caldas@10.0.3.1/', password => $password, port => 1022);
See also Net::SSH::Any::URI.
- port => $port
-
Sets the SSH port number used when looking for running servers.
- password => $password
-
Sets the SSH password.
- key_path => $private_key_path
- key_paths => \@private_key_paths
-
Path to files containing private keys to use for authentication.
- backend_opts => { $backend_name => \%opts, ... }
-
Per backend specific options.
- $uri = $tssh->uri
-
Returns a Net::SSH::Any::URI object representing a working SSH service.
- $error = $tssh->error
-
Returns the last error.
- $tssh->stop
-
Terminates any running process (i.e. any SSH server).
BACKENDS
The following backends are currently available.
They lack proper documentation as this is a work in progress yet.
- Remote
-
Tries to connect to localhost or to any other given service.
- OpenSSH_Daemon
-
Starts a new OpenSSH server.
- Dropbear_Daemon
-
Starts a new Dropbear server.
Note: requires a patched version of dropbear installed (https://github.com/salva/dropbear).
- Cygwin
-
In MS Windows systems, downloads and install Cygwin, including the OpenSSH packages, and uses then to run a SSH server.