| 1 | package Net::SSH::Any::Test::Backend::_Daemon; | ||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use Net::SSH::Any; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use Net::SSH::Any::Constants qw(SSHA_BACKEND_ERROR); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use parent 'Net::SSH::Any::Test::Backend::_Base'; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||
| 11 | 2 | ▶ | sub _validate_backend_opts { | ||||||||||||||||||||||||||||||||
|
Subroutine
_validate_backend_opts: called CC=9 SCAR=29.0
| |||||||||||||||||||||||||||||||||||
| 12 | 2 | my $tssh = shift; | |||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||
| 14 | 2 | ▶ | $tssh->SUPER::_validate_backend_opts or return; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||
| 16 | 2 | ▶ | unless ($tssh->{run_server}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 17 | 0 | $tssh->_log("Skipping Dropbear_Daemon backend as run_server is unset"); | |||||||||||||||||||||||||||||||||
| 18 | return | ||||||||||||||||||||||||||||||||||
| 19 | 0 | } | |||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||
| 21 | 2 | my $opts = $tssh->{current_opts}; | |||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||
| 23 | 2 | ▶ | $opts->{"${_}_key_path"} //= $tssh->_backend_wfile("${_}_key") for qw(user host); | ||||||||||||||||||||||||||||||||
|
Condition33%1/3
$$opts{"${_}_key_path"} //= $tssh->_backend_wfile("${_}_key")
MC/DC0%0/2
$$opts{"${_}_key_path"} //= $tssh->_backend_wfile("${_}_key")
$$opts{"${_}_key_path"}
$tssh->_backend_wfile("${_}_key")
Truth table33%1/3
A //= B
A= $$opts{"${_}_key_path"}B= $tssh->_backend_wfile("${_}_key")
| |||||||||||||||||||||||||||||||||||
| 24 | 2 | ▶ | $opts->{user} //= $tssh->_os_current_user // do { | ||||||||||||||||||||||||||||||||
|
Condition33%2/6
$opts->{"user"} //= $tssh->_os_current_user // do {
$tssh->_log("Unable to determine current user");
return
}
$tssh->_os_current_user // do {
$tssh->_log("Unable to determine current user");
return
}
MC/DC0%0/3
$opts->{"user"} //= $tssh->_os_current_user // do {
$tssh->_log("Unable to determine current user");
return
}
$opts->{"user"}
$tssh->_os_current_user
do {
$tssh->_log("Unable to determine current user");
return
}
Truth table0%0/4
A //= B // C
A= $opts->{"user"}B= $tssh->_os_current_userC= do {
$tssh->_log("Unable to determine current user");
return
}
| |||||||||||||||||||||||||||||||||||
| 25 | 0 | $tssh->_log("Unable to determine current user"); | |||||||||||||||||||||||||||||||||
| 26 | 0 | return; | |||||||||||||||||||||||||||||||||
| 27 | }; | ||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||
| 29 | 2 | ▶ | $opts->{port} //= $tssh->_find_unused_tcp_port // return; | ||||||||||||||||||||||||||||||||
|
Condition50%2/4
$opts->{"port"} //= $tssh->_find_unused_tcp_port // (return)
$tssh->_find_unused_tcp_port // (return)
MC/DC0%0/1
$opts->{"port"} //= $tssh->_find_unused_tcp_port // (return)
$opts->{"port"}
Truth table50%1/2
A
A= $opts->{"port"}
| |||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||
| 31 | 2 | 1; | |||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||
| 34 | 2 | my $log_ix; | |||||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | sub _log_fn { | ||||||||||||||||||||||||||||||||
|
Subroutine
_log_fn: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 36 | 0 | my ($tssh, $name) = @_; | |||||||||||||||||||||||||||||||||
| 37 | 0 | my $fn = sprintf "%d-%s.log", ++$log_ix, $name; | |||||||||||||||||||||||||||||||||
| 38 | 0 | $tssh->_backend_wfile($fn); | |||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||
| 41 | 2 | ▶ | sub _find_unused_tcp_port { | ||||||||||||||||||||||||||||||||
|
Subroutine
_find_unused_tcp_port: called CC=3 SCAR=11.6
| |||||||||||||||||||||||||||||||||||
| 42 | 2 | my $tssh = shift; | |||||||||||||||||||||||||||||||||
| 43 | 2 | $tssh->_log("looking for an unused TCP port"); | |||||||||||||||||||||||||||||||||
| 44 | 2 | for (1..32) { | |||||||||||||||||||||||||||||||||
| 45 | 2 | my $port = 5000 + int rand 27000; | |||||||||||||||||||||||||||||||||
| 46 | 2 | ▶ | unless (IO::Socket::INET->new(PeerAddr => "localhost:$port", | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 47 | Proto => 'tcp', | ||||||||||||||||||||||||||||||||||
| 48 | Timeout => $tssh->{timeout})) { | ||||||||||||||||||||||||||||||||||
| 49 | 2 | $tssh->_log("port $port is available"); | |||||||||||||||||||||||||||||||||
| 50 | 2 | return $port; | |||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||
| 53 | 0 | $tssh->_set_error(SSHA_BACKEND_ERROR, "Can't find free TCP port for SSH server"); | |||||||||||||||||||||||||||||||||
| 54 | 0 | return; | |||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||
| 57 | 0 | ▶ | sub _create_all_keys { | ||||||||||||||||||||||||||||||||
|
Subroutine
_create_all_keys: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||
| 58 | 0 | my $tssh = shift; | |||||||||||||||||||||||||||||||||
| 59 | $tssh->_create_key($tssh->{current_opts}{"${_}_key_path"}) or return | ||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | for qw(user host); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 61 | 0 | 1; | |||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | sub _is_localhost { 1 } | ||||||||||||||||||||||||||||||||
|
Subroutine
_is_localhost: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||
| 66 | 0 | ▶ | sub _check_daemon_and_set_uri { | ||||||||||||||||||||||||||||||||
|
Subroutine
_check_daemon_and_set_uri: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||
| 67 | 0 | my $tssh = shift; | |||||||||||||||||||||||||||||||||
| 68 | 0 | my $opts = $tssh->{current_opts}; | |||||||||||||||||||||||||||||||||
| 69 | my $uri = Net::SSH::Any::URI->new(host => "localhost", | ||||||||||||||||||||||||||||||||||
| 70 | port => $opts->{port}, | ||||||||||||||||||||||||||||||||||
| 71 | user => $opts->{user}, | ||||||||||||||||||||||||||||||||||
| 72 | 0 | key_path => $opts->{user_key_path}); | |||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||
| 74 | 0 | $tssh->_log("Waiting for SSH service to pop up at", $uri->as_string ); | |||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||
| 76 | 0 | for (1..20) { | |||||||||||||||||||||||||||||||||
| 77 | 0 | ▶ | if ($tssh->_is_server_running($uri)) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | $tssh->_check_and_set_uri($uri) and return 1; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 79 | 0 | $tssh->_or_set_error(SSHA_BACKEND_ERROR, "unable to connect to server: SSH handshake failed"); | |||||||||||||||||||||||||||||||||
| 80 | 0 | return; | |||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | unless ($tssh->_os_check_proc($tssh->{daemon_proc})) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 83 | 0 | $tssh->_or_set_error(SSHA_BACKEND_ERROR, "unable to connect to server: daemon died"); | |||||||||||||||||||||||||||||||||
| 84 | 0 | last; | |||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||
| 86 | 0 | $tssh->_log("Retrying in 1s [$_]..."); | |||||||||||||||||||||||||||||||||
| 87 | 0 | sleep 1; | |||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||
| 90 | 0 | $tssh->_or_set_error(SSHA_BACKEND_ERROR, "unable to connect to server: too many retries"); | |||||||||||||||||||||||||||||||||
| 91 | () | ||||||||||||||||||||||||||||||||||
| 92 | 0 | } | |||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||
| 94 | 0 | ▶ | sub _stop { | ||||||||||||||||||||||||||||||||
|
Subroutine
_stop: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 95 | 0 | my $tssh = shift; | |||||||||||||||||||||||||||||||||
| 96 | 0 | my $daemon = $tssh->_daemon_name; | |||||||||||||||||||||||||||||||||
| 97 | 0 | my $proc = $tssh->{daemon_proc}; | |||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||
| 99 | 0 | $tssh->_log("Stopping daemon process, pid", $proc->{pid}); | |||||||||||||||||||||||||||||||||
| 100 | 0 | $tssh->_os_wait_proc($proc, 0, 1); | |||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||
| 103 | 2 | 1; | |||||||||||||||||||||||||||||||||