lib/Mogura/Server/API.pm

filter: Statementstmt 89.2% 150 / 168 Branchbran 56.8% 50 / 88 Conditioncond 44.6% 42 / 94 MC/DCmcdc 11.9% 5 / 42 Subroutinesub 86.2% 25 / 29 Podpod 0.0% 0 / 1 totaltotal 64.4% 272 / 422 CC 86 SCAR 31.3
CC
86
Cov
69%
_valid_inventory
67.2
__ANON__
26.1
__ANON__
15.1
CRAP 22.9
« lib/Mogura/ResultStream.pm ↑ Summary blib/lib/Mogura/Scanner/Config.pm »
1 package Mogura::Server::API;
2 4 ▶use Mojo::Base -strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 4 ▶use Mojo::File qw(path);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use Mojo::Asset::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use Mojo::JSON qw(to_json);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use Mojo::IOLoop::Subprocess;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use Fcntl qw(:flock);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use Scalar::Util qw(weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use Mogura::Protocol qw(valid_id artifact_name);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use Mogura::Server::Results;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 4 ▶use constant ARTIFACT_LIMIT => 4 * 1024**3;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 6 ▶sub register {
Subroutine register: called CC=9 SCAR=24.4
Pod undocumented
15 6 my ($class, $app) = @_;
16 6 my $store = $app->store;
17 6 my $receiving = 0;
18 6 my $validating = 0;
19 6 my $incoming = path($store->state, 'incoming')->make_path({mode => 0700});
20  
21 # Serialize allocation and startup sweeping across servers using this state.
22 # A validation subprocess inherits the asset lock until it finishes.
23 6 ▶ open my $directory_lock, '<', $incoming or die "Open incoming directory: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $directory_lock, "<", $incoming or die "Open incoming directory: $!" 6 0 6
24 6 ▶ flock($directory_lock, LOCK_EX) or die "Lock incoming directory: $!";
Branch: 1 branch
BranchTrueFalseTotal
flock $directory_lock, 2 or die "Lock incoming directory: $!" 6 0 6
25 6 for my $file ($incoming->list->each) {
26 1 ▶ next unless $file->basename =~ /\Amojo\.tmp\.[A-Za-z0-9_]+\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $file->basename =~ /\Amojo\.tmp\.[A-Za-z0-9_]+\z/u 0 1 1
27 1 ▶ open my $fh, '<', $file or next;
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $file or next 1 0 1
28 1 ▶ unlink $file if flock($fh, LOCK_EX | LOCK_NB);
Branch: 1 branch
BranchTrueFalseTotal
if flock $fh, 6 1 0 1
29 }
30 6 ▶ flock($directory_lock, LOCK_UN) or die "Unlock incoming directory: $!";
Branch: 1 branch
BranchTrueFalseTotal
flock $directory_lock, 8 or die "Unlock incoming directory: $!" 6 0 6
31 $app->hook(
32 136 ▶ after_build_tx => sub {
Subroutine __ANON__: called CC=1 SCAR=0.2
33 136 my ($tx) = @_;
34 136 weaken($tx);
35 $tx->req->content->once(
36 136 ▶ body => sub {
Subroutine __ANON__: called CC=18 SCAR=32.6
37 136 my ($content) = @_;
38 136 my $req = $tx->req;
39 return
40 136 ▶ unless $req->method eq 'PUT'
Branch: 1 branch
BranchTrueFalseTotal
unless $req->method eq "PUT" and $req->url->path->to_string =~ m[\A/api/jobs/([a-f0-9]{32})/([a-f0-9]{32})/files/(syft|cdx|grype|log)\z]u 125 11 136
Condition66%2/3
$req->method eq "PUT" and $req->url->path->to_string =~ m[\A/api/jobs/([a-f0-9]{32})/([a-f0-9]{32})/files/(syft|cdx|grype|log)\z]u
!ll&&!rl&&r
125011
MC/DC50%1/2
$req->method eq "PUT" and $req->url->path->to_string =~ m[\A/api/jobs/([a-f0-9]{32})/([a-f0-9]{32})/files/(syft|cdx|grype|log)\z]u
$req->method eq "PUT" $req->url->path->to_string =~ m[\A/api/jobs/([a-f0-9]{32})/([a-f0-9]{32})/files/(syft|cdx|grype|log)\z]u
Truth table66%2/3
A and B
A= $req->method eq "PUT"B= $req->url->path->to_string =~ m[\A/api/jobs/([a-f0-9]{32})/([a-f0-9]{32})/files/(syft|cdx|grype|log)\z]u
ABresult
0X0
100
111
41 && $req->url->path->to_string =~
42 m{\A/api/jobs/([a-f0-9]{32})/([a-f0-9]{32})/files/(syft|cdx|grype|log)\z};
43 11 my ($id, $run) = ($1, $2);
44 11 my $headers = $req->headers;
45 11 ▶ my $size = $headers->content_length // '';
Condition50%1/2
$headers->content_length // ""
l!l
110
MC/DC0%0/1
$headers->content_length // ""
$headers->content_length
Truth table50%1/2
A
A= $headers->content_length
Aresult
11
00
46 11 my $scanner = $store->authenticate($headers->authorization);
47 return
48 11 ▶ unless _secure_connection($tx)
Branch: 1 branch
BranchTrueFalseTotal
unless _secure_connection($tx) and defined $scanner and $store->owns($scanner, $id, $run) 1 10 11
Condition50%3/6
_secure_connection($tx) and defined $scanner and $store->owns($scanner, $id, $run)
!ll&&!rl&&r
0110
_secure_connection($tx) and defined $scanner
!ll&&!rl&&r
0011
MC/DC33%1/3
_secure_connection($tx) and defined $scanner and $store->owns($scanner, $id, $run)
_secure_connection($tx) defined $scanner $store->owns($scanner, $id, $run)
Truth table50%2/4
A and B and C
A= _secure_connection($tx)B= defined $scannerC= $store->owns($scanner, $id, $run)
ABCresult
0XX0
10X0
1100
1111
49 && defined($scanner)
50 && $store->owns($scanner, $id, $run);
51 10 ▶ return unless $size =~ /\A[0-9]{1,10}\z/ && $size <= ARTIFACT_LIMIT;
Branch: 1 branch
BranchTrueFalseTotal
unless $size =~ /\A[0-9]{1,10}\z/u and $size <= 4294967296 0 10 10
Condition33%1/3
$size =~ /\A[0-9]{1,10}\z/u and $size <= 4294967296
!ll&&!rl&&r
0010
MC/DC0%0/2
$size =~ /\A[0-9]{1,10}\z/u and $size <= 4294967296
$size =~ /\A[0-9]{1,10}\z/u $size <= 4294967296
Truth table33%1/3
A and B
A= $size =~ /\A[0-9]{1,10}\z/uB= $size <= 4294967296
ABresult
0X0
100
111
52 return
53 10 ▶ if $headers->transfer_encoding
Branch: 1 branch
BranchTrueFalseTotal
if $headers->transfer_encoding or $headers->content_encoding or ($headers->content_type // "") ne "application/octet-stream" 0 10 10
Condition37%3/8
$headers->transfer_encoding or $headers->content_encoding or ($headers->content_type // "") ne "application/octet-stream"
l!l&&r!l&&!r
0010
$headers->transfer_encoding or $headers->content_encoding
l!l&&r!l&&!r
0010
$headers->content_type // ""
l!l
100
MC/DC0%0/3
$headers->transfer_encoding or $headers->content_encoding or ($headers->content_type // "") ne "application/octet-stream"
$headers->transfer_encoding $headers->content_encoding $headers->content_type
Truth table25%1/4
A or B or C
A= $headers->transfer_encodingB= $headers->content_encodingC= $headers->content_type
ABCresult
1XX1
01X1
0011
0000
54 || $headers->content_encoding
55 || ($headers->content_type // '') ne 'application/octet-stream';
56 10 ▶ return if $receiving >= 2;
Branch: 1 branch
BranchTrueFalseTotal
if $receiving >= 2 0 10 10
57 10 ++$receiving;
58 10 ▶ $tx->once(finish => sub { --$receiving });
Subroutine __ANON__: called CC=1 SCAR=0.0
59 10 $tx->{mogura_upload} = 1;
60 10 my $asset = Mojo::Asset::File->new(tmpdir => "$incoming");
61 10 ▶ flock($directory_lock, LOCK_EX) or die "Lock incoming directory: $!";
Branch: 1 branch
BranchTrueFalseTotal
flock $directory_lock, 2 or die "Lock incoming directory: $!" 10 0 10
62 my $locked =
63 10 ▶ eval { flock($asset->handle, LOCK_EX) or die "Lock upload: $!"; 1 };
Branch: 1 branch
BranchTrueFalseTotal
flock $asset->handle, 2 or die "Lock upload: $!" 10 0 10
64 10 my $error = $@;
65 10 ▶ flock($directory_lock, LOCK_UN) or die "Unlock incoming directory: $!";
Branch: 1 branch
BranchTrueFalseTotal
flock $directory_lock, 8 or die "Unlock incoming directory: $!" 10 0 10
66 10 ▶ die $error unless $locked;
Branch: 1 branch
BranchTrueFalseTotal
unless $locked 0 10 10
67 10 $content->auto_upgrade(0)->asset($asset);
68 10 $req->max_message_size($size + 16384);
69 }
70 136 );
71 }
72 6 );
73  
74 my $api = $app->routes->under('/api')->to(
75 27 ▶ cb => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
76 27 my ($c) = @_;
77 27 my $id = $store->authenticate($c->req->headers->authorization);
78 27 ▶ unless (defined $id && _secure_connection($c->tx)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $id and _secure_connection($c->tx)) 2 25 27
Condition66%2/3
defined $id and _secure_connection($c->tx)
!ll&&!rl&&r
2025
MC/DC50%1/2
defined $id and _secure_connection($c->tx)
defined $id _secure_connection($c->tx)
Truth table66%2/3
A and B
A= defined $idB= _secure_connection($c->tx)
ABresult
0X0
100
111
79 2 $c->render(status => 401, json => {});
80 2 return undef;
81 }
82 25 $c->stash(scanner => $id);
83 25 return 1;
84 }
85 6 );
86 $api->get('/identity')->to(
87 0 ▶ cb => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
88 0 my ($c) = @_;
89 0 $c->render(
90 json => {
91 scanner => $c->stash('scanner'),
92 server =>
93 scalar $store->db->selectrow_array(
94 "SELECT value FROM settings WHERE name='id'")
95 }
96 );
97 }
98 6 );
99 $api->post('/inventory')->to(
100 2 ▶ cb => sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
101 2 my ($c) = @_;
102 2 my $inv = $c->req->json;
103 2 ▶ return $c->render(status => 400, json => {}) unless _valid_inventory($inv);
Branch: 1 branch
BranchTrueFalseTotal
unless _valid_inventory($inv) 0 2 2
104 2 $store->db->do('UPDATE scanners SET seen=?,inventory=? WHERE id=?',
105 undef, time, to_json($inv), $c->stash('scanner'));
106 2 return $c->render(
107 json => {cancel => $store->pending_cancellations($c->stash('scanner'))});
108 }
109 6 );
110 $api->get('/jobs')->to(
111 1 ▶ cb => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
112 1 my ($c) = @_;
113 1 $c->render(json => {job => scalar $store->offer($c->stash('scanner'))});
114 }
115 6 );
116 my $job = $api->under('/jobs/:id/:run')->to(
117 22 ▶ cb => sub {
Subroutine __ANON__: called CC=3 SCAR=15.1
118 22 my ($c) = @_;
119 22 ▶ return 1 if valid_id($c->stash('id')) && valid_id($c->stash('run'));
Branch: 1 branch
BranchTrueFalseTotal
if valid_id($c->stash("id")) and valid_id($c->stash("run")) 22 0 22
Condition33%1/3
valid_id($c->stash("id")) and valid_id($c->stash("run"))
!ll&&!rl&&r
0022
MC/DC0%0/2
valid_id($c->stash("id")) and valid_id($c->stash("run"))
valid_id($c->stash("id")) valid_id($c->stash("run"))
Truth table33%1/3
A and B
A= valid_id($c->stash("id"))B= valid_id($c->stash("run"))
ABresult
0X0
100
111
120 0 $c->render(status => 400, json => {});
121 0 return undef;
122 }
123 6 );
124 $job->post('/claim')->to(
125 4 ▶ cb => sub {
Subroutine __ANON__: called CC=6 SCAR=18.1
126 4 my ($c) = @_;
127 4 my $ok = $store->claim(map { $c->stash($_) } qw(scanner id run));
128 4 ▶ $c->render(
Branch: 3 branches
BranchTrueFalseTotal
($ok // '') eq 'expired' ? : 0 4 4
$ok ? : 2 2 4
($ok // '') eq 'cancel' ? : 0 4 4
Condition100%4/4
$ok // ""
l!l
22
$ok // ""
l!l
22
MC/DC100%1/1
$ok // ""
$ok
MC/DC100%1/1
$ok // ""
$ok
Truth table100%2/2
A
A= $ok
Aresult
11
00
Truth table100%2/2
A
A= $ok
Aresult
11
00
129 status => ($ok // '') eq 'expired' ? 410 : $ok ? 200 : 409,
130 json => {
131 id => $c->stash('id'),
132 run => $c->stash('run'),
133 cancel => ($ok // '') eq 'cancel' ? 1 : 0
134 }
135 );
136 }
137 6 );
138 6 for my $action (qw(progress complete)) {
139 $job->post("/$action")->to(
140 7 ▶ cb => sub {
Subroutine __ANON__: called CC=9 SCAR=27.2
141 7 my ($c) = @_;
142 7 my $record = $c->req->json;
143 return $c->render(status => 400, json => {})
144 unless ref $record eq 'HASH'
145 && ($record->{sequence} // '') =~ /\A[1-9][0-9]{0,9}\z/
146 && ref($record->{warnings} // []) eq 'ARRAY'
147 7 ▶ && (!defined $record->{grype_db} || ref($record->{grype_db}) eq 'HASH');
Branch: 1 branch
BranchTrueFalseTotal
unless ref $record eq "HASH" and ($record->{"sequence"} // "") =~ /\A[1-9][0-9]{0,9}\z/u and ref($record->{"warnings"} // []) eq "ARRAY" and !defined($record->{"grype_db"}) || ref $record->{"grype_db"} eq "HASH" 0 7 7
Condition37%6/16
ref $record eq "HASH" and ($record->{"sequence"} // "") =~ /\A[1-9][0-9]{0,9}\z/u and ref($record->{"warnings"} // []) eq "ARRAY" and !defined($record->{"grype_db"}) || ref $record->{"grype_db"} eq "HASH"
!ll&&!rl&&r
007
ref $record eq "HASH" and ($record->{"sequence"} // "") =~ /\A[1-9][0-9]{0,9}\z/u and ref($record->{"warnings"} // []) eq "ARRAY"
!ll&&!rl&&r
007
ref $record eq "HASH" and ($record->{"sequence"} // "") =~ /\A[1-9][0-9]{0,9}\z/u
!ll&&!rl&&r
007
$record->{"sequence"} // ""
l!l
70
$record->{"warnings"} // []
l!l
07
not defined $record->{"grype_db"} or ref $record->{"grype_db"} eq "HASH"
l!l&&r!l&&!r
700
MC/DC0%0/5
ref $record eq "HASH" and ($record->{"sequence"} // "") =~ /\A[1-9][0-9]{0,9}\z/u and ref($record->{"warnings"} // []) eq "ARRAY" and !defined($record->{"grype_db"}) || ref $record->{"grype_db"} eq "HASH"
ref $record eq "HASH" $record->{"sequence"} $record->{"warnings"} not defined $record->{"grype_db"} ref $record->{"grype_db"} eq "HASH"
Truth table0%0/6
A and B and C and not(D) or E
A= ref $record eq "HASH"B= $record->{"sequence"}C= $record->{"warnings"}D= not defined $record->{"grype_db"}E= ref $record->{"grype_db"} eq "HASH"
ABCDEresult
0XXXX0
10XXX0
110XX0
111000
1111X1
111011
148 7 my $ok = $store->update_run((map { $c->stash($_) } qw(scanner id run)),
149 $record, $action eq 'complete');
150 7 ▶ $c->render(
Branch: 1 branch
BranchTrueFalseTotal
$ok ? : 4 3 7
151 status => $ok ? 200 : 409,
152 json => {id => $c->stash('id'), run => $c->stash('run'), action => $action}
153 );
154 }
155 12 );
156 }
157 $job->put('/files/:kind')->to(
158 11 ▶ cb => sub {
Subroutine __ANON__: called CC=8 SCAR=21.6
159 11 my ($c) = @_;
160 11 my ($scanner, $id, $run, $kind) = map { $c->stash($_) } qw(scanner id run kind);
161 11 ▶ return $c->render(status => 403, json => {}) unless $store->owns($scanner, $id, $run);
Branch: 1 branch
BranchTrueFalseTotal
unless $store->owns($scanner, $id, $run) 1 10 11
162 10 ▶ return $c->render(status => 400, json => {}) unless artifact_name($kind);
Branch: 1 branch
BranchTrueFalseTotal
unless artifact_name($kind) 0 10 10
163 10 ▶ return $c->render(status => 429, json => {}) unless $c->tx->{mogura_upload};
Branch: 1 branch
BranchTrueFalseTotal
unless $c->tx->{"mogura_upload"} 0 10 10
164 10 my $asset = $c->req->content->asset;
165 10 my $size = $c->req->headers->content_length;
166 10 ▶ my $hash = $c->req->headers->header('X-Content-SHA256') // '';
Condition50%1/2
$c->req->headers->header("X-Content-SHA256") // ""
l!l
100
MC/DC0%0/1
$c->req->headers->header("X-Content-SHA256") // ""
$c->req->headers->header("X-Content-SHA256")
Truth table50%1/2
A
A= $c->req->headers->header("X-Content-SHA256")
Aresult
11
00
167 10 ▶ return $c->render(status => 400, json => {})
Branch: 1 branch
BranchTrueFalseTotal
unless $hash =~ /\A[a-f0-9]{64}\z/u and $asset->size == $size 0 10 10
Condition33%1/3
$hash =~ /\A[a-f0-9]{64}\z/u and $asset->size == $size
!ll&&!rl&&r
0010
MC/DC0%0/2
$hash =~ /\A[a-f0-9]{64}\z/u and $asset->size == $size
$hash =~ /\A[a-f0-9]{64}\z/u $asset->size == $size
Truth table33%1/3
A and B
A= $hash =~ /\A[a-f0-9]{64}\z/uB= $asset->size == $size
ABresult
0X0
100
111
168 unless $hash =~ /\A[a-f0-9]{64}\z/ && $asset->size == $size;
169 10 ▶ return $c->render(status => 429, json => {}) if $validating >= 2;
Branch: 1 branch
BranchTrueFalseTotal
if $validating >= 2 0 10 10
170 10 ++$validating;
171 10 $c->render_later;
172 Mojo::IOLoop::Subprocess->new->run(
173 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
174 0 $store->receive($scanner, $id, $run, $kind, $asset->path, $size, $hash);
175 0 return 1;
176 },
177 10 ▶ sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
178 10 my (undef, $error) = @_;
179 10 --$validating;
180 10 ▶ if ($error) { $app->log->error("Upload $id/$kind: $error"); }
Branch: 1 branch
BranchTrueFalseTotal
if ($error) 4 6 10
181 $c->render(
182 10 ▶ status => $error ? 409 : 200,
Branch: 2 branches
BranchTrueFalseTotal
$error ? : 4 6 10
$error ? : 4 6 10
183 json => $error
184 ? {}
185 : {id => $id, run => $run, kind => $kind, sha256 => $hash}
186 );
187 }
188 10 );
189 }
190 6 );
191  
192 # A single background builder resumes pending receipts after server restart.
193 6 my $building;
194 Mojo::IOLoop->recurring(
195 1 ▶ 1 => sub {
Subroutine __ANON__: called CC=4 SCAR=25.8
196 1 ▶ return if $building;
Branch: 1 branch
BranchTrueFalseTotal
if $building 0 1 1
197 1 ▶ my $item = $store->db->selectrow_hashref(
Branch: 1 branch
BranchTrueFalseTotal
my $item = $store->db->selectrow_hashref("SELECT job,kind FROM receipts WHERE indexed=0 AND kind IN ('syft','grype') LIMIT 1") or return 0 1 1
198 q{SELECT job,kind FROM receipts WHERE indexed=0 AND kind IN ('syft','grype') LIMIT 1}
199 ) or return;
200 0 my ($id, $kind) = @$item{qw(job kind)};
201 0 my $results = Mogura::Server::Results->new(state => $store->state);
202 0 my $file = $results->location($id, $kind);
203 0 ▶ my $lock = $results->build_lock($file) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $lock = $results->build_lock($file) or return 0 0 0
204 0 $building = 1;
205 Mojo::IOLoop::Subprocess->new->run(
206 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
207 0 my $source = $store->artifact($id, $kind);
208 0 $results->build(
209 $source, $file, $kind,
210 $results->revision($source),
211 lock => $lock
212 );
213 },
214 0 ▶ sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
215 0 my (undef, $error) = @_;
216 0 ▶ $app->log->error("Index $id/$kind: $error") if $error;
Branch: 1 branch
BranchTrueFalseTotal
if $error 0 0 0
217 0 ▶ $store->db->do(
Branch: 1 branch
BranchTrueFalseTotal
$error ? : 0 0 0
218 'UPDATE receipts SET indexed=? WHERE job=? AND kind=?',
219 undef, $error ? -1 : 1,
220 $id, $kind
221 );
222 0 $building = 0;
223 }
224 0 );
225 }
226 6 );
227 }
228  
229 36 ▶sub _secure_connection {
Subroutine _secure_connection: called CC=5 SCAR=18.6
230 36 my ($tx) = @_;
231 36 ▶ my $peer = $tx->original_remote_address // '';
Condition50%1/2
$tx->original_remote_address // ""
l!l
360
MC/DC0%0/1
$tx->original_remote_address // ""
$tx->original_remote_address
Truth table50%1/2
A
A= $tx->original_remote_address
Aresult
11
00
232 36 ▶ return ($tx->req->url->base->scheme // '') eq 'https' || $peer eq '127.0.0.1' || $peer eq '::1';
Condition50%4/8
($tx->req->url->base->scheme // '') eq 'https' || $peer eq '127.0.0.1' || $peer eq '::1'
l!l&&r!l&&!r
3600
($tx->req->url->base->scheme // "") eq "https" or $peer eq "127.0.0.1"
l!l&&r!l&&!r
0360
$tx->req->url->base->scheme // ""
l!l
2511
MC/DC0%0/3
($tx->req->url->base->scheme // '') eq 'https' || $peer eq '127.0.0.1' || $peer eq '::1'
$tx->req->url->base->scheme $peer eq "127.0.0.1" $peer eq '::1'
Truth table25%1/4
A or B || C
A= $tx->req->url->base->schemeB= $peer eq "127.0.0.1"C= $peer eq '::1'
ABCresult
1XX1
01X1
0011
0000
233 }
234  
235 2 ▶sub _valid_inventory {
Subroutine _valid_inventory: called CC=24 SCAR=42.1
236 2 my ($inv) = @_;
237 2 ▶ return unless ref $inv eq 'HASH' && ref $inv->{disks} eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $inv eq "HASH" and ref $inv->{"disks"} eq "ARRAY" 0 2 2
Condition33%1/3
ref $inv eq "HASH" and ref $inv->{"disks"} eq "ARRAY"
!ll&&!rl&&r
002
MC/DC0%0/2
ref $inv eq "HASH" and ref $inv->{"disks"} eq "ARRAY"
ref $inv eq "HASH" ref $inv->{"disks"} eq "ARRAY"
Truth table33%1/3
A and B
A= ref $inv eq "HASH"B= ref $inv->{"disks"} eq "ARRAY"
ABresult
0X0
100
111
238 2 ▶ for my $key (qw(blocked errors)) { return unless ref($inv->{$key} // []) eq 'ARRAY' }
Branch: 1 branch
BranchTrueFalseTotal
unless ref($inv->{$key} // []) eq "ARRAY" 0 4 4
Condition50%1/2
$inv->{$key} // []
l!l
04
MC/DC0%0/1
$inv->{$key} // []
$inv->{$key}
Truth table50%1/2
A
A= $inv->{$key}
Aresult
11
00
239 2 my @targets;
240 2 for my $disk (@{$inv->{disks}}) {
241 return
242 unless ref $disk eq 'HASH'
243 && ref $disk->{targets} eq 'ARRAY'
244 2 ▶ && ref($disk->{reasons} // []) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $disk eq "HASH" and ref $disk->{"targets"} eq "ARRAY" and ref($disk->{"reasons"} // []) eq "ARRAY" 0 2 2
Condition37%3/8
ref $disk eq "HASH" and ref $disk->{"targets"} eq "ARRAY" and ref($disk->{"reasons"} // []) eq "ARRAY"
!ll&&!rl&&r
002
ref $disk eq "HASH" and ref $disk->{"targets"} eq "ARRAY"
!ll&&!rl&&r
002
$disk->{"reasons"} // []
l!l
02
MC/DC0%0/3
ref $disk eq "HASH" and ref $disk->{"targets"} eq "ARRAY" and ref($disk->{"reasons"} // []) eq "ARRAY"
ref $disk eq "HASH" ref $disk->{"targets"} eq "ARRAY" $disk->{"reasons"}
Truth table25%1/4
A and B and C
A= ref $disk eq "HASH"B= ref $disk->{"targets"} eq "ARRAY"C= $disk->{"reasons"}
ABCresult
0XX0
10X0
1100
1111
245 2 push @targets, @{$disk->{targets}};
246 }
247 2 ▶ push @targets, $inv->{host} if defined $inv->{host};
Branch: 1 branch
BranchTrueFalseTotal
if defined $inv->{"host"} 0 2 2
248 2 for my $target (@targets) {
249 return
250 unless ref $target eq 'HASH'
251 && ref($target->{reasons} // []) eq 'ARRAY'
252 2 ▶ && ref($target->{mountpoints} // []) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $target eq "HASH" and ref($target->{"reasons"} // []) eq "ARRAY" and ref($target->{"mountpoints"} // []) eq "ARRAY" 0 2 2
Condition40%4/10
ref $target eq "HASH" and ref($target->{"reasons"} // []) eq "ARRAY" and ref($target->{"mountpoints"} // []) eq "ARRAY"
!ll&&!rl&&r
002
ref $target eq "HASH" and ref($target->{"reasons"} // []) eq "ARRAY"
!ll&&!rl&&r
002
$target->{"reasons"} // []
l!l
02
$target->{"mountpoints"} // []
l!l
02
MC/DC0%0/3
ref $target eq "HASH" and ref($target->{"reasons"} // []) eq "ARRAY" and ref($target->{"mountpoints"} // []) eq "ARRAY"
ref $target eq "HASH" $target->{"reasons"} $target->{"mountpoints"}
Truth table0%0/4
A and B and C
A= ref $target eq "HASH"B= $target->{"reasons"}C= $target->{"mountpoints"}
ABCresult
0XX0
10X0
1100
1111
253 2 ▶ next unless $target->{selectable};
Branch: 1 branch
BranchTrueFalseTotal
unless $target->{"selectable"} 0 2 2
254 return
255 unless ($target->{token} // '') =~ /\A[a-f0-9]{64}\z/
256 2 ▶ && ref $target->{identity} eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ($target->{"token"} // "") =~ /\A[a-f0-9]{64}\z/u and ref $target->{"identity"} eq "HASH" 0 2 2
Condition40%2/5
($target->{"token"} // "") =~ /\A[a-f0-9]{64}\z/u and ref $target->{"identity"} eq "HASH"
!ll&&!rl&&r
002
$target->{"token"} // ""
l!l
20
MC/DC0%0/2
($target->{"token"} // "") =~ /\A[a-f0-9]{64}\z/u and ref $target->{"identity"} eq "HASH"
$target->{"token"} ref $target->{"identity"} eq "HASH"
Truth table33%1/3
A and B
A= $target->{"token"}B= ref $target->{"identity"} eq "HASH"
ABresult
0X0
100
111
257 return
258 unless ref $target->{identity}{disk} eq 'HASH'
259 2 ▶ && ref $target->{identity}{partition} eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $target->{"identity"}{"disk"} eq "HASH" and ref $target->{"identity"}{"partition"} eq "HASH" 0 2 2
Condition33%1/3
ref $target->{"identity"}{"disk"} eq "HASH" and ref $target->{"identity"}{"partition"} eq "HASH"
!ll&&!rl&&r
002
MC/DC0%0/2
ref $target->{"identity"}{"disk"} eq "HASH" and ref $target->{"identity"}{"partition"} eq "HASH"
ref $target->{"identity"}{"disk"} eq "HASH" ref $target->{"identity"}{"partition"} eq "HASH"
Truth table33%1/3
A and B
A= ref $target->{"identity"}{"disk"} eq "HASH"B= ref $target->{"identity"}{"partition"} eq "HASH"
ABresult
0X0
100
111
260 }
261 2 return 1;
262 }
263 4 1;
« lib/Mogura/ResultStream.pm ↑ Summary blib/lib/Mogura/Scanner/Config.pm »