| 1 | package Mogura::Server; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 4 | ▶ | use Mojo::Base 'Mojolicious'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use Mojo::File qw(path); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use Mojo::IOLoop::Subprocess; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 4 | ▶ | use Cwd qw(abs_path); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 4 | ▶ | use Mogura::Protocol qw(random_id valid_id); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 4 | ▶ | use Mogura::Server::API; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 4 | ▶ | use Mogura::Server::I18N; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 4 | ▶ | use Mogura::Server::Store; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 4 | ▶ | use Mogura::Server::Results; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 0 | ▶ | has store => sub { Mogura::Server::Store->new }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 4 | my $assets = path(abs_path(__FILE__))->sibling('Server'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 16 | ▶ | sub assets { $assets } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
assets: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 6 | ▶ | sub startup { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
startup: called CC=1 SCAR=0.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 6 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 6 | $self->renderer->paths([Mogura::Server::assets()->child('templates')->to_string]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 6 | $self->static->paths([Mogura::Server::assets()->child('public')->to_string]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 6 | $self->store->initialize; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 6 | $self->mode('production'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 6 | $self->secrets( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | scalar $self->store->db->selectrow_array( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | "SELECT value FROM settings WHERE name='session'") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 6 | $self->sessions->cookie_name('mogura_session'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 6 | $self->sessions->samesite('Strict'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 6 | $self->max_request_size(262144); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 6 | Mogura::Server::API->register($self); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 6 | Mogura::Server::I18N->register($self); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 6 | $self->_register_display_helpers; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 6 | ▶ | $self->hook(before_dispatch => sub { $self->_protect_request(@_) }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 6 | my $routes = $self->routes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 6 | ▶ | $routes->get('/')->to(cb => sub { $self->_show_index(@_) }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | $routes->get('/inventory')->to( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 9 | ▶ | cb => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 9 | my ($controller) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 9 | $controller->res->headers->cache_control('no-store'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 9 | $self->_inventory_page($controller); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 9 | $controller->render(template => 'inventory'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 6 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 6 | ▶ | $routes->get('/history')->to(cb => sub { $self->_show_history(@_) }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 6 | ▶ | $routes->post('/scans')->to(cb => sub { $self->_start_scan(@_) }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | $routes->post('/scans/:id/cancel')->to( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | ▶ | cb => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | my ($c) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | return $c->render(status => 403, text => $c->l('invalid_csrf')) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | if $c->validation->csrf_protect->has_error('csrf_token'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | my $id = $c->stash('id'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | ▶ | return $c->reply->not_found unless $self->store->cancel($id); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | $c->res->code(303); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | return $c->redirect_to("/scans/$id"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 6 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 6 | ▶ | $routes->get('/scans/:id')->to(cb => sub { $self->_show_scan(@_) }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 6 | ▶ | $routes->post('/scans/:id/tags')->to(cb => sub { $self->_update_tags(@_) }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 6 | ▶ | $routes->post('/scans/:id/note')->to(cb => sub { $self->_update_note(@_) }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 6 | ▶ | $routes->get('/scans/:id/download/:kind')->to(cb => sub { $self->_download_artifact(@_) }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 6 | ▶ | $routes->get('/scans/:id/results/:kind')->to(cb => sub { $self->_result_page(@_) }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 6 | ▶ | $routes->post('/scans/:id/results/:kind/rebuild')->to(cb => sub { $self->_rebuild_result(@_) }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | $routes->get('/scans/:id/results/:kind/build') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 6 | ▶ | ->to(cb => sub { $self->_result_build_status(@_) }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 6 | ▶ | sub _register_display_helpers { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_register_display_helpers: called CC=1 SCAR=0.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 6 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | $self->helper( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 209 | ▶ | display => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=14.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 209 | my ($controller, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 209 | ▶ | return $controller->l('unknown') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
defined $value and not ref $value and length $value
defined $value and not ref $value
MC/DC33%1/3
defined $value and not ref $value and length $value
defined $value
not ref $value
length $value
Truth table50%2/4
A and not(B) and C
A= defined $valueB= not ref $valueC= length $value
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | unless defined $value && !ref($value) && length($value); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 54 | return $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 6 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | $self->helper( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 77 | ▶ | label => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=12.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 77 | my ($controller, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 77 | ▶ | return $controller->l('unknown') unless defined $value && length $value; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $value and length $value
MC/DC0%0/2
defined $value and length $value
defined $value
length $value
Truth table33%1/3
A and B
A= defined $valueB= length $value
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 77 | return $controller->l($value); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 6 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | $self->helper( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 42 | ▶ | exclusion_reasons => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 42 | my ($controller, $reasons) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 42 | return $self->_exclusion_reasons($controller, $reasons); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 6 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 42 | ▶ | sub _exclusion_reasons { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_exclusion_reasons: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 42 | my ($self, $controller, $reasons) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | # Several partitions can report the same disk-wide exclusion. Present each | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | # reason once while preserving the original diagnostic data in inventory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 42 | my @labels = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | qr/\A(?:Mounted filesystem|Scanner storage:|Active swap|Referenced)/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | $controller->l('in_use') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | [qr/\ANo hardware serial/, $controller->l('no_identity')], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | qr/\A(?:Ambiguous filesystem|Partition table present)/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | $controller->l('ambiguous_layout') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | [qr/\AOnly ext4/, $controller->l('unsupported_filesystem')], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | [qr/\ABIOS boot partition:/, $controller->l('bios_boot')], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | [qr/\ACannot resolve scanner storage:/, $controller->l('storage_unresolved')], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 42 | my %seen; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | my @translated; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 42 | for my $reason (@$reasons) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 28 | my $label = $reason; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 28 | for my $translation (@labels) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 150 | ▶ | next unless $reason =~ $translation->[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 10 | $label = $translation->[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 10 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | # Keep the device and detected layout visible instead of collapsing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | # distinct unsupported partitions into a single generic label. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 28 | ▶ | if ($label =~ /\AUnsupported partition table/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 2 | $label =~ s/\AUnsupported partition table/$controller->l('unsupported_table')/e; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | elsif ($label =~ /\AUnsupported or unknown partition/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 16 | $label =~ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 16 | s/\AUnsupported or unknown partition/$controller->l('unsupported_partition')/e; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | $label =~ s/\AUnsupported/$controller->l('unsupported_layout')/e; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 28 | ▶ | push @translated, $label unless $seen{$label}++; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 42 | return \@translated; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 136 | ▶ | sub _protect_request { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_protect_request: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 136 | my ($self, $controller) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 136 | my $headers = $controller->res->headers; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 136 | $headers->header( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 'Content-Security-Policy' => join( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | '; ', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | "default-src 'none'", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | "style-src 'self'", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | "script-src 'self'", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | "worker-src 'self'", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | "connect-src 'self'", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | "form-action 'self'", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | "frame-ancestors 'none'", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | "base-uri 'none'", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 136 | $headers->header('X-Content-Type-Options' => 'nosniff'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 136 | $headers->header('Referrer-Policy' => 'no-referrer'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 136 | $headers->cache_control('no-store'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 17 | ▶ | sub _inventory_page { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_inventory_page: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 17 | my ($self, $controller) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 17 | my $page = $self->_page_number($controller->param('page')); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 17 | my $items = $self->store->inventories($page); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 17 | my $more = @$items > 4; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 17 | ▶ | pop @$items if $more; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 17 | $controller->stash(inventory => $items, page => $page, more => $more); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 8 | ▶ | sub _show_index { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_show_index: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 8 | my ($self, $controller) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 8 | $self->_inventory_page($controller); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 8 | $controller->stash(scan_id => random_id()); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 8 | $controller->render(template => 'index'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 5 | ▶ | sub _show_history { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_show_history: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 5 | my ($self, $controller) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 5 | ▶ | my $tag = substr($controller->param('tag') // '', 0, 120); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$controller->param("tag") // ""
MC/DC100%1/1
$controller->param("tag") // ""
$controller->param("tag")
Truth table100%2/2
A
A= $controller->param("tag")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 5 | my $page = $self->_page_number($controller->param('page')); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 5 | my $history = $self->store->history($tag, $page); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 5 | my $has_more = @$history > 50; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 5 | ▶ | pop @$history if $has_more; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 5 | $controller->stash( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | history => $history, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | tag => $tag, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | page => $page, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | more => $has_more, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 5 | $controller->render(template => 'history'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 17 | ▶ | sub _start_scan { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_start_scan: called CC=13 SCAR=27.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 17 | my ($self, $controller) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 17 | ▶ | return $controller->render(text => $controller->l('invalid_csrf'), status => 403) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | if $controller->validation->csrf_protect->has_error('csrf_token'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 10 | my @tags = @{$controller->every_param('tags')}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 10 | ▶ | my $draft_tag = $controller->param('new_tag') // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$controller->param("new_tag") // ""
MC/DC100%1/1
$controller->param("new_tag") // ""
$controller->param("new_tag")
Truth table100%2/2
A
A= $controller->param("new_tag")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 10 | ▶ | push @tags, $draft_tag if $draft_tag =~ /\S/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | my $request = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | id => $controller->param('scan_id'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 10 | ▶ | tags => eval { Mogura::Server::Tags->validate(\@tags) }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$controller->param("note") // ""
MC/DC100%1/1
$controller->param("note") // ""
$controller->param("note")
Truth table100%2/2
A
A= $controller->param("note")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | note => $controller->param('note') // '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | token => $controller->param('target'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | return $controller->render(text => $controller->l('invalid_tags'), status => 400) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 10 | ▶ | unless defined $request->{tags}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 10 | ▶ | my ($scanner, $token) = split /:/, $request->{token} // '', 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$request->{"token"} // ""
MC/DC0%0/1
$request->{"token"} // ""
$request->{"token"}
Truth table50%1/2
A
A= $request->{"token"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | return $controller->render(text => $controller->l('invalid_input'), status => 400) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | unless valid_id($request->{id}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | && ($token // '') =~ /\A[a-f0-9]{64}\z/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | && length($request->{note}) <= 2000 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 10 | ▶ | && index($request->{note}, "\0") < 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition36%4/11
valid_id($request->{"id"}) and ($token // "") =~ /\A[a-f0-9]{64}\z/u and length $request->{"note"} <= 2000 and index($request->{"note"}, "\0") == -1
valid_id($request->{"id"}) and ($token // "") =~ /\A[a-f0-9]{64}\z/u and length $request->{"note"} <= 2000
valid_id($request->{"id"}) and ($token // "") =~ /\A[a-f0-9]{64}\z/u
$token // ""
MC/DC0%0/4
valid_id($request->{"id"}) and ($token // "") =~ /\A[a-f0-9]{64}\z/u and length $request->{"note"} <= 2000 and index($request->{"note"}, "\0") == -1
valid_id($request->{"id"})
$token
length $request->{"note"} <= 2000
index($request->{"note"}, "\0") == -1
Truth table20%1/5
A and B and C and D
A= valid_id($request->{"id"})B= $tokenC= length $request->{"note"} <= 2000D= index($request->{"note"}, "\0") == -1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | my $status = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 10 | $self->store->submit($request->{id}, $scanner, $token, $request->{tags}, $request->{note}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 10 | ▶ | return $controller->render(text => $controller->l('target_unavailable'), status => 409) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | if $status == 409; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 5 | return $self->_submission_response($controller, $request->{id}, $status); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 5 | ▶ | sub _submission_response { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_submission_response: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 5 | my ($self, $controller, $id, $status) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 5 | ▶ | if (($controller->req->headers->accept // '') =~ /application\/json/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$controller->req->headers->accept // ""
MC/DC100%1/1
$controller->req->headers->accept // ""
$controller->req->headers->accept
Truth table100%2/2
A
A= $controller->req->headers->accept
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 2 | return $controller->render( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | status => $status, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | json => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | id => $id, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | url => "/scans/$id", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | next_id => random_id(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 3 | ▶ | $controller->res->code($status == 200 ? 302 : 303); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 3 | return $controller->redirect_to("/scans/$id"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 23 | ▶ | sub _show_scan { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_show_scan: called CC=11 SCAR=24.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 23 | my ($self, $controller) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 23 | my $scan = $self->store->get($controller->param('id')); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 23 | ▶ | return $controller->reply->not_found unless $scan; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | my ($seen) = $self->store->db->selectrow_array( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 'SELECT seen FROM scanners WHERE id=? AND digest IS NOT NULL', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 23 | undef, $scan->{scanner_id}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 23 | ▶ | $scan->{online} = ($seen // 0) >= time - 30; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$seen // 0
MC/DC100%1/1
$seen // 0
$seen
Truth table100%2/2
A
A= $seen
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 23 | ▶ | my $host = ($scan->{target}{kind} // '') eq 'host'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$scan->{"target"}{"kind"} // ""
MC/DC0%0/1
$scan->{"target"}{"kind"} // ""
$scan->{"target"}{"kind"}
Truth table50%1/2
A
A= $scan->{"target"}{"kind"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 23 | ▶ | $scan->{removal} = $host ? 'system_volume' : 'do_not_disconnect'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | $scan->{removal} = 'can_disconnect' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 23 | ▶ | if !$host && $scan->{online} && $self->store->can_disconnect($scan); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
not $host and $scan->{"online"} and $self->store->can_disconnect($scan)
not $host and $scan->{"online"}
MC/DC66%2/3
not $host and $scan->{"online"} and $self->store->can_disconnect($scan)
not $host
$scan->{"online"}
$self->store->can_disconnect($scan)
Truth table75%3/4
not(A) and B and C
A= not $hostB= $scan->{"online"}C= $self->store->can_disconnect($scan)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 23 | my $artifacts = $self->_artifacts($scan->{id}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 23 | my (%versions, %result_states); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 23 | my $results = Mogura::Server::Results->new(state => $self->store->state); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 23 | for my $kind (qw(syft grype)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 46 | ▶ | next unless $artifacts->{$kind}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 16 | my $revision = $results->revision($artifacts->{$kind}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 16 | my $file = $results->available($scan->{id}, $kind, $revision); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 16 | ▶ | $versions{$kind} = $results->version($file, $revision) if $file; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 16 | $result_states{$kind} = $results->build_status($results->location($scan->{id}, $kind)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | $controller->stash( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 23 | scan => $scan, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | artifacts => $artifacts, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | versions => \%versions, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | result_states => \%result_states, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 23 | $controller->render(template => 'scan'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 14 | ▶ | sub _result_page { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_result_page: called CC=17 SCAR=28.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 14 | my ($self, $controller) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 14 | ▶ | my ($id, $kind) = map { $controller->param($_) // '' } qw(id kind); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$controller->param($_) // ""
MC/DC0%0/1
$controller->param($_) // ""
$controller->param($_)
Truth table50%1/2
A
A= $controller->param($_)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 14 | ▶ | return $controller->reply->not_found unless $kind eq 'syft' || $kind eq 'grype'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$kind eq "syft" or $kind eq "grype"
MC/DC100%2/2
$kind eq "syft" or $kind eq "grype"
$kind eq "syft"
$kind eq "grype"
Truth table100%3/3
A or B
A= $kind eq "syft"B= $kind eq "grype"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 13 | my $source = $self->store->artifact($id, $kind); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 13 | ▶ | return $controller->reply->not_found unless $source; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 12 | my $results = Mogura::Server::Results->new(state => $self->store->state); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 12 | my $revision = $results->revision($source); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 12 | my $file = $results->available($id, $kind, $revision); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 12 | ▶ | return $controller->render( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | status => 409, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | json => {error => $controller->l('create_list_first')} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | ) unless $file; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 9 | my $version = $results->version($file, $revision); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 9 | ▶ | return $controller->render(status => 409, json => {error => $controller->l('results_changed')}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$controller->param("version") // ""
MC/DC0%0/1
$controller->param("version") // ""
$controller->param("version")
Truth table50%1/2
A
A= $controller->param("version")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | unless ($controller->param('version') // '') eq $version; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 7 | ▶ | my $request = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%6/6
$controller->param("query") // ""
$controller->param("start") // 0
$controller->param("descending") // ""
MC/DC100%1/1
$controller->param("query") // ""
$controller->param("query")
MC/DC100%1/1
$controller->param("start") // 0
$controller->param("start")
MC/DC100%1/1
$controller->param("descending") // ""
$controller->param("descending")
Truth table100%2/2
A
A= $controller->param("query")
Truth table100%2/2
A
A= $controller->param("start")
Truth table100%2/2
A
A= $controller->param("descending")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | version => $version, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | query => $controller->param('query') // '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | start => $controller->param('start') // '0', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | column => $controller->param('column'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | descending => ($controller->param('descending') // '') eq '1', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | return $controller->render(status => 400, json => {error => $controller->l('invalid_search')}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | if length($request->{query}) > 500 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | || $request->{start} !~ /\A[0-9]{1,9}\z/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 7 | ▶ | || (defined($request->{column}) && $request->{column} !~ /\A[0-4]\z/); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition88%8/9
length $request->{"query"} > 500 or not $request->{"start"} =~ /\A[0-9]{1,9}\z/u or defined $request->{"column"} and not $request->{"column"} =~ /\A[0-4]\z/u
length $request->{"query"} > 500 or not $request->{"start"} =~ /\A[0-9]{1,9}\z/u
defined $request->{"column"} and not $request->{"column"} =~ /\A[0-4]\z/u
MC/DC75%3/4
length $request->{"query"} > 500 or not $request->{"start"} =~ /\A[0-9]{1,9}\z/u or defined $request->{"column"} and not $request->{"column"} =~ /\A[0-4]\z/u
length $request->{"query"} > 500
not $request->{"start"} =~ /\A[0-9]{1,9}\z/u
defined $request->{"column"}
not $request->{"column"} =~ /\A[0-4]\z/u
Truth table80%4/5
A or not(B) or C and not(D)
A= length $request->{"query"} > 500B= not $request->{"start"} =~ /\A[0-9]{1,9}\z/uC= defined $request->{"column"}D= not $request->{"column"} =~ /\A[0-4]\z/u
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 5 | my $key = "$id-$kind-$revision"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | # Searches and sorting run outside the HTTP event loop, including on old | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | # scans. The browser never falls back to decoding the original artifact. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 5 | ▶ | if (($self->{result_queries} // 0) >= 2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$self->{"result_queries"} // 0
MC/DC100%1/1
$self->{"result_queries"} // 0
$self->{"result_queries"}
Truth table100%2/2
A
A= $self->{"result_queries"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | $controller->res->headers->header('Retry-After' => 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 0 | return $controller->render(status => 429, json => {pending => 1}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 5 | $self->{result_queries}++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 5 | $controller->render_later; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | Mojo::IOLoop::Subprocess->new->run( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | ▶ | sub { $results->page($file, $revision, $request) }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 5 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 5 | my ($process, $error, $page) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 5 | $self->{result_queries}--; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 5 | ▶ | if ($error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 0 | $self->log->error("Result query $key: $error"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | $controller->render( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | status => 500, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | json => {error => $controller->l('result_load_failed')} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 5 | $controller->render(json => $page); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 5 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 7 | ▶ | sub _rebuild_result { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_rebuild_result: called CC=10 SCAR=24.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 7 | my ($self, $controller) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 7 | ▶ | return $controller->render(status => 403, json => {error => $controller->l('invalid_csrf')}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | if $controller->validation->csrf_protect->has_error('csrf_token'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 6 | ▶ | my ($id, $kind) = map { $controller->param($_) // '' } qw(id kind); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$controller->param($_) // ""
MC/DC0%0/1
$controller->param($_) // ""
$controller->param($_)
Truth table50%1/2
A
A= $controller->param($_)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 6 | ▶ | return $controller->reply->not_found unless $kind eq 'syft' || $kind eq 'grype'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$kind eq "syft" or $kind eq "grype"
MC/DC0%0/2
$kind eq "syft" or $kind eq "grype"
$kind eq "syft"
$kind eq "grype"
Truth table33%1/3
A or B
A= $kind eq "syft"B= $kind eq "grype"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 6 | my $scan = $self->store->get($id); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 6 | ▶ | return $controller->reply->not_found unless $scan; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | return $controller->render(status => 409, json => {error => $controller->l('wait_scan')}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 6 | ▶ | if $scan->{status} eq 'running' || $scan->{status} eq 'queued'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$scan->{"status"} eq "running" or $scan->{"status"} eq "queued"
MC/DC50%1/2
$scan->{"status"} eq "running" or $scan->{"status"} eq "queued"
$scan->{"status"} eq "running"
$scan->{"status"} eq "queued"
Truth table66%2/3
A or B
A= $scan->{"status"} eq "running"B= $scan->{"status"} eq "queued"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 5 | my $source = $self->store->artifact($id, $kind); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 5 | ▶ | return $controller->reply->not_found unless $source; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 5 | my $results = Mogura::Server::Results->new(state => $self->store->state); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 5 | my $file = $results->location($id, $kind); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 5 | my $lock = $results->build_lock($file); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 5 | ▶ | return $controller->render(status => 409, json => {error => $controller->l('wait_build')}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | unless $lock; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 4 | my $revision = $results->revision($source); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 4 | my $status = {state => 'running', token => random_id()}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 4 | $results->save_build_status($file, $status); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 4 | my $process = Mojo::IOLoop::Subprocess->new; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 4 | my $key = "$id-$kind"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 4 | $self->{result_jobs}{$key} = $process; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | $process->run( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 0 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 0 | my $ok = eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 0 | $results->build($source, $file, $kind, $revision, force => 1, lock => $lock); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 0 | my $error = $@; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | ▶ | $results->save_build_status($file, {%$status, state => $ok ? 'ready' : 'failed'}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | return $error; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 4 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 4 | my ($process, $error, $build_error) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 4 | ▶ | if ($error || $build_error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$error or $build_error
MC/DC100%2/2
$error or $build_error
$error
$build_error
Truth table100%3/3
A or B
A= $errorB= $build_error
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 2 | ▶ | $self->log->error("Result rebuild $key: " . ($error || $build_error)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$error || $build_error
MC/DC0%0/2
$error || $build_error
$error
$build_error
Truth table66%2/3
A || B
A= $errorB= $build_error
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | # Status writes can fail for the same reason as the build | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | # (for example a full disk). Always release the build lock. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 2 | eval { $results->save_build_status($file, {%$status, state => 'failed'}); }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 2 | ▶ | $self->log->error("Result rebuild status $key: $@") if $@; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 4 | close $lock; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 4 | delete $self->{result_jobs}{$key}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 4 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 4 | return $controller->render( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | status => 202, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | json => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | status_url => "/scans/$id/results/$kind/build?token=$status->{token}", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 4 | ▶ | sub _result_build_status { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_result_build_status: called CC=10 SCAR=25.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 4 | my ($self, $controller) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 4 | ▶ | my ($id, $kind) = map { $controller->param($_) // '' } qw(id kind); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$controller->param($_) // ""
MC/DC0%0/1
$controller->param($_) // ""
$controller->param($_)
Truth table50%1/2
A
A= $controller->param($_)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 4 | ▶ | return $controller->reply->not_found unless $kind eq 'syft' || $kind eq 'grype'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$kind eq "syft" or $kind eq "grype"
MC/DC0%0/2
$kind eq "syft" or $kind eq "grype"
$kind eq "syft"
$kind eq "grype"
Truth table33%1/3
A or B
A= $kind eq "syft"B= $kind eq "grype"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 4 | ▶ | return $controller->reply->not_found unless $self->store->artifact($id, $kind); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 4 | my $results = Mogura::Server::Results->new(state => $self->store->state); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 4 | my $status = $results->build_status($results->location($id, $kind)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | return $controller->render(status => 409, json => {error => $controller->l('refresh_status')}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 4 | ▶ | unless ($controller->param('token') // '') eq ($status->{token} // ''); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%2/4
$controller->param("token") // ""
$status->{"token"} // ""
MC/DC0%0/1
$controller->param("token") // ""
$controller->param("token")
MC/DC0%0/1
$status->{"token"} // ""
$status->{"token"}
Truth table50%1/2
A
A= $controller->param("token")
Truth table50%1/2
A
A= $status->{"token"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 4 | my $response = {state => $status->{state}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 4 | ▶ | if ($status->{state} eq 'ready') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 2 | my $source = $self->store->artifact($id, $kind); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 2 | my $revision = $results->revision($source); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 2 | my $file = $results->available($id, $kind, $revision); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 2 | ▶ | if ($file) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | $response->{url} = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 2 | "/scans/$id/results/$kind?version=" . $results->version($file, $revision); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 0 | $response->{state} = 'failed'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 4 | return $controller->render(json => $response); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 23 | ▶ | sub _artifacts { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_artifacts: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 23 | my ($self, $id) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 23 | return {map { $_ => scalar($self->store->artifact($id, $_)) } qw(syft cdx grype log)}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 5 | ▶ | sub _update_tags { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_update_tags: called CC=11 SCAR=24.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 5 | my ($self, $controller) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 5 | ▶ | return $controller->render(text => $controller->l('invalid_csrf'), status => 403) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | if $controller->validation->csrf_protect->has_error('csrf_token'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 4 | my $scan = $self->store->get($controller->param('id')); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 4 | ▶ | return $controller->reply->not_found unless $scan; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 4 | ▶ | my $operation = $controller->param('operation') // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$controller->param("operation") // ""
MC/DC100%1/1
$controller->param("operation") // ""
$controller->param("operation")
Truth table100%2/2
A
A= $controller->param("operation")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 4 | ▶ | return $controller->render(text => $controller->l('invalid_tag_operation'), status => 400) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$operation eq "add" or $operation eq "remove"
MC/DC100%2/2
$operation eq "add" or $operation eq "remove"
$operation eq "add"
$operation eq "remove"
Truth table100%3/3
A or B
A= $operation eq "add"B= $operation eq "remove"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | unless $operation eq 'add' || $operation eq 'remove'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 3 | my $values = eval { Mogura::Server::Tags->validate([$controller->param('tag')]); }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 3 | ▶ | return $controller->render(text => $controller->l('tag_limit'), status => 400) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | unless defined $values; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 2 | my $tags = eval { $self->store->change_tags($scan->{id}, $operation, $values); }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 2 | ▶ | unless (defined $tags) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | 0 | my $error = $@; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 0 | ▶ | die $error unless $error =~ /\A(?:Invalid tag|Tag too long|Remove exactly)/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 0 | return $controller->render(text => $controller->l('tag_limit'), status => 400); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 2 | ▶ | return $controller->render(json => {tags => $tags}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$controller->req->headers->accept // ""
MC/DC100%1/1
$controller->req->headers->accept // ""
$controller->req->headers->accept
Truth table100%2/2
A
A= $controller->req->headers->accept
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | if ($controller->req->headers->accept // '') eq 'application/json'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 1 | $controller->res->code(303); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 1 | $controller->redirect_to('/scans/' . $scan->{id}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 7 | ▶ | sub _update_note { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_update_note: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 7 | my ($self, $controller) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | 7 | ▶ | return $controller->render(text => $controller->l('invalid_csrf'), status => 403) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | if $controller->validation->csrf_protect->has_error('csrf_token'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 6 | my $scan = $self->store->get($controller->param('id')); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 6 | ▶ | return $controller->reply->not_found unless $scan; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 5 | ▶ | my $note = $controller->param('note') // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$controller->param("note") // ""
MC/DC0%0/1
$controller->param("note") // ""
$controller->param("note")
Truth table50%1/2
A
A= $controller->param("note")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 5 | ▶ | return $controller->render(text => $controller->l('note_limit'), status => 400) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
length $note > 2000 or index($note, "\0") != -1
MC/DC50%1/2
length $note > 2000 or index($note, "\0") != -1
length $note > 2000
index($note, "\0") != -1
Truth table66%2/3
A or B
A= length $note > 2000B= index($note, "\0") != -1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | if length($note) > 2000 || index($note, "\0") >= 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 2 | $self->store->db->do('UPDATE jobs SET note=? WHERE id=?', undef, $note, $scan->{id}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 2 | ▶ | return $controller->render(json => {note => $note}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$controller->req->headers->accept // ""
MC/DC100%1/1
$controller->req->headers->accept // ""
$controller->req->headers->accept
Truth table100%2/2
A
A= $controller->req->headers->accept
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | if ($controller->req->headers->accept // '') eq 'application/json'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 1 | $controller->res->code(303); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 1 | $controller->redirect_to('/scans/' . $scan->{id}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | 22 | ▶ | sub _page_number { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_page_number: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 22 | my ($self, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 22 | ▶ | return 1 unless ($value // '') =~ /\A[1-9]\d{0,5}\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$value // ""
MC/DC100%1/1
$value // ""
$value
Truth table100%2/2
A
A= $value
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | 2 | return $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | 7 | ▶ | sub _download_artifact { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_download_artifact: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | 7 | my ($self, $controller) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | # Store resolves a Scan ID plus an allowlisted kind; no request value is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | # ever interpreted as a filesystem path or a download filename. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 7 | my $kind = $controller->param('kind'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 7 | ▶ | if ($kind eq 'metadata') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | 4 | ▶ | my $scan = $self->store->get($controller->param('id')) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | or return $controller->reply->not_found; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | 3 | $controller->res->headers->content_disposition('attachment; filename="metadata.json"'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | 3 | return $controller->render(json => $scan); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | 3 | my $file = $self->store->artifact($controller->param('id'), $kind); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | 3 | ▶ | return $controller->reply->not_found unless $file; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | 2 | my $headers = $controller->res->headers; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 2 | $headers->content_disposition('attachment; filename="' . $file->basename . '"'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | 2 | ▶ | $headers->content_type($kind eq 'log' ? 'text/plain; charset=UTF-8' : 'application/json'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 2 | $controller->reply->file("$file"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||