« blib/lib/Langertha/Holmgang/Sim/Linux/Docker.pm
↑ Summary
blib/lib/Langertha/Holmgang/Sim/Linux/Storage.pm »
| 1 | package Langertha::Holmgang::Sim::Linux::Http; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: HTTP between simulated devices: curl, applications behind ports, probes at the end state | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 5 | ▶ | use strict; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 5 | ▶ | use warnings; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 5 | ▶ | use utf8; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 5 | ▶ | use JSON::MaybeXS (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 5 | our $VERSION = '0.001'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 5 | my $JSON = JSON::MaybeXS->new( utf8 => 0, canonical => 1, allow_nonref => 1 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 5 | our %REASON = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 101 => 'Switching Protocols', 200 => 'OK', 201 => 'Created', 204 => 'No Content', 301 => 'Moved Permanently', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 302 => 'Found', 304 => 'Not Modified', 307 => 'Temporary Redirect', 308 => 'Permanent Redirect', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 400 => 'Bad Request', 401 => 'Unauthorized', 403 => 'Forbidden', 404 => 'Not Found', 405 => 'Not Allowed', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 408 => 'Request Time-out', 413 => 'Request Entity Too Large', 421 => 'Misdirected Request', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 426 => 'Upgrade Required', 429 => 'Too Many Requests', 494 => 'Request Header Or Cookie Too Large', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 495 => 'SSL Certificate Error', 496 => 'No Required SSL Certificate', 500 => 'Internal Server Error', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 502 => 'Bad Gateway', 503 => 'Service Temporarily Unavailable', 504 => 'Gateway Time-out', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 250 | ▶ | sub _linux { require Langertha::Holmgang::Sim::Linux; return 'Langertha::Holmgang::Sim::Linux' } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_linux: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 546 | ▶ | sub _nginx_on { my ($d) = @_; return ref $d eq 'HASH' && ref $d->{nginx} eq 'HASH' } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_nginx_on: called CC=2 SCAR=7.1
Condition66%2/3
ref $d eq 'HASH' && ref $$d{'nginx'} eq 'HASH'
MC/DC50%1/2
ref $d eq 'HASH' && ref $$d{'nginx'} eq 'HASH'
ref $d eq 'HASH'
ref $$d{'nginx'} eq 'HASH'
Truth table66%2/3
A && B
A= ref $d eq 'HASH'B= ref $$d{'nginx'} eq 'HASH'
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 427 | ▶ | sub _docker_on { my ($d) = @_; return ref $d eq 'HASH' && ref $d->{docker} eq 'HASH' } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_docker_on: called CC=2 SCAR=7.1
Condition66%2/3
ref $d eq 'HASH' && ref $$d{'docker'} eq 'HASH'
MC/DC50%1/2
ref $d eq 'HASH' && ref $$d{'docker'} eq 'HASH'
ref $d eq 'HASH'
ref $$d{'docker'} eq 'HASH'
Truth table66%2/3
A && B
A= ref $d eq 'HASH'B= ref $$d{'docker'} eq 'HASH'
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 179 | ▶ | sub before { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
before: called CC=5 SCAR=16.1
Pod
documented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 179 | my ($state) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 179 | ▶ | return unless ref $state eq 'HASH'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 179 | for my $h ( sort keys %$state ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 343 | my $d = $state->{$h}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 343 | ▶ | if ( _nginx_on($d) ) { require Langertha::Holmgang::Sim::Linux::Nginx; Langertha::Holmgang::Sim::Linux::Nginx::ensure( $d, $h, $state ) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 343 | ▶ | if ( _docker_on($d) ) { Langertha::Holmgang::Sim::Linux::_part('Docker'); Langertha::Holmgang::Sim::Linux::Docker::ensure( $d, $h, $state ) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 179 | return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 179 | ▶ | sub after { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
after: called CC=21 SCAR=32.2
Pod
documented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 179 | my ($state) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 179 | ▶ | return unless ref $state eq 'HASH'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 179 | for my $h ( sort keys %$state ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 343 | my $d = $state->{$h}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 343 | ▶ | next unless ref $d eq 'HASH' && ref $d->{probes} eq 'HASH'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $d eq "HASH" and ref $$d{"probes"} eq "HASH"
MC/DC50%1/2
ref $d eq "HASH" and ref $$d{"probes"} eq "HASH"
ref $d eq "HASH"
ref $$d{"probes"} eq "HASH"
Truth table66%2/3
A and B
A= ref $d eq "HASH"B= ref $$d{"probes"} eq "HASH"
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 100 | for my $n ( sort keys %{ $d->{probes} } ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 100 | my $p = $d->{probes}{$n}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 100 | ▶ | next unless ref $p eq 'HASH' && defined $p->{url}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $p eq "HASH" and defined $$p{"url"}
MC/DC0%0/2
ref $p eq "HASH" and defined $$p{"url"}
ref $p eq "HASH"
defined $$p{"url"}
Truth table33%1/3
A and B
A= ref $p eq "HASH"B= defined $$p{"url"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | my $res = request( $state, $h, { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | url => $p->{url}, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | method => $p->{method} // 'GET', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | ▶ | headers => { map { lc($_) => $p->{headers}{$_} } keys %{ $p->{headers} || {} } }, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$$p{'headers'} || {}
MC/DC0%0/1
$$p{'headers'} || {}
$$p{'headers'}
Truth table50%1/2
A
A= $$p{'headers'}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 100 | ▶ | map { exists $p->{$_} ? ( $_ => $p->{$_} ) : () } qw( insecure resolve cacert cert key body_size max_time follow tls_version sni ), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$$p{"method"} // "GET"
MC/DC0%0/1
$$p{"method"} // "GET"
$$p{"method"}
Truth table50%1/2
A
A= $$p{"method"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | } ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 100 | ▶ | my %r = ( status => $res->{status} // 0 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$$res{"status"} // 0
MC/DC100%1/1
$$res{"status"} // 0
$$res{"status"}
Truth table100%2/2
A
A= $$res{"status"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 100 | ▶ | $r{error} = $res->{error} if defined $res->{error}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 100 | ▶ | for my $k (qw( body cert protocol )) { $r{$k} = $res->{$k} if defined $res->{$k} } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 100 | ▶ | $r{headers} = { map { lc( $_->[0] ) => $_->[1] } @{ $res->{headers} || [] } } if $res->{headers}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$$res{'headers'} || []
MC/DC0%0/1
$$res{'headers'} || []
$$res{'headers'}
Truth table50%1/2
A
A= $$res{'headers'}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 100 | ▶ | $r{location} = $r{headers}{location} if $r{headers} && defined $r{headers}{location}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$r{"headers"} and defined $r{"headers"}{"location"}
MC/DC0%0/2
$r{"headers"} and defined $r{"headers"}{"location"}
$r{"headers"}
defined $r{"headers"}{"location"}
Truth table66%2/3
A and B
A= $r{"headers"}B= defined $r{"headers"}{"location"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 100 | ▶ | $r{backend} = $res->{backend} if $res->{backend}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 100 | ▶ | $r{redirects} = $res->{redirects} if $res->{redirects}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 100 | $p->{result} = \%r; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 179 | return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | # --- Adressen --------------------------------------------------------------------- | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | # Adressen eines Geraets (ohne Laenge) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 459 | ▶ | sub addresses { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
addresses: called CC=4 SCAR=14.0
Pod
documented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 459 | my ($d) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 459 | my @a = ('127.0.0.1'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 459 | ▶ | for my $if ( values %{ $d->{interfaces} || {} } ) { push @a, map { s{/.*}{}r } @{ $if->{addr} || [] } } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%2/4
$$d{'interfaces'} || {}
$$if{'addr'} || []
MC/DC0%0/1
$$d{'interfaces'} || {}
$$d{'interfaces'}
MC/DC0%0/1
$$if{'addr'} || []
$$if{'addr'}
Truth table50%1/2
A
A= $$d{'interfaces'}
Truth table50%1/2
A
A= $$if{'addr'}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 459 | return @a; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | # Name -> ( geraet, ip ) vom fragenden Geraet aus; () wenn unbekannt | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 203 | ▶ | sub resolve { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
resolve: called CC=15 SCAR=38.8
Pod
documented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 203 | my ( $state, $from, $name, $override ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 203 | my $d = $state->{$from}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 203 | my $ip; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 203 | ▶ | if ( $name =~ /\A\d+\.\d+\.\d+\.\d+\z/ ) { $ip = $name } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | elsif ( defined $override ) { $ip = $override } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | elsif ( $name eq 'localhost' ) { $ip = '127.0.0.1' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 124 | ▶ | ($ip) = _linux()->can('_resolve')->( $d, $name ) if ref $d eq 'HASH'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 124 | ▶ | if ( !defined $ip ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | # Rueckfall: der Name eines Geraets im Zustand (bzw. sein hostname) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | ▶ | my ($h) = grep { $_ eq $name || ( ref $state->{$_} eq 'HASH' && ( $state->{$_}{hostname} // '' ) eq $name ) } sort keys %$state; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/8
$_ eq $name || ref $$state{$_} eq 'HASH' && ($$state{$_}{'hostname'} // '') eq $name
ref $$state{$_} eq "HASH" and ($$state{$_}{"hostname"} // "") eq $name
$$state{$_}{"hostname"} // ""
MC/DC0%0/3
$_ eq $name || ref $$state{$_} eq 'HASH' && ($$state{$_}{'hostname'} // '') eq $name
$_ eq $name
ref $$state{$_} eq "HASH"
$$state{$_}{"hostname"}
Truth table0%0/4
A || B and C
A= $_ eq $nameB= ref $$state{$_} eq "HASH"C= $$state{$_}{"hostname"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | ▶ | return () unless defined $h; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | my @a = grep { $_ ne '127.0.0.1' } addresses( $state->{$h} ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | ▶ | return ( $h, $a[0] // '127.0.0.1' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$a[0] // "127.0.0.1"
MC/DC0%0/1
$a[0] // "127.0.0.1"
$a[0]
Truth table0%0/2
A
A= $a[0]
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 203 | ▶ | return ( $from, $ip ) if $ip =~ /\A127\./; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 125 | for my $h ( sort keys %$state ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 334 | ▶ | next unless ref $state->{$h} eq 'HASH'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 334 | ▶ | return ( $h, $ip ) if grep { $_ eq $ip } addresses( $state->{$h} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | return ( undef, $ip ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | # --- Anfrage -------------------------------------------------------------------- | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 230 | ▶ | sub parse_url { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_url: called CC=6 SCAR=18.3
Pod
documented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 230 | my ($u) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 230 | ▶ | $u = "http://$u" unless $u =~ m{\A[a-z]+://}i; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 230 | ▶ | my ( $scheme, $host, $port, $path ) = $u =~ m{\A([a-z]+)://(\[[^\]]+\]|[^/:?#]+)(?::(\d+))?([^#]*)}i or return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 230 | $scheme = lc $scheme; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 230 | ▶ | $path = '/' . $path if $path !~ m{\A/}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 230 | ▶ | return { scheme => $scheme, host => lc $host, port => $port // ( $scheme eq 'https' ? 443 : 80 ), path => $path }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$port // ($scheme eq "https" ? 443 : 80)
MC/DC100%1/1
$port // ($scheme eq "https" ? 443 : 80)
$port
Truth table100%2/2
A
A= $port
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 203 | ▶ | sub request { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
request: called CC=44 SCAR=52.2
Pod
documented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 203 | my ( $state, $from, $req, $depth ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 203 | ▶ | $depth //= 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$depth //= 0
MC/DC100%1/1
$depth //= 0
$depth
Truth table100%2/2
A
A= $depth
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 203 | ▶ | my $u = parse_url( $req->{url} // '' ) or return { error => "(3) URL using bad/illegal format or missing URL", code => 3 }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$$req{"url"} // ""
MC/DC0%0/1
$$req{"url"} // ""
$$req{"url"}
Truth table50%1/2
A
A= $$req{"url"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 203 | ▶ | return { error => "(1) Protocol \"$u->{scheme}\" not supported", code => 1 } unless $u->{scheme} =~ /\Ahttps?\z/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 203 | my %r = ( %$req, %$u ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 203 | ▶ | $r{method} = uc( $r{method} // 'GET' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$r{"method"} // "GET"
MC/DC0%0/1
$r{"method"} // "GET"
$r{"method"}
Truth table50%1/2
A
A= $r{"method"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 203 | ▶ | $r{headers} = { %{ $req->{headers} || {} } }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$$req{'headers'} || {}
MC/DC0%0/1
$$req{'headers'} || {}
$$req{'headers'}
Truth table50%1/2
A
A= $$req{'headers'}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 203 | ▶ | $r{headers}{host} //= $u->{host} . ( $u->{port} == ( $u->{scheme} eq 'https' ? 443 : 80 ) ? '' : ":$u->{port}" ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%2/2
$r{"headers"}{"host"} //= $$u{"host"} . ($$u{"port"} == ($$u{"scheme"} eq "https" ? 443 : 80) ? "" : qq[:$$u{"port"}])
MC/DC100%1/1
$r{"headers"}{"host"} //= $$u{"host"} . ($$u{"port"} == ($$u{"scheme"} eq "https" ? 443 : 80) ? "" : qq[:$$u{"port"}])
$r{"headers"}{"host"}
Truth table100%2/2
A
A= $r{"headers"}{"host"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 203 | my $override; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 203 | ▶ | for my $rv ( ref $req->{resolve} ? @{ $req->{resolve} } : grep {defined} $req->{resolve} ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | my ( $n, $p, $ip ) = split /:/, $rv, 3; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | ▶ | $override = $ip if defined $ip && lc($n) eq $u->{host} && $p == $u->{port}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
defined $ip and lc $n eq $$u{"host"} and $p == $$u{"port"}
defined $ip and lc $n eq $$u{"host"}
MC/DC0%0/3
defined $ip and lc $n eq $$u{"host"} and $p == $$u{"port"}
defined $ip
lc $n eq $$u{"host"}
$p == $$u{"port"}
Truth table0%0/4
A and B and C
A= defined $ipB= lc $n eq $$u{"host"}C= $p == $$u{"port"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 203 | my ( $to, $ip ) = resolve( $state, $from, $u->{host}, $override ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 203 | ▶ | return { error => "(6) Could not resolve host: $u->{host}", code => 6 } unless defined $ip; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 203 | $r{ip} = $ip; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 203 | ▶ | $r{client_ip} //= $to && $to eq $from ? '127.0.0.1' : _source_ip( $state->{$from}, $ip ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$r{"client_ip"} //= $to && $to eq $from ? "127.0.0.1" : _source_ip($$state{$from}, $ip)
$to and $to eq $from
MC/DC0%0/3
$r{"client_ip"} //= $to && $to eq $from ? "127.0.0.1" : _source_ip($$state{$from}, $ip)
$r{"client_ip"}
$to
$to eq $from
Truth table0%0/4
A //= B and C
A= $r{"client_ip"}B= $toC= $to eq $from
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 203 | my $refused = { error => "(7) Failed to connect to $u->{host} port $u->{port} after 0 ms: Couldn't connect to server", code => 7 }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 203 | ▶ | return $refused unless defined $to; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 203 | my $dev = $state->{$to}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 203 | my $res; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 203 | ▶ | if ( _nginx_on($dev) ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 202 | require Langertha::Holmgang::Sim::Linux::Nginx; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 202 | $res = Langertha::Holmgang::Sim::Linux::Nginx::serve( $state, $to, \%r, $from, $depth ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 203 | ▶ | if ( !$res && _docker_on($dev) ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $res and _docker_on($dev)
MC/DC100%2/2
not $res and _docker_on($dev)
not $res
_docker_on($dev)
Truth table100%3/3
not(A) and B
A= not $resB= _docker_on($dev)
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 1 | Langertha::Holmgang::Sim::Linux::_part('Docker'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 1 | $res = Langertha::Holmgang::Sim::Linux::Docker::serve( $state, $to, \%r, $from, $depth ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 203 | ▶ | $res //= app_serve( $state, $to, \%r, $from ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$res //= app_serve($state, $to, \%r, $from)
MC/DC100%2/2
$res //= app_serve($state, $to, \%r, $from)
$res
app_serve($state, $to, \%r, $from)
Truth table100%3/3
A //= B
A= $resB= app_serve($state, $to, \%r, $from)
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 203 | ▶ | return $refused unless $res; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 193 | ▶ | return $res if defined $res->{error}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | # TLS: der Client prueft, was der Server vorzeigt | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 191 | ▶ | if ( $u->{scheme} eq 'https' ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 37 | ▶ | if ( !$res->{tls} ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 1 | return { error => '(35) OpenSSL/3.0.15: error:0A00010B:SSL routines::wrong version number', code => 35 }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 36 | ▶ | if ( !$req->{insecure} ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 34 | require Langertha::Holmgang::Sim::Linux::Pki; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 34 | ▶ | if ( my $bad = Langertha::Holmgang::Sim::Linux::Pki::client_verify( $state, $from, $res->{tls}, \%r ) ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 28 | return { error => $bad->[1], code => $bad->[0], tls_lines => $res->{tls}{lines} }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 162 | my $max = $req->{max_time}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 162 | ▶ | if ( defined $max && ( $res->{delay} // 0 ) > $max ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition20%1/5
defined $max and ($$res{"delay"} // 0) > $max
$$res{"delay"} // 0
MC/DC0%0/2
defined $max and ($$res{"delay"} // 0) > $max
defined $max
$$res{"delay"}
Truth table33%1/3
A and B
A= defined $maxB= $$res{"delay"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | return { error => sprintf( '(28) Operation timed out after %d milliseconds with 0 bytes received', $max * 1000 + 1 ), code => 28 }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 162 | ▶ | if ( $req->{follow} && ( $res->{status} // 0 ) =~ /\A30[1278]\z/ ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition20%1/5
$$req{"follow"} and ($$res{"status"} // 0) =~ /\A30[1278]\z/
$$res{"status"} // 0
MC/DC0%0/2
$$req{"follow"} and ($$res{"status"} // 0) =~ /\A30[1278]\z/
$$req{"follow"}
$$res{"status"}
Truth table33%1/3
A and B
A= $$req{"follow"}B= $$res{"status"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | ▶ | my ($loc) = map { $_->[1] } grep { lc( $_->[0] ) eq 'location' } @{ $res->{headers} || [] }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$$res{'headers'} || []
MC/DC0%0/1
$$res{'headers'} || []
$$res{'headers'}
Truth table0%0/2
A
A= $$res{'headers'}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | ▶ | if ( defined $loc ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | ▶ | my $n = ( $req->{_redirects} // 0 ) + 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$$req{"_redirects"} // 0
MC/DC0%0/1
$$req{"_redirects"} // 0
$$req{"_redirects"}
Truth table0%0/2
A
A= $$req{"_redirects"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | ▶ | return { error => "(47) Maximum (50) redirects followed", code => 47, redirects => $n - 1 } if $n > 50; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | ▶ | my $next = $loc =~ m{\A[a-z]+://}i ? $loc : "$u->{scheme}://$u->{host}" . ( $loc =~ m{\A/} ? $loc : "/$loc" ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | ▶ | my %h = %{ $req->{headers} || {} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$$req{'headers'} || {}
MC/DC0%0/1
$$req{'headers'} || {}
$$req{'headers'}
Truth table0%0/2
A
A= $$req{'headers'}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | delete $h{host}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | my $r2 = request( $state, $from, { %$req, url => $next, headers => \%h, _redirects => $n }, $depth ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | ▶ | $r2->{redirects} //= $n; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$$r2{"redirects"} //= $n
MC/DC0%0/2
$$r2{"redirects"} //= $n
$$r2{"redirects"}
$n
Truth table0%0/3
A //= B
A= $$r2{"redirects"}B= $n
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | return $r2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 162 | return $res; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 125 | ▶ | sub _source_ip { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_source_ip: called CC=8 SCAR=21.3
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 125 | my ( $d, $to ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 125 | my @a = grep { $_ ne '127.0.0.1' } addresses($d); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 125 | ▶ | for my $if ( values %{ $d->{interfaces} || {} } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$$d{'interfaces'} || {}
MC/DC0%0/1
$$d{'interfaces'} || {}
$$d{'interfaces'}
Truth table50%1/2
A
A= $$d{'interfaces'}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 125 | ▶ | for my $c ( @{ $if->{addr} || [] } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$$if{'addr'} || []
MC/DC0%0/1
$$if{'addr'} || []
$$if{'addr'}
Truth table50%1/2
A
A= $$if{'addr'}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 125 | my ( $ip, $len ) = split m{/}, $c; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 125 | ▶ | return $ip if defined $len && _linux()->can('_in')->( $to, "$ip/$len" ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $len and _linux()->can("_in")->($to, "$ip/$len")
MC/DC50%1/2
defined $len and _linux()->can("_in")->($to, "$ip/$len")
defined $len
_linux()->can("_in")->($to, "$ip/$len")
Truth table66%2/3
A and B
A= defined $lenB= _linux()->can("_in")->($to, "$ip/$len")
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 1 | ▶ | return $a[0] // '127.0.0.1'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$a[0] // "127.0.0.1"
MC/DC0%0/1
$a[0] // "127.0.0.1"
$a[0]
Truth table50%1/2
A
A= $a[0]
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | # --- Anwendungen (http) ----------------------------------------------------------- | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | # Passt ein Lauscher "ip:port" | "port" auf ( ip, port )? 127.* nur vom Geraet selbst. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 78 | ▶ | sub listens { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
listens: called CC=12 SCAR=31.9
Pod
documented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 78 | my ( $key, $ip, $port, $local ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 78 | ▶ | my ( $lip, $lport ) = $key =~ /\A(?:(.+):)?(\d+)\z/ or return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 78 | ▶ | return 0 unless $lport == $port; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 74 | ▶ | $lip //= '0.0.0.0'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$lip //= "0.0.0.0"
MC/DC0%0/1
$lip //= "0.0.0.0"
$lip
Truth table50%1/2
A
A= $lip
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 74 | ▶ | $lip = '0.0.0.0' if $lip eq '*' || $lip eq ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$lip eq "*" or $lip eq ""
MC/DC0%0/2
$lip eq "*" or $lip eq ""
$lip eq "*"
$lip eq ""
Truth table33%1/3
A or B
A= $lip eq "*"B= $lip eq ""
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 74 | ▶ | return 1 if $lip eq '0.0.0.0'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 74 | ▶ | return 0 if $lip =~ /\A127\./ && !$local; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$lip =~ /\A127\./ and not $local
MC/DC0%0/2
$lip =~ /\A127\./ and not $local
$lip =~ /\A127\./
not $local
Truth table33%1/3
A and not(B)
A= $lip =~ /\A127\./B= not $local
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 74 | ▶ | return $lip eq $ip || ( $lip =~ /\A127\./ && $ip =~ /\A127\./ ) ? 1 : 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition16%1/6
$lip eq $ip or $lip =~ /\A127\./ and $ip =~ /\A127\./
$lip =~ /\A127\./ and $ip =~ /\A127\./
MC/DC0%0/3
$lip eq $ip or $lip =~ /\A127\./ and $ip =~ /\A127\./
$lip eq $ip
$lip =~ /\A127\./
$ip =~ /\A127\./
Truth table25%1/4
A or B and C
A= $lip eq $ipB= $lip =~ /\A127\./C= $ip =~ /\A127\./
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 83 | ▶ | sub app_serve { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
app_serve: called CC=8 SCAR=21.1
Pod
documented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 83 | my ( $state, $to, $req, $from ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 83 | my $dev = $state->{$to}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 83 | ▶ | my $apps = ref $dev->{http} eq 'HASH' ? $dev->{http} : return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 78 | ▶ | my $local = defined $from && $from eq $to; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
defined $from && $from eq $to
MC/DC50%1/2
defined $from && $from eq $to
defined $from
$from eq $to
Truth table66%2/3
A && B
A= defined $fromB= $from eq $to
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 78 | ▶ | my ($key) = grep { listens( $_, $req->{ip}, $req->{port}, $local ) } sort keys %$apps or return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 74 | my $app = $apps->{$key}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 74 | ▶ | if ( defined $app->{service} ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 74 | ▶ | my $svc = ( $dev->{services} || {} )->{ $app->{service} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$$dev{'services'} || {}
MC/DC0%0/1
$$dev{'services'} || {}
$$dev{'services'}
Truth table50%1/2
A
A= $$dev{'services'}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 74 | ▶ | return undef unless $svc && $svc->{active}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$svc and $$svc{"active"}
MC/DC50%1/2
$svc and $$svc{"active"}
$svc
$$svc{"active"}
Truth table66%2/3
A and B
A= $svcB= $$svc{"active"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 73 | return respond( $app, $req, "$to $key" ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 75 | ▶ | sub respond { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
respond: called CC=18 SCAR=39.0
Pod
documented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 75 | my ( $app, $req, $name ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 75 | ▶ | my $path = $req->{path} // '/'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$$req{"path"} // "/"
MC/DC0%0/1
$$req{"path"} // "/"
$$req{"path"}
Truth table50%1/2
A
A= $$req{"path"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 75 | ( my $bare = $path ) =~ s/\?.*//; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 75 | ▶ | my %h = %{ $req->{headers} || {} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$$req{'headers'} || {}
MC/DC0%0/1
$$req{'headers'} || {}
$$req{'headers'}
Truth table50%1/2
A
A= $$req{'headers'}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 2 | ▶ | my $fill = sub { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=18.7
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 2 | my ($t) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 2 | ▶ | return $t unless defined $t && !ref $t; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $t and not ref $t
MC/DC0%0/2
defined $t and not ref $t
defined $t
not ref $t
Truth table33%1/3
A and not(B)
A= defined $tB= not ref $t
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 2 | ▶ | my $host = $h{host} // ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$h{"host"} // ""
MC/DC0%0/1
$h{"host"} // ""
$h{"host"}
Truth table50%1/2
A
A= $h{"host"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 2 | $host =~ s/:\d+\z//; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 2 | $t =~ s/\{host\}/$host/g; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 2 | $t =~ s/\{path\}/$path/g; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | ▶ | $t =~ s/\{header:([\w-]+)\}/$h{lc $1} \/\/ ''/ge; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$h{lc $1} // ""
MC/DC0%0/1
$h{lc $1} // ""
$h{lc $1}
Truth table0%0/2
A
A= $h{lc $1}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 2 | return $t; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 75 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | my $backend = { app => $name, path => $path, host => $h{host}, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 75 | ▶ | headers => { map { $_ => $h{$_} } grep { $_ ne 'host' && $_ ne 'user-agent' && $_ ne 'accept' } sort keys %h } }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%6/6
$_ ne 'host' && $_ ne 'user-agent' && $_ ne 'accept'
$_ ne "host" and $_ ne "user-agent"
MC/DC100%3/3
$_ ne 'host' && $_ ne 'user-agent' && $_ ne 'accept'
$_ ne "host"
$_ ne "user-agent"
$_ ne 'accept'
Truth table100%4/4
A and B && C
A= $_ ne "host"B= $_ ne "user-agent"C= $_ ne 'accept'
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 75 | ▶ | my $mk = sub { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=20.7
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 75 | my ($s) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | ▶ | my @hd = map { [ $_, $fill->( $s->{headers}{$_} ) ] } sort keys %{ $s->{headers} || {} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$$s{'headers'} || {}
MC/DC0%0/1
$$s{'headers'} || {}
$$s{'headers'}
Truth table50%1/2
A
A= $$s{'headers'}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | my $body = $s->{echo} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | ? $JSON->encode( { method => $req->{method}, path => $path, headers => { %h } } ) . "\n" | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 75 | ▶ | : $fill->( $s->{body} // '' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$$s{"body"} // ""
MC/DC0%0/1
$$s{"body"} // ""
$$s{"body"}
Truth table50%1/2
A
A= $$s{"body"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | return { status => $s->{status} // 200, headers => \@hd, body => $body, backend => $backend, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 75 | ▶ | delay => $s->{delay} // $app->{delay} // 0 }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition71%5/7
$$s{"status"} // 200
($$s{"delay"} // $$app{"delay"}) // 0
$$s{"delay"} // $$app{"delay"}
MC/DC0%0/1
$$s{"status"} // 200
$$s{"status"}
MC/DC50%1/2
($$s{"delay"} // $$app{"delay"}) // 0
$$s{"delay"}
$$app{"delay"}
Truth table50%1/2
A
A= $$s{"status"}
Truth table66%2/3
A // B
A= $$s{"delay"}B= $$app{"delay"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 75 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 75 | ▶ | for my $c ( @{ $app->{require} || [] } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$$app{'require'} || []
MC/DC0%0/1
$$app{'require'} || []
$$app{'require'}
Truth table50%1/2
A
A= $$app{'require'}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | ▶ | my $v = $h{ lc( $c->{header} // '' ) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$$c{"header"} // ""
MC/DC0%0/1
$$c{"header"} // ""
$$c{"header"}
Truth table0%0/2
A
A= $$c{"header"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | my $ok = defined $v; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | ▶ | $ok &&= $v eq $c->{equals} if $ok && defined $c->{equals}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$ok and defined $$c{"equals"}
$ok &&= $v eq $$c{"equals"}
MC/DC0%0/2
$ok and defined $$c{"equals"}
$ok
defined $$c{"equals"}
MC/DC0%0/2
$ok &&= $v eq $$c{"equals"}
$ok
$v eq $$c{"equals"}
Truth table0%0/3
A and B
A= $okB= defined $$c{"equals"}
Truth table0%0/3
A &&= B
A= $okB= $v eq $$c{"equals"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | ▶ | $ok &&= $v =~ /$c->{regex}/ if $ok && defined $c->{regex}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$ok and defined $$c{"regex"}
$ok &&= $v =~ /$$c{"regex"}/
MC/DC0%0/2
$ok and defined $$c{"regex"}
$ok
defined $$c{"regex"}
MC/DC0%0/2
$ok &&= $v =~ /$$c{"regex"}/
$ok
$v =~ /$$c{"regex"}/
Truth table0%0/3
A and B
A= $okB= defined $$c{"regex"}
Truth table0%0/3
A &&= B
A= $okB= $v =~ /$$c{"regex"}/
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | ▶ | $ok = !defined $v if exists $c->{absent}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | ▶ | return $mk->($c) unless $ok; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 4 | my ($route) = sort { length $b->{path} <=> length $a->{path} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 75 | ▶ | grep { substr( $bare, 0, length $_->{path} ) eq $_->{path} } @{ $app->{routes} || [ { path => '/' } ] }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$$app{'routes'} || [{'path', '/'}]
MC/DC0%0/1
$$app{'routes'} || [{'path', '/'}]
$$app{'routes'}
Truth table50%1/2
A
A= $$app{'routes'}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 75 | ▶ | return $mk->( $route || { status => 404, body => "Not Found\n" } ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$route || {'status', 404, 'body', "Not Found\n"}
MC/DC0%0/1
$route || {'status', 404, 'body', "Not Found\n"}
$route
Truth table50%1/2
A
A= $route
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | # --- curl --------------------------------------------------------------------------- | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 5 | my %CURL_FLAG = map { $_ => 1 } qw( -s --silent -S --show-error -f --fail --fail-with-body -k --insecure -I --head | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | -i --include -v --verbose -L --location -4 -6 --http1.1 --http1.0 --http2 --compressed -N --no-buffer -g --globoff | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | --no-progress-meter -q --ipv4 --ipv6 --tlsv1.2 --tlsv1.3 --ssl-no-revoke ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 5 | my %CURL_ARG = map { $_ => 1 } qw( -o --output -w --write-out -H --header -X --request -d --data --data-binary | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | --data-raw --data-urlencode -F --form --resolve --cacert --capath --cert --key -m --max-time --connect-timeout | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | -u --user -A --user-agent -e --referer -b --cookie -c --cookie-jar --max-redirs -T --upload-file --interface | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | --retry --retry-delay --cert-type --key-type --pass --url --tls-max --ciphers ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 26 | ▶ | sub curl { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
curl: called CC=114 SCAR=68.9
Pod
documented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 26 | my ( $dev, $av, $ctx ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 26 | ▶ | my $state = $ctx->{state} || { $ctx->{host} => $dev }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$$ctx{'state'} || {$$ctx{'host'}, $dev}
MC/DC0%0/1
$$ctx{'state'} || {$$ctx{'host'}, $dev}
$$ctx{'state'}
Truth table50%1/2
A
A= $$ctx{'state'}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 26 | my $from = $ctx->{host}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 26 | my ( %f, @hdr, @res, $url, $out_file, $wfmt, $method, $body ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 26 | my @a = @$av; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 26 | ▶ | while (@a) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 71 | my $x = shift @a; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 71 | ▶ | if ( $x =~ /\A-([a-zA-Z]{2,})\z/ ) { # -sSfL, -sSo datei | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 7 | my @c = split //, $1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 7 | ▶ | my $takes = $CURL_ARG{"-$c[-1]"} ? pop @c : undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | return ( "curl: option $x: is unknown\ncurl: try 'curl --help' or 'curl --manual' for more information", 0 ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 7 | ▶ | if grep { !$CURL_FLAG{"-$_"} } @c; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 7 | $f{"-$_"} = 1 for @c; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 7 | ▶ | unshift @a, "-$takes" if defined $takes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 7 | next; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | ▶ | if ( $x =~ /\A(--[\w.-]+)=(.*)\z/s && $CURL_ARG{$1} ) { unshift @a, $1, $2; next } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$x =~ /\A(--[\w.-]+)=(.*)\z/s and $CURL_ARG{$1}
MC/DC0%0/2
$x =~ /\A(--[\w.-]+)=(.*)\z/s and $CURL_ARG{$1}
$x =~ /\A(--[\w.-]+)=(.*)\z/s
$CURL_ARG{$1}
Truth table33%1/3
A and B
A= $x =~ /\A(--[\w.-]+)=(.*)\z/sB= $CURL_ARG{$1}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 64 | ▶ | if ( $CURL_FLAG{$x} ) { $f{$x} = 1; next } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 45 | ▶ | if ( $CURL_ARG{$x} ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 19 | my $v = shift @a; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 19 | ▶ | return ( "curl: option $x: requires parameter\ncurl: try 'curl --help' or 'curl --manual' for more information", 0 ) unless defined $v; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 19 | ▶ | if ( $x eq '-o' || $x eq '--output' ) { $out_file = $v } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 10 branches
Condition66%2/3
$x eq "-o" or $x eq "--output"
MC/DC50%1/2
$x eq "-o" or $x eq "--output"
$x eq "-o"
$x eq "--output"
Truth table66%2/3
A or B
A= $x eq "-o"B= $x eq "--output"
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 6 | ▶ | elsif ( $x eq '-w' || $x eq '--write-out' ) { $wfmt = $v } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$x eq "-w" or $x eq "--write-out"
MC/DC50%1/2
$x eq "-w" or $x eq "--write-out"
$x eq "-w"
$x eq "--write-out"
Truth table66%2/3
A or B
A= $x eq "-w"B= $x eq "--write-out"
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 5 | ▶ | elsif ( $x eq '-H' || $x eq '--header' ) { push @hdr, $v } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$x eq "-H" or $x eq "--header"
MC/DC50%1/2
$x eq "-H" or $x eq "--header"
$x eq "-H"
$x eq "--header"
Truth table66%2/3
A or B
A= $x eq "-H"B= $x eq "--header"
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | ▶ | elsif ( $x eq '-X' || $x eq '--request' ) { $method = $v } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$x eq "-X" or $x eq "--request"
MC/DC0%0/2
$x eq "-X" or $x eq "--request"
$x eq "-X"
$x eq "--request"
Truth table33%1/3
A or B
A= $x eq "-X"B= $x eq "--request"
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | elsif ( $x =~ /\A(?:-d|--data(?:-binary|-raw|-urlencode)?|-F|--form|-T|--upload-file)\z/ ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 1 | my $len = length $v; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 1 | ▶ | if ( $v =~ /\@(\S+)\z/ || $x eq '-T' || $x eq '--upload-file' ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$v =~ /\@(\S+)\z/ or $x eq "-T" or $x eq "--upload-file"
$v =~ /\@(\S+)\z/ or $x eq "-T"
MC/DC0%0/3
$v =~ /\@(\S+)\z/ or $x eq "-T" or $x eq "--upload-file"
$v =~ /\@(\S+)\z/
$x eq "-T"
$x eq "--upload-file"
Truth table25%1/4
A or B or C
A= $v =~ /\@(\S+)\z/B= $x eq "-T"C= $x eq "--upload-file"
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 1 | ▶ | my $p = $x =~ /\A(?:-T|--upload-file)\z/ ? $v : $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 1 | my $L = _linux(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 1 | ▶ | my $e = $L->can('_file_entry')->( $dev, $p ) or return ( "curl: (26) Failed to open/read local data from file/application", 0 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 1 | $len = $L->can('_file_size')->($e); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 1 | ▶ | $body = ( $body // 0 ) + $len; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$body // 0
MC/DC0%0/1
$body // 0
$body
Truth table50%1/2
A
A= $body
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 1 | ▶ | $method //= $x =~ /\A(?:-T|--upload-file)\z/ ? 'PUT' : 'POST'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$method //= $x =~ /\A(?:-T|--upload-file)\z/ ? "PUT" : "POST"
MC/DC0%0/1
$method //= $x =~ /\A(?:-T|--upload-file)\z/ ? "PUT" : "POST"
$method
Truth table50%1/2
A
A= $method
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | elsif ( $x eq '--resolve' ) { push @res, $v } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | ▶ | elsif ( $x eq '-m' || $x eq '--max-time' ) { $f{max_time} = $v } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$x eq "-m" or $x eq "--max-time"
MC/DC0%0/2
$x eq "-m" or $x eq "--max-time"
$x eq "-m"
$x eq "--max-time"
Truth table33%1/3
A or B
A= $x eq "-m"B= $x eq "--max-time"
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 0 | ▶ | elsif ( $x eq '-u' || $x eq '--user' ) { push @hdr, 'Authorization: Basic ' . _b64($v) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$x eq "-u" or $x eq "--user"
MC/DC0%0/2
$x eq "-u" or $x eq "--user"
$x eq "-u"
$x eq "--user"
Truth table33%1/3
A or B
A= $x eq "-u"B= $x eq "--user"
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | ▶ | elsif ( $x eq '-A' || $x eq '--user-agent' ) { push @hdr, "User-Agent: $v" } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$x eq "-A" or $x eq "--user-agent"
MC/DC0%0/2
$x eq "-A" or $x eq "--user-agent"
$x eq "-A"
$x eq "--user-agent"
Truth table33%1/3
A or B
A= $x eq "-A"B= $x eq "--user-agent"
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 0 | elsif ( $x eq '--url' ) { $url = $v } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 1 | else { $f{$x} = $v } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 19 | next; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 26 | ▶ | return ( "curl: option $x: is unknown\ncurl: try 'curl --help' or 'curl --manual' for more information", 0 ) if $x =~ /\A-/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 26 | ▶ | $url //= $x; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$url //= $x
MC/DC0%0/2
$url //= $x
$url
$x
Truth table33%1/3
A //= B
A= $urlB= $x
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 26 | ▶ | return ( "curl: no URL specified!\ncurl: try 'curl --help' or 'curl --manual' for more information", 0 ) unless defined $url; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 26 | ▶ | my $silent = $f{'-s'} || $f{'--silent'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$f{'-s'} || $f{'--silent'}
MC/DC0%0/2
$f{'-s'} || $f{'--silent'}
$f{'-s'}
$f{'--silent'}
Truth table33%1/3
A || B
A= $f{'-s'}B= $f{'--silent'}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 26 | ▶ | my $show = $f{'-S'} || $f{'--show-error'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$f{'-S'} || $f{'--show-error'}
MC/DC50%1/2
$f{'-S'} || $f{'--show-error'}
$f{'-S'}
$f{'--show-error'}
Truth table66%2/3
A || B
A= $f{'-S'}B= $f{'--show-error'}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 26 | ▶ | my $head = $f{'-I'} || $f{'--head'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$f{'-I'} || $f{'--head'}
MC/DC50%1/2
$f{'-I'} || $f{'--head'}
$f{'-I'}
$f{'--head'}
Truth table66%2/3
A || B
A= $f{'-I'}B= $f{'--head'}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 26 | my %h = ( 'user-agent' => 'curl/7.88.1', accept => '*/*' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 26 | ▶ | for (@hdr) { my ( $k, $v ) = /\A([^:]+):\s*(.*)\z/ or next; $h{ lc $k } = $v } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 26 | ▶ | my $u = parse_url($url) // {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
parse_url($url) // {}
MC/DC0%0/1
parse_url($url) // {}
parse_url($url)
Truth table50%1/2
A
A= parse_url($url)
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 26 | ▶ | $h{host} //= $u->{host} . ( ( $u->{port} // 80 ) == ( ( $u->{scheme} // '' ) eq 'https' ? 443 : 80 ) ? '' : ":$u->{port}" ) if $u->{host}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition66%4/6
$h{"host"} //= $$u{"host"} . (($$u{"port"} // 80) == (($$u{"scheme"} // "") eq "https" ? 443 : 80) ? "" : qq[:$$u{"port"}])
$$u{"port"} // 80
$$u{"scheme"} // ""
MC/DC100%1/1
$h{"host"} //= $$u{"host"} . (($$u{"port"} // 80) == (($$u{"scheme"} // "") eq "https" ? 443 : 80) ? "" : qq[:$$u{"port"}])
$h{"host"}
MC/DC0%0/1
$$u{"port"} // 80
$$u{"port"}
MC/DC0%0/1
$$u{"scheme"} // ""
$$u{"scheme"}
Truth table100%2/2
A
A= $h{"host"}
Truth table50%1/2
A
A= $$u{"port"}
Truth table50%1/2
A
A= $$u{"scheme"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | my $req = { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | url => $url, method => $method // ( $head ? 'HEAD' : 'GET' ), headers => \%h, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | resolve => \@res, insecure => $f{'-k'} || $f{'--insecure'}, follow => $f{'-L'} || $f{'--location'}, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | ( defined $body ? ( body_size => $body ) : () ), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 26 | ▶ | map { defined $f{"--$_"} ? ( $_ => $f{"--$_"} ) : () } qw( cacert cert key ), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition62%5/8
$method // ($head ? "HEAD" : "GET")
$f{'-k'} || $f{'--insecure'}
$f{'-L'} || $f{'--location'}
MC/DC100%1/1
$method // ($head ? "HEAD" : "GET")
$method
MC/DC50%1/2
$f{'-k'} || $f{'--insecure'}
$f{'-k'}
$f{'--insecure'}
MC/DC0%0/2
$f{'-L'} || $f{'--location'}
$f{'-L'}
$f{'--location'}
Truth table100%2/2
A
A= $method
Truth table66%2/3
A || B
A= $f{'-k'}B= $f{'--insecure'}
Truth table33%1/3
A || B
A= $f{'-L'}B= $f{'--location'}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 26 | ▶ | $req->{max_time} = $f{max_time} if defined $f{max_time} && $f{max_time} =~ /\A\d+(?:\.\d+)?\z/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $f{"max_time"} and $f{"max_time"} =~ /\A\d+(?:\.\d+)?\z/
MC/DC0%0/2
defined $f{"max_time"} and $f{"max_time"} =~ /\A\d+(?:\.\d+)?\z/
defined $f{"max_time"}
$f{"max_time"} =~ /\A\d+(?:\.\d+)?\z/
Truth table33%1/3
A and B
A= defined $f{"max_time"}B= $f{"max_time"} =~ /\A\d+(?:\.\d+)?\z/
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 26 | my $res = request( $state, $from, $req ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 26 | my @v; # -v | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 26 | ▶ | my $verbose = $f{'-v'} || $f{'--verbose'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$f{'-v'} || $f{'--verbose'}
MC/DC0%0/2
$f{'-v'} || $f{'--verbose'}
$f{'-v'}
$f{'--verbose'}
Truth table33%1/3
A || B
A= $f{'-v'}B= $f{'--verbose'}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 26 | ▶ | if ($verbose) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 0 | ▶ | my ( undef, $ip ) = $u->{host} ? resolve( $state, $from, $u->{host} ) : (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 0 | ▶ | if ( defined $ip ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | push @v, "* Trying $ip:$u->{port}..."; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | ▶ | push @v, "* Connected to $u->{host} ($ip) port $u->{port} (#0)" unless ( $res->{code} // 0 ) == 7; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$$res{"code"} // 0
MC/DC0%0/1
$$res{"code"} // 0
$$res{"code"}
Truth table0%0/2
A
A= $$res{"code"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 0 | ▶ | push @v, @{ $res->{tls_lines} || [] } if $u->{scheme} && $u->{scheme} eq 'https'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/5
$$u{"scheme"} and $$u{"scheme"} eq "https"
$$res{'tls_lines'} || []
MC/DC0%0/2
$$u{"scheme"} and $$u{"scheme"} eq "https"
$$u{"scheme"}
$$u{"scheme"} eq "https"
MC/DC0%0/1
$$res{'tls_lines'} || []
$$res{'tls_lines'}
Truth table0%0/3
A and B
A= $$u{"scheme"}B= $$u{"scheme"} eq "https"
Truth table0%0/2
A
A= $$res{'tls_lines'}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 26 | my $code = $res->{code}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 0 | ▶ | if ( !defined $code && ( $f{'-f'} || $f{'--fail'} ) && ( $res->{status} // 0 ) >= 400 ) { $code = 22 } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition36%4/11
not defined $code and $f{"-f"} || $f{"--fail"} and ($$res{"status"} // 0) >= 400
not defined $code and $f{"-f"} || $f{"--fail"}
$f{"-f"} or $f{"--fail"}
$$res{"status"} // 0
MC/DC0%0/4
not defined $code and $f{"-f"} || $f{"--fail"} and ($$res{"status"} // 0) >= 400
not defined $code
$f{"-f"}
$f{"--fail"}
$$res{"status"}
Truth table33%2/6
not(A) and B or C and D
A= not defined $codeB= $f{"-f"}C= $f{"--fail"}D= $$res{"status"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 26 | my @out; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 26 | ▶ | if ( defined $res->{error} ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 5 | push @out, @v; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 5 | ▶ | push @out, "* $res->{error}" if $verbose; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 5 | ▶ | push @out, "curl: $res->{error}" if !$silent || $show; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $silent or $show
MC/DC50%1/2
not $silent or $show
not $silent
$show
Truth table66%2/3
not(A) or B
A= not $silentB= $show
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | push @out, 'More details here: https://curl.se/docs/sslcerts.html', '', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 'curl failed to verify the legitimacy of the server and therefore could not', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 'establish a secure connection to it. To learn more about this situation and', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 'how to fix it, please visit the web page mentioned above.' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 5 | ▶ | if ( $res->{code} // 0 ) == 60 && ( !$silent || $show ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%4/8
($$res{"code"} // 0) == 60 and !$silent || $show
$$res{"code"} // 0
not $silent or $show
MC/DC0%0/3
($$res{"code"} // 0) == 60 and !$silent || $show
$$res{"code"}
not $silent
$show
Truth table25%1/4
A and not(B) or C
A= $$res{"code"}B= not $silentC= $show
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 5 | ▶ | push @out, _wout( $wfmt, { http_code => '000' }, $url ) if defined $wfmt; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 5 | return ( join( "\n", @out ), 0 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 21 | ▶ | my $status = $res->{status} // 200; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$$res{"status"} // 200
MC/DC0%0/1
$$res{"status"} // 200
$$res{"status"}
Truth table50%1/2
A
A= $$res{"status"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 21 | ▶ | my @hl = ( "HTTP/1.1 $status " . ( $REASON{$status} // '' ), _resp_headers($res) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$Langertha::Holmgang::Sim::Linux::Http::REASON{$status} // ""
MC/DC0%0/1
$Langertha::Holmgang::Sim::Linux::Http::REASON{$status} // ""
$Langertha::Holmgang::Sim::Linux::Http::REASON{$status}
Truth table50%1/2
A
A= $Langertha::Holmgang::Sim::Linux::Http::REASON{$status}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 21 | ▶ | if ($verbose) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | push @v, "> $req->{method} " . ( $u->{path} // '/' ) . ' HTTP/1.1', "> Host: " . ( $h{host} // '' ), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 0 | ( map { '> ' . _hname($_) . ": $h{$_}" } grep { exists $h{$_} } 'user-agent', 'accept', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 0 | ▶ | grep { !/\A(?:host|user-agent|accept)\z/ } sort keys %h ), '>'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/4
$$u{"path"} // "/"
$h{"host"} // ""
MC/DC0%0/1
$$u{"path"} // "/"
$$u{"path"}
MC/DC0%0/1
$h{"host"} // ""
$h{"host"}
Truth table0%0/2
A
A= $$u{"path"}
Truth table0%0/2
A
A= $h{"host"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 0 | push @v, ( map {"< $_"} @hl ), '<'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 21 | ▶ | if ( $code && $code == 22 ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$code and $code == 22
MC/DC0%0/2
$code and $code == 22
$code
$code == 22
Truth table33%1/3
A and B
A= $codeB= $code == 22
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 0 | push @out, @v; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 0 | ▶ | push @out, "curl: (22) The requested URL returned error: $status" if !$silent || $show; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $silent or $show
MC/DC0%0/2
not $silent or $show
not $silent
$show
Truth table0%0/3
not(A) or B
A= not $silentB= $show
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 0 | ▶ | push @out, _wout( $wfmt, { http_code => $status }, $url ) if defined $wfmt; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 0 | return ( join( "\n", @out ), 0 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 21 | push @out, @v; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 21 | my $show_body = !$head; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 21 | ▶ | if ( $head || $f{'-i'} || $f{'--include'} ) { push @out, @hl, '' } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$head or $f{"-i"} or $f{"--include"}
$head or $f{"-i"}
MC/DC33%1/3
$head or $f{"-i"} or $f{"--include"}
$head
$f{"-i"}
$f{"--include"}
Truth table50%2/4
A or B or C
A= $headB= $f{"-i"}C= $f{"--include"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 21 | ▶ | my $b = $res->{body} // ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$$res{"body"} // ""
MC/DC0%0/1
$$res{"body"} // ""
$$res{"body"}
Truth table50%1/2
A
A= $$res{"body"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 21 | ▶ | if ( defined $out_file ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 0 | ▶ | if ( $out_file ne '/dev/null' && $out_file ne '-' ) { my ( $e, $ok ) = _linux()->can('_write_path')->( $dev, $out_file, $b, 0, $ctx ); return ( $e, 0 ) unless $ok } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
$out_file ne "/dev/null" and $out_file ne "-"
MC/DC0%0/2
$out_file ne "/dev/null" and $out_file ne "-"
$out_file ne "/dev/null"
$out_file ne "-"
Truth table33%1/3
A and B
A= $out_file ne "/dev/null"B= $out_file ne "-"
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 6 | ▶ | $show_body = 0 unless $out_file eq '-'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 21 | ▶ | if ($show_body) { ( my $t = $b ) =~ s/\n\z//; push @out, $t if length $t } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 21 | ▶ | if ( defined $wfmt ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 0 | ▶ | my ($loc) = map { $_->[1] } grep { lc( $_->[0] ) eq 'location' } @{ $res->{headers} || [] }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$$res{'headers'} || []
MC/DC0%0/1
$$res{'headers'} || []
$$res{'headers'}
Truth table50%1/2
A
A= $$res{'headers'}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 6 | ▶ | my $w = _wout( $wfmt, { http_code => $status, redirect_url => $loc // '', ssl_verify_result => 0 }, $url ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$loc // ""
MC/DC0%0/1
$loc // ""
$loc
Truth table50%1/2
A
A= $loc
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 0 | ▶ | if ( @out && !$verbose && $show_body ) { $out[-1] .= $w } else { push @out, $w } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
@out and not $verbose and $show_body
@out and not $verbose
MC/DC0%0/3
@out and not $verbose and $show_body
@out
not $verbose
$show_body
Truth table25%1/4
A and not(B) and C
A= @outB= not $verboseC= $show_body
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 21 | ▶ | pop @out while @out && $out[-1] eq '' && $head; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
@out and $out[-1] eq "" and $head
@out and $out[-1] eq ""
MC/DC33%1/3
@out and $out[-1] eq "" and $head
@out
$out[-1] eq ""
$head
Truth table50%2/4
A and B and C
A= @outB= $out[-1] eq ""C= $head
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 21 | return ( join( "\n", @out ), 1 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 21 | ▶ | sub _resp_headers { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_resp_headers: called CC=3 SCAR=11.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 21 | my ($res) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 21 | ▶ | my @h = ( 'Server: ' . ( $res->{server} // 'nginx' ) ) x !!$res->{server}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$$res{"server"} // "nginx"
MC/DC100%1/1
$$res{"server"} // "nginx"
$$res{"server"}
Truth table100%2/2
A
A= $$res{"server"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 21 | ▶ | push @h, map {"$_->[0]: $_->[1]"} @{ $res->{headers} || [] }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$$res{'headers'} || []
MC/DC0%0/1
$$res{'headers'} || []
$$res{'headers'}
Truth table50%1/2
A
A= $$res{'headers'}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 21 | return @h; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 0 | ▶ | sub _hname { my ($n) = @_; return join '-', map {ucfirst} split /-/, $n } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_hname: not called CC=1 SCAR=6.9
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 6 | ▶ | sub _wout { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_wout: called CC=2 SCAR=7.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 6 | my ( $fmt, $v, $url ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 6 | $fmt =~ s/\\n/\n/g; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 6 | $fmt =~ s/%\{url_effective\}/$url/g; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 6 | $fmt =~ s/%\{time_total\}/0.012000/g; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 6 | ▶ | $fmt =~ s/%\{(\w+)\}/$v->{$1} \/\/ ''/ge; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$$v{$1} // ""
MC/DC0%0/1
$$v{$1} // ""
$$v{$1}
Truth table50%1/2
A
A= $$v{$1}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 6 | $fmt =~ s/\n\z//; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 6 | return $fmt; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 0 | ▶ | sub _b64 { require MIME::Base64; return MIME::Base64::encode_base64( $_[0], '' ) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_b64: not called CC=1 SCAR=6.9
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 5 | 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | __END__ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||