Any/Test/Backend/_Daemon.pm

filter: Statementstmt 48.4% 32 / 66 Branchbran 21.4% 3 / 14 Conditioncond 38.4% 5 / 13 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 58.3% 7 / 12 Podpod n/a totaltotal 42.3% 47 / 111 CC 17 SCAR 25.8
CC
17
Cov
43%
_check_daemon_and_set_uri
30.0
_validate_backend_opts
18.1
_create_all_keys
12.0
CRAP 13.2
« Any/Test.pm ↑ Summary Any/SCP/Putter/Standard.pm »
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
BranchTrueFalseTotal
$tssh->SUPER::_validate_backend_opts or return 2 0 2
15  
16 2 ▶ unless ($tssh->{run_server}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tssh->{"run_server"}) 0 2 2
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")
l!l&&r!l&&!r
040
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")
ABresult
1X1
011
000
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 }
l!l&&r!l&&!r
020
$tssh->_os_current_user // do { $tssh->_log("Unable to determine current user"); return }
l!l&&r!l&&!r
200
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 }
ABCresult
1XX1
01X1
0011
0000
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)
l!l
02
$tssh->_find_unused_tcp_port // (return)
l!l
20
MC/DC0%0/1
$opts->{"port"} //= $tssh->_find_unused_tcp_port // (return)
$opts->{"port"}
Truth table50%1/2
A
A= $opts->{"port"}
Aresult
11
00
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
BranchTrueFalseTotal
unless ("IO::Socket::INET"->new("PeerAddr", "localhost:$port", "Proto", "tcp", "Timeout", $tssh->{"timeout"})) 2 0 2
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
BranchTrueFalseTotal
$tssh->_create_key($tssh->{"current_opts"}{"${_}_key_path"}) or return 0 0 0
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
BranchTrueFalseTotal
if ($tssh->_is_server_running($uri)) 0 0 0
78 0 ▶ $tssh->_check_and_set_uri($uri) and return 1;
Branch: 1 branch
BranchTrueFalseTotal
$tssh->_check_and_set_uri($uri) and return 1 0 0 0
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
BranchTrueFalseTotal
unless ($tssh->_os_check_proc($tssh->{"daemon_proc"})) 0 0 0
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;
« Any/Test.pm ↑ Summary Any/SCP/Putter/Standard.pm »