Any/Test/Backend/Dropbear_Daemon.pm

filter: Statementstmt 41.9% 26 / 62 Branchbran 8.3% 2 / 24 Conditioncond 11.5% 3 / 26 MC/DCmcdc 0.0% 0 / 14 Subroutinesub 63.6% 7 / 11 Podpod n/a totaltotal 27.7% 38 / 137 CC 23 SCAR 35.7
CC
23
Cov
28%
_create_key
90.0
_extract_publickey_from_log
42.0
_start_and_check
12.0
CRAP 35.6
« Any/Backend/Net_SSH2/DPipe.pm ↑ Summary Any/Backend/Sexec_Cmd.pm »
1 package Net::SSH::Any::Test::Backend::Dropbear_Daemon;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use Net::SSH::Any;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Net::SSH::Any::Constants qw(SSHA_BACKEND_ERROR);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶use parent 'Net::SSH::Any::Test::Backend::_Daemon';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 ▶sub _validate_backend_opts {
Subroutine _validate_backend_opts: called CC=5 SCAR=23.4
12 1 my $tssh = shift;
13  
14 1 ▶ $tssh->SUPER::_validate_backend_opts or return;
Branch: 1 branch
BranchTrueFalseTotal
$tssh->SUPER::_validate_backend_opts or return 1 0 1
15  
16 # dropbear and dbclient are resolved here so that they can be used
17 # as friends by any other commands
18 1 my $opts = $tssh->{current_opts};
19 1 ▶ $tssh->_be_find_cmd('dropbear') // return;
Condition50%1/2
$tssh->_be_find_cmd("dropbear") // (return)
l!l
01
MC/DC0%0/1
$tssh->_be_find_cmd("dropbear") // (return)
$tssh->_be_find_cmd("dropbear")
Truth table50%1/2
A
A= $tssh->_be_find_cmd("dropbear")
Aresult
11
00
20 0 ▶ $tssh->_be_find_cmd('dropbearconvert') // return;
Condition0%0/2
$tssh->_be_find_cmd("dropbearconvert") // (return)
l!l
00
MC/DC0%0/1
$tssh->_be_find_cmd("dropbearconvert") // (return)
$tssh->_be_find_cmd("dropbearconvert")
Truth table0%0/2
A
A= $tssh->_be_find_cmd("dropbearconvert")
Aresult
11
00
21 0 ▶ $tssh->_be_find_cmd('dropbearkey') // return;
Condition0%0/2
$tssh->_be_find_cmd("dropbearkey") // (return)
l!l
00
MC/DC0%0/1
$tssh->_be_find_cmd("dropbearkey") // (return)
$tssh->_be_find_cmd("dropbearkey")
Truth table0%0/2
A
A= $tssh->_be_find_cmd("dropbearkey")
Aresult
11
00
22  
23 0 1;
24 }
25  
26 1 my $key_type = 'rsa';
27  
28 0 ▶sub _extract_publickey_from_log {
Subroutine _extract_publickey_from_log: not called CC=6 SCAR=37.4
29 0 my ($tssh, $log, $pubkey_path) = @_;
30 0 ▶ if (open my($in), '<', $log) {
Branch: 1 branch
BranchTrueFalseTotal
if (open my $in, "<", $log) 0 0 0
31 0 local $_;
32 0 ▶ while (<$in>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $in)) 0 0 0
33 0 ▶ if (/^ssh-$key_type\s+/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^ssh-$key_type\s+/) 0 0 0
34 0 ▶ if (open my($out), '>', $pubkey_path) {
Branch: 1 branch
BranchTrueFalseTotal
if (open my $out, ">", $pubkey_path) 0 0 0
35 0 print $out $_;
36 0 ▶ close $out and return 1;
Branch: 1 branch
BranchTrueFalseTotal
close $out and return 1 0 0 0
37 }
38 0 last;
39 }
40 }
41 }
42 0 $tssh->_set_error(SSHA_BACKEND_ERROR, "unable to extract publickey from dropbearkey log");
43 0 return;
44 }
45  
46 0 ▶sub _create_key {
Subroutine _create_key: not called CC=9 SCAR=45.0
47 0 my ($tssh, $path) = @_;
48 0 ▶ -f "$path.dbk" and -f "$path.pub" and return 1;
Branch: 1 branch
BranchTrueFalseTotal
-f "$path.dbk" and -f "$path.pub" and return 1 0 0 0
Condition0%0/3
-f "$path.dbk" and -f "$path.pub"
!ll&&!rl&&r
000
MC/DC0%0/2
-f "$path.dbk" and -f "$path.pub"
-f "$path.dbk" -f "$path.pub"
Truth table0%0/3
A and B
A= -f "$path.dbk"B= -f "$path.pub"
ABresult
0X0
100
111
49 0 my $tmppath = join('.', $path, $$, int(rand(9999999)));
50 0 my $log_fn = $tssh->_log_fn('dropbearkey');
51 0 ▶ if ($tssh->_run_cmd({stdout_file => $log_fn}, 'dropbearkey', -t => $key_type, -s => 1024, -f => "$tmppath.dbk") and
Branch: 1 branch
BranchTrueFalseTotal
if ($tssh->_run_cmd({"stdout_file", $log_fn}, "dropbearkey", "-t", $key_type, "-s", 1024, "-f", "$tmppath.dbk") and $tssh->_run_cmd({}, "dropbearconvert", "dropbear", "openssh", "$tmppath.dbk", $tmppath) and $tssh->_extract_publickey_from_log($log_fn, "$tmppath.pub")) 0 0 0
Condition0%0/6
$tssh->_run_cmd({"stdout_file", $log_fn}, "dropbearkey", "-t", $key_type, "-s", 1024, "-f", "$tmppath.dbk") and $tssh->_run_cmd({}, "dropbearconvert", "dropbear", "openssh", "$tmppath.dbk", $tmppath) and $tssh->_extract_publickey_from_log($log_fn, "$tmppath.pub")
!ll&&!rl&&r
000
$tssh->_run_cmd({"stdout_file", $log_fn}, "dropbearkey", "-t", $key_type, "-s", 1024, "-f", "$tmppath.dbk") and $tssh->_run_cmd({}, "dropbearconvert", "dropbear", "openssh", "$tmppath.dbk", $tmppath)
!ll&&!rl&&r
000
MC/DC0%0/3
$tssh->_run_cmd({"stdout_file", $log_fn}, "dropbearkey", "-t", $key_type, "-s", 1024, "-f", "$tmppath.dbk") and $tssh->_run_cmd({}, "dropbearconvert", "dropbear", "openssh", "$tmppath.dbk", $tmppath) and $tssh->_extract_publickey_from_log($log_fn, "$tmppath.pub")
$tssh->_run_cmd({"stdout_file", $log_fn}, "dropbearkey", "-t", $key_type, "-s", 1024, "-f", "$tmppath.dbk") $tssh->_run_cmd({}, "dropbearconvert", "dropbear", "openssh", "$tmppath.dbk", $tmppath) $tssh->_extract_publickey_from_log($log_fn, "$tmppath.pub")
Truth table0%0/4
A and B and C
A= $tssh->_run_cmd({"stdout_file", $log_fn}, "dropbearkey", "-t", $key_type, "-s", 1024, "-f", "$tmppath.dbk")B= $tssh->_run_cmd({}, "dropbearconvert", "dropbear", "openssh", "$tmppath.dbk", $tmppath)C= $tssh->_extract_publickey_from_log($log_fn, "$tmppath.pub")
ABCresult
0XX0
10X0
1100
1111
52 $tssh->_run_cmd({}, 'dropbearconvert', 'dropbear', 'openssh', "$tmppath.dbk", $tmppath) and
53 $tssh->_extract_publickey_from_log($log_fn, "$tmppath.pub")) {
54 0 unlink $path;
55 0 unlink "$path.pub";
56 0 unlink "$path.dbk";
57 0 chmod 0644, "$tmppath.pub";
58 0 ▶ if (rename $tmppath, $path and
Branch: 1 branch
BranchTrueFalseTotal
if (rename $tmppath, $path and rename "$tmppath.pub", "$path.pub" and rename "$tmppath.dbk", "$path.dbk") 0 0 0
Condition0%0/6
rename $tmppath, $path and rename "$tmppath.pub", "$path.pub" and rename "$tmppath.dbk", "$path.dbk"
!ll&&!rl&&r
000
rename $tmppath, $path and rename "$tmppath.pub", "$path.pub"
!ll&&!rl&&r
000
MC/DC0%0/3
rename $tmppath, $path and rename "$tmppath.pub", "$path.pub" and rename "$tmppath.dbk", "$path.dbk"
rename $tmppath, $path rename "$tmppath.pub", "$path.pub" rename "$tmppath.dbk", "$path.dbk"
Truth table0%0/4
A and B and C
A= rename $tmppath, $pathB= rename "$tmppath.pub", "$path.pub"C= rename "$tmppath.dbk", "$path.dbk"
ABCresult
0XX0
10X0
1100
1111
59 rename "$tmppath.pub", "$path.pub" and
60 rename "$tmppath.dbk", "$path.dbk") {
61 0 $tssh->_log("key generated $path");
62 0 return 1;
63 }
64 }
65 0 $tssh->_or_set_error(SSHA_BACKEND_ERROR, "key generation failed");
66 0 return;
67 }
68  
69 1 ▶sub _be_find_cmd {
Subroutine _be_find_cmd: called CC=4 SCAR=15.2
70 1 my $tssh = shift;
71 1 ▶ my $find_opts = (ref($_[0]) ? shift : {});
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 1 1
72 1 my ($name, $friend, $app, $default) = @_;
73 1 my $opts = $tssh->{current_opts};
74 $tssh->SUPER::_be_find_cmd($find_opts,
75 $name,
76 $friend // $opts->{local_dropbear_cmd},
77 1 ▶ $app // { POSIX => 'Dropbear', MSWin => 'Cygwin' },
Condition40%2/5
$friend // $opts->{"local_dropbear_cmd"}
l!l&&r!l&&!r
001
$app // {"POSIX", "Dropbear", "MSWin", "Cygwin"}
l!l
01
MC/DC0%0/2
$friend // $opts->{"local_dropbear_cmd"}
$friend $opts->{"local_dropbear_cmd"}
MC/DC0%0/1
$app // {"POSIX", "Dropbear", "MSWin", "Cygwin"}
$app
Truth table33%1/3
A // B
A= $friendB= $opts->{"local_dropbear_cmd"}
ABresult
1X1
011
000
Truth table50%1/2
A
A= $app
Aresult
11
00
78 $default);
79 }
80  
81 0 ▶sub _start_and_check {
Subroutine _start_and_check: not called CC=3 SCAR=24.8
82 0 my $tssh = shift;
83  
84 0 ▶ $tssh->_create_all_keys or return;
Branch: 1 branch
BranchTrueFalseTotal
$tssh->_create_all_keys or return 0 0 0
85  
86 0 my $opts = $tssh->{current_opts};
87 0 $tssh->{daemon_proc} = $tssh->_run_cmd({async => 1},
88 'dropbear', '-E', '-s',
89 -r => "$opts->{host_key_path}.dbk",
90 -U => "$opts->{user_key_path}.pub",
91 -p => "localhost:$opts->{port}",
92 -P => $tssh->_backend_wfile('dropbear.pid'));
93  
94 0 ▶ $tssh->_check_daemon_and_set_uri and return 1;
Branch: 1 branch
BranchTrueFalseTotal
$tssh->_check_daemon_and_set_uri and return 1 0 0 0
95 0 $tssh->_stop;
96 ()
97 0 }
98  
99 0 ▶sub _daemon_name { 'dropbear' }
Subroutine _daemon_name: not called CC=1 SCAR=6.9
100  
101 1 1;
« Any/Backend/Net_SSH2/DPipe.pm ↑ Summary Any/Backend/Sexec_Cmd.pm »