| 1 | package Punk::Test; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 56 | ▶ | use 5.010; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 56 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 56 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 56 | our $VERSION = '0.70'; | |||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 56 | ▶ | use Test::Builder (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 56 | ▶ | use Scalar::Util (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 56 | ▶ | use Socket qw(AF_UNIX SOCK_STREAM PF_UNSPEC); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 56 | ▶ | use POSIX (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 56 | ▶ | use File::Raw::JSON (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 56 | ▶ | use File::Raw::XML (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 56 | ▶ | use Punk::Test::WS (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 56 | ▶ | use Punk::Test::WS::Conn (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | # An in-process test client for a compiled Punk application: one object is | ||||||||||||||||||||||||||||||||||||||||||
| 19 | # one browser - it keeps a cookie jar, so sessions, CSRF and flash flows | ||||||||||||||||||||||||||||||||||||||||||
| 20 | # test the way they run. Every assertion returns $self for chaining and | ||||||||||||||||||||||||||||||||||||||||||
| 21 | # reports through the one Test::Builder singleton, so it works under | ||||||||||||||||||||||||||||||||||||||||||
| 22 | # Test::More and Test2 alike. | ||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | 56 | my $TB = Test::Builder->new; | |||||||||||||||||||||||||||||||||||||||||
| 25 | 56 | my %APPS; | |||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | # An application under test runs in the `test` environment unless something | ||||||||||||||||||||||||||||||||||||||||||
| 28 | # already said which. It is where a 500 still says what the handler died | ||||||||||||||||||||||||||||||||||||||||||
| 29 | # with: in production that goes to the log and the body is a fixed message, | ||||||||||||||||||||||||||||||||||||||||||
| 30 | # and an assertion cannot read a log. | ||||||||||||||||||||||||||||||||||||||||||
| 31 | 56 | ▶ | $ENV{PUNK_ENV} = 'test' unless defined $ENV{PUNK_ENV}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | 178 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=11 SCAR=24.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | 178 | my ($class, $app, %opts) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 35 | 178 | ▶ | my $app_class = ref $app ? undef : $app; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 178 | ▶ | if (ref $app ne 'CODE') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | 152 | my $name = $app; | |||||||||||||||||||||||||||||||||||||||||
| 38 | 152 | ▶ | unless ($name->can('to_app')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | # uncoverable branch false | ||||||||||||||||||||||||||||||||||||||||||
| 40 | 1 | ▶ | eval "require $name" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | or die "Punk::Test: could not load $name: $@"; | ||||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||
| 43 | # uncoverable branch true | ||||||||||||||||||||||||||||||||||||||||||
| 44 | 151 | ▶ | $name->can('to_app') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | or die "Punk::Test: $name has no to_app - not a Punk app?\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 46 | # to_app compiles once per class, and two clients against one app | ||||||||||||||||||||||||||||||||||||||||||
| 47 | # (two browsers, one server) is a thing tests want - so the frozen | ||||||||||||||||||||||||||||||||||||||||||
| 48 | # coderef is shared | ||||||||||||||||||||||||||||||||||||||||||
| 49 | # uncoverable condition false | ||||||||||||||||||||||||||||||||||||||||||
| 50 | 151 | ▶ | $app = $APPS{$name} //= $name->to_app; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/3
$APPS{$name} //= $name->to_app
MC/DC100%0/2
$APPS{$name} //= $name->to_app
$APPS{$name}
$name->to_app
Truth table100%2/3
A //= B
A= $APPS{$name}B= $name->to_app
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||
| 52 | return bless { | ||||||||||||||||||||||||||||||||||||||||||
| 53 | app => $app, | ||||||||||||||||||||||||||||||||||||||||||
| 54 | class => $app_class, | ||||||||||||||||||||||||||||||||||||||||||
| 55 | jar => {}, | ||||||||||||||||||||||||||||||||||||||||||
| 56 | headers => {}, | ||||||||||||||||||||||||||||||||||||||||||
| 57 | timeout => $opts{timeout} // 5, | ||||||||||||||||||||||||||||||||||||||||||
| 58 | max_bytes => $opts{max_bytes} // 1_000_000, | ||||||||||||||||||||||||||||||||||||||||||
| 59 | csrf_cookie => $opts{csrf_cookie} // 'csrf', | ||||||||||||||||||||||||||||||||||||||||||
| 60 | # uncoverable condition left count:2 | ||||||||||||||||||||||||||||||||||||||||||
| 61 | # uncoverable condition left count:3 | ||||||||||||||||||||||||||||||||||||||||||
| 62 | # uncoverable condition left count:4 | ||||||||||||||||||||||||||||||||||||||||||
| 63 | 177 | ▶ | csrf_header => $opts{csrf_header} // 'X-CSRF-Token', | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%5/8
$opts{"timeout"} // 5
$opts{"max_bytes"} // 1000000
$opts{"csrf_cookie"} // "csrf"
$opts{"csrf_header"} // "X-CSRF-Token"
MC/DC100%1/1
$opts{"timeout"} // 5
$opts{"timeout"}
MC/DC100%0/1
$opts{"max_bytes"} // 1000000
$opts{"max_bytes"}
MC/DC100%0/1
$opts{"csrf_cookie"} // "csrf"
$opts{"csrf_cookie"}
MC/DC100%0/1
$opts{"csrf_header"} // "X-CSRF-Token"
$opts{"csrf_header"}
Truth table100%2/2
A
A= $opts{"timeout"}
Truth table100%1/2
A
A= $opts{"max_bytes"}
Truth table100%1/2
A
A= $opts{"csrf_cookie"}
Truth table100%1/2
A
A= $opts{"csrf_header"}
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | res => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 65 | }, $class; | ||||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | # ---- requests ---------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | 415 | ▶ | sub get_ok { my $self = shift; $self->_request_ok('GET', @_) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_ok: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | 140 | ▶ | sub post_ok { my $self = shift; $self->_request_ok('POST', @_) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
post_ok: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | 3 | ▶ | sub put_ok { my $self = shift; $self->_request_ok('PUT', @_) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
put_ok: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | 7 | ▶ | sub patch_ok { my $self = shift; $self->_request_ok('PATCH', @_) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
patch_ok: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | 5 | ▶ | sub delete_ok { my $self = shift; $self->_request_ok('DELETE', @_) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
delete_ok: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | 4 | ▶ | sub head_ok { my $self = shift; $self->_request_ok('HEAD', @_) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
head_ok: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 5 | ▶ | sub options_ok { my $self = shift; $self->_request_ok('OPTIONS', @_) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
options_ok: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | 19 | ▶ | sub request_ok { my $self = shift; $self->_request_ok(@_) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
request_ok: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | # Sign a user straight into the jar - the signed session cookie is minted | ||||||||||||||||||||||||||||||||||||||||||
| 80 | # through the app's own session config, so tests reach guarded pages without | ||||||||||||||||||||||||||||||||||||||||||
| 81 | # driving a login flow first. Takes an id or a user row; needs a client | ||||||||||||||||||||||||||||||||||||||||||
| 82 | # built from a class name (the app object holds the session secret). | ||||||||||||||||||||||||||||||||||||||||||
| 83 | 4 | ▶ | sub login_as { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
login_as: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | 4 | my ($self, $user) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 85 | my $class = $self->{class} | ||||||||||||||||||||||||||||||||||||||||||
| 86 | 4 | ▶ | or die "Punk::Test: login_as needs a client built from a class " | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | . "name, not a coderef\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 88 | 3 | my $app = $class->punk_app; | |||||||||||||||||||||||||||||||||||||||||
| 89 | 3 | ▶ | my $auth = $app->{auth} || {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$app->{'auth'} || {}
MC/DC100%1/1
$app->{'auth'} || {}
$app->{'auth'}
Truth table100%2/2
A
A= $app->{'auth'}
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | 3 | ▶ | my $key = $auth->{session_key} // 'user_id'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$auth->{"session_key"} // "user_id"
MC/DC100%1/1
$auth->{"session_key"} // "user_id"
$auth->{"session_key"}
Truth table100%2/2
A
A= $auth->{"session_key"}
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | 3 | ▶ | my $idf = ($auth->{fields} || {})->{id} // 'id'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%4/4
+($auth->{"fields"} || {})->{"id"} // "id"
$auth->{'fields'} || {}
MC/DC100%1/1
+($auth->{"fields"} || {})->{"id"} // "id"
$auth->{'fields'}
Truth table100%2/2
A
A= $auth->{'fields'}
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | 3 | ▶ | my $id = ref $user eq 'HASH' ? $user->{$idf} : $user; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | # uncoverable branch true | ||||||||||||||||||||||||||||||||||||||||||
| 94 | 3 | ▶ | defined $id or die "Punk::Test: login_as needs a user row or id\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | # _seal_session, not _seal: an application with `session store => ...` | ||||||||||||||||||||||||||||||||||||||||||
| 96 | # keeps the payload server-side, so a cookie with the session sealed into | ||||||||||||||||||||||||||||||||||||||||||
| 97 | # it is no session at all there. This writes it wherever the application | ||||||||||||||||||||||||||||||||||||||||||
| 98 | # will look. | ||||||||||||||||||||||||||||||||||||||||||
| 99 | 3 | my ($name, $value) = Punk::Session::_seal_session($app, { $key => $id }); | |||||||||||||||||||||||||||||||||||||||||
| 100 | 3 | $self->{jar}{$name} = $value; | |||||||||||||||||||||||||||||||||||||||||
| 101 | 3 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | # A header on every request from here on, the way the jar holds a cookie: | ||||||||||||||||||||||||||||||||||||||||||
| 105 | # a credential a client carries, an Accept a whole file's worth of requests | ||||||||||||||||||||||||||||||||||||||||||
| 106 | # needs. undef removes one; no arguments gives back the lot. | ||||||||||||||||||||||||||||||||||||||||||
| 107 | # | ||||||||||||||||||||||||||||||||||||||||||
| 108 | # $t->request_header(Authorization => "Bearer $key"); | ||||||||||||||||||||||||||||||||||||||||||
| 109 | # $t->request_header(Authorization => undef); | ||||||||||||||||||||||||||||||||||||||||||
| 110 | # | ||||||||||||||||||||||||||||||||||||||||||
| 111 | # A request's own `headers` still wins, so one call can be made an exception | ||||||||||||||||||||||||||||||||||||||||||
| 112 | # without unsetting and setting again around it. Named for the request side | ||||||||||||||||||||||||||||||||||||||||||
| 113 | # because `header` is the last response's, and one name for both directions | ||||||||||||||||||||||||||||||||||||||||||
| 114 | # is how a test comes to assert what it just sent. | ||||||||||||||||||||||||||||||||||||||||||
| 115 | 7 | ▶ | sub request_header { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
request_header: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | 7 | my ($self, %h) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 117 | 7 | ▶ | return { %{ $self->{headers} } } unless %h; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | 6 | for my $k (keys %h) { | |||||||||||||||||||||||||||||||||||||||||
| 119 | 7 | ▶ | if (defined $h{$k}) { $self->{headers}{$k} = $h{$k} } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | 1 | else { delete $self->{headers}{$k} } | |||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||
| 122 | 6 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | 184 | ▶ | sub _urlenc { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_urlenc: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | 184 | my ($s) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 127 | # uncoverable branch true | ||||||||||||||||||||||||||||||||||||||||||
| 128 | 184 | ▶ | $s = '' unless defined $s; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 129 | # uncoverable branch true | ||||||||||||||||||||||||||||||||||||||||||
| 130 | 184 | ▶ | utf8::encode($s) if utf8::is_utf8($s); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 131 | 184 | $s =~ s/([^A-Za-z0-9_.~-])/sprintf '%%%02X', ord $1/ge; | |||||||||||||||||||||||||||||||||||||||||
| 132 | 184 | return $s; | |||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||
| 135 | # A path, or [ 'book', id => 1 ] naming a route. | ||||||||||||||||||||||||||||||||||||||||||
| 136 | # | ||||||||||||||||||||||||||||||||||||||||||
| 137 | # This is what turns a wrong route name into a failing test rather than a | ||||||||||||||||||||||||||||||||||||||||||
| 138 | # 404 in production: url_for croaks on a name no route carries, and the | ||||||||||||||||||||||||||||||||||||||||||
| 139 | # croak arrives here, at the request that named it. | ||||||||||||||||||||||||||||||||||||||||||
| 140 | 693 | ▶ | sub _resolve_path { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_resolve_path: called CC=6 SCAR=18.0
| |||||||||||||||||||||||||||||||||||||||||||
| 141 | 693 | my ($self, $path) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 142 | 693 | ▶ | return $path unless ref $path eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 143 | 6 | my ($name, @args) = @$path; | |||||||||||||||||||||||||||||||||||||||||
| 144 | my $class = $self->{class} | ||||||||||||||||||||||||||||||||||||||||||
| 145 | 6 | ▶ | or die "Punk::Test: [ '$name', ... ] names a route, which needs the " | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 146 | . "application class - construct the client with " | ||||||||||||||||||||||||||||||||||||||||||
| 147 | . "Punk::Test->new('MyApp') rather than with a coderef\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 148 | # uncoverable branch false | ||||||||||||||||||||||||||||||||||||||||||
| 149 | 5 | ▶ | my $app = $class->can('punk_app') ? $class->punk_app : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 150 | # uncoverable branch true | ||||||||||||||||||||||||||||||||||||||||||
| 151 | # uncoverable condition left | ||||||||||||||||||||||||||||||||||||||||||
| 152 | # uncoverable condition right | ||||||||||||||||||||||||||||||||||||||||||
| 153 | 5 | ▶ | $app && $app->can('url_for') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%1/3
$app and $app->can("url_for")
MC/DC100%0/2
$app and $app->can("url_for")
$app
$app->can("url_for")
Truth table100%1/3
A and B
A= $appB= $app->can("url_for")
| |||||||||||||||||||||||||||||||||||||||||||
| 154 | or die "Punk::Test: [ '$name', ... ] needs Punk 0.31 or newer\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 155 | 5 | return $app->url_for($name, @args); | |||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||
| 158 | 633 | ▶ | sub _build_env { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_env: called CC=30 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||
| 159 | 633 | my ($self, $method, $path, %o) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 160 | 633 | ▶ | my $query = $o{query} // ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$o{"query"} // ""
MC/DC100%1/1
$o{"query"} // ""
$o{"query"}
Truth table100%2/2
A
A= $o{"query"}
| |||||||||||||||||||||||||||||||||||||||||||
| 161 | 633 | ▶ | ($path, $query) = ($1, $2) if !length $query && $path =~ /\A([^?]*)\?(.*)\z/s; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not length $query and $path =~ /\A([^?]*)\?(.*)\z/s
MC/DC100%2/2
not length $query and $path =~ /\A([^?]*)\?(.*)\z/s
not length $query
$path =~ /\A([^?]*)\?(.*)\z/s
Truth table100%3/3
not(A) and B
A= not length $queryB= $path =~ /\A([^?]*)\?(.*)\z/s
| |||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||
| 163 | 633 | my ($body, $type) = ('', $o{type}); | |||||||||||||||||||||||||||||||||||||||||
| 164 | 633 | my ($in, $clen); | |||||||||||||||||||||||||||||||||||||||||
| 165 | 633 | ▶ | if (exists $o{upload}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 166 | 24 | for my $k (qw(json xml body type)) { | |||||||||||||||||||||||||||||||||||||||||
| 167 | die "Punk::Test: upload and $k do not combine - an upload " | ||||||||||||||||||||||||||||||||||||||||||
| 168 | 90 | ▶ | . "is multipart/form-data\n" if exists $o{$k}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||||||||
| 170 | 20 | ($in, $clen, $type) = $self->_multipart_input($o{form}, $o{upload}); | |||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||
| 172 | elsif (exists $o{json}) { | ||||||||||||||||||||||||||||||||||||||||||
| 173 | 20 | $body = File::Raw::JSON::file_json_encode($o{json}); | |||||||||||||||||||||||||||||||||||||||||
| 174 | # uncoverable condition left | ||||||||||||||||||||||||||||||||||||||||||
| 175 | 20 | ▶ | $type //= 'application/json'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%1/2
$type //= "application/json"
MC/DC100%0/1
$type //= "application/json"
$type
Truth table100%1/2
A
A= $type
| |||||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||
| 177 | elsif (exists $o{xml}) { | ||||||||||||||||||||||||||||||||||||||||||
| 178 | # a Document or Node serialises itself; anything else is markup the | ||||||||||||||||||||||||||||||||||||||||||
| 179 | # caller wrote, including the malformed strings a test wants to send | ||||||||||||||||||||||||||||||||||||||||||
| 180 | 7 | ▶ | $body = ref $o{xml} ? $o{xml}->to_string : $o{xml}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 181 | # uncoverable condition left | ||||||||||||||||||||||||||||||||||||||||||
| 182 | 7 | ▶ | $type //= 'application/xml'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%1/2
$type //= "application/xml"
MC/DC100%0/1
$type //= "application/xml"
$type
Truth table100%1/2
A
A= $type
| |||||||||||||||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||||||||||||
| 184 | elsif (exists $o{form}) { | ||||||||||||||||||||||||||||||||||||||||||
| 185 | 52 | my $f = $o{form}; | |||||||||||||||||||||||||||||||||||||||||
| 186 | 52 | $body = join '&', map { _urlenc($_) . '=' . _urlenc($f->{$_}) } | |||||||||||||||||||||||||||||||||||||||||
| 187 | sort keys %$f; | ||||||||||||||||||||||||||||||||||||||||||
| 188 | # uncoverable condition left | ||||||||||||||||||||||||||||||||||||||||||
| 189 | 52 | ▶ | $type //= 'application/x-www-form-urlencoded'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%1/2
$type //= "application/x-www-form-urlencoded"
MC/DC100%0/1
$type //= "application/x-www-form-urlencoded"
$type
Truth table100%1/2
A
A= $type
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||
| 191 | elsif (defined $o{body}) { | ||||||||||||||||||||||||||||||||||||||||||
| 192 | 16 | $body = $o{body}; | |||||||||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||
| 195 | 627 | ▶ | unless ($in) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 196 | # uncoverable branch true | ||||||||||||||||||||||||||||||||||||||||||
| 197 | 609 | ▶ | open $in, '<', \$body or die "Punk::Test: $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 198 | 609 | ▶ | $clen = length $body if length $body or defined $type; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
length $body or defined $type
MC/DC100%2/2
length $body or defined $type
length $body
defined $type
Truth table100%3/3
A or B
A= length $bodyB= defined $type
| |||||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||
| 200 | 627 | my $env = { | |||||||||||||||||||||||||||||||||||||||||
| 201 | REQUEST_METHOD => $method, | ||||||||||||||||||||||||||||||||||||||||||
| 202 | PATH_INFO => $path, | ||||||||||||||||||||||||||||||||||||||||||
| 203 | QUERY_STRING => $query, | ||||||||||||||||||||||||||||||||||||||||||
| 204 | SERVER_NAME => 'localhost', | ||||||||||||||||||||||||||||||||||||||||||
| 205 | SERVER_PORT => 80, | ||||||||||||||||||||||||||||||||||||||||||
| 206 | SERVER_PROTOCOL => 'HTTP/1.1', | ||||||||||||||||||||||||||||||||||||||||||
| 207 | HTTP_HOST => 'localhost', | ||||||||||||||||||||||||||||||||||||||||||
| 208 | 'psgi.url_scheme' => 'http', | ||||||||||||||||||||||||||||||||||||||||||
| 209 | 'psgi.input' => $in, | ||||||||||||||||||||||||||||||||||||||||||
| 210 | 'psgi.errors' => \*STDERR, | ||||||||||||||||||||||||||||||||||||||||||
| 211 | 'psgi.version' => [ 1, 1 ], | ||||||||||||||||||||||||||||||||||||||||||
| 212 | 'psgi.streaming' => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 213 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 214 | 627 | ▶ | if (defined $clen) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 215 | 113 | $env->{CONTENT_LENGTH} = $clen; | |||||||||||||||||||||||||||||||||||||||||
| 216 | # uncoverable condition right | ||||||||||||||||||||||||||||||||||||||||||
| 217 | 113 | ▶ | $env->{CONTENT_TYPE} = $type // ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%1/2
$type // ""
MC/DC100%0/1
$type // ""
$type
Truth table100%1/2
A
A= $type
| |||||||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||||||
| 219 | # Sticky headers first, so a single request's `headers` can still override | ||||||||||||||||||||||||||||||||||||||||||
| 220 | # one of them - the narrower statement wins, as it does everywhere else. | ||||||||||||||||||||||||||||||||||||||||||
| 221 | 627 | for my $h ($self->{headers}, $o{headers}) { | |||||||||||||||||||||||||||||||||||||||||
| 222 | 1254 | ▶ | next unless $h; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 223 | 800 | for my $k (keys %$h) { | |||||||||||||||||||||||||||||||||||||||||
| 224 | 340 | my $ek = uc $k; | |||||||||||||||||||||||||||||||||||||||||
| 225 | 340 | $ek =~ tr/-/_/; | |||||||||||||||||||||||||||||||||||||||||
| 226 | # uncoverable branch false | ||||||||||||||||||||||||||||||||||||||||||
| 227 | # uncoverable condition left | ||||||||||||||||||||||||||||||||||||||||||
| 228 | # uncoverable condition right | ||||||||||||||||||||||||||||||||||||||||||
| 229 | 340 | ▶ | $ek = "HTTP_$ek" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%1/3
$ek eq "CONTENT_TYPE" or $ek eq "CONTENT_LENGTH"
MC/DC100%0/2
$ek eq "CONTENT_TYPE" or $ek eq "CONTENT_LENGTH"
$ek eq "CONTENT_TYPE"
$ek eq "CONTENT_LENGTH"
Truth table100%1/3
A or B
A= $ek eq "CONTENT_TYPE"B= $ek eq "CONTENT_LENGTH"
| |||||||||||||||||||||||||||||||||||||||||||
| 230 | unless $ek eq 'CONTENT_TYPE' || $ek eq 'CONTENT_LENGTH'; | ||||||||||||||||||||||||||||||||||||||||||
| 231 | 340 | $env->{$ek} = $h->{$k}; | |||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||||||||||||||||
| 234 | 627 | ▶ | if ($o{csrf}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 235 | 11 | my $tok = $self->csrf_token; | |||||||||||||||||||||||||||||||||||||||||
| 236 | 11 | ▶ | if (defined $tok) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 237 | 4 | my $ek = uc $self->{csrf_header}; | |||||||||||||||||||||||||||||||||||||||||
| 238 | 4 | $ek =~ tr/-/_/; | |||||||||||||||||||||||||||||||||||||||||
| 239 | 4 | $env->{"HTTP_$ek"} = $tok; | |||||||||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||||||||
| 241 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 242 | 7 | $TB->diag("csrf => 1, but the jar holds no " | |||||||||||||||||||||||||||||||||||||||||
| 243 | . "'$self->{csrf_cookie}' cookie yet - GET a page first"); | ||||||||||||||||||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||||||||||||||||
| 246 | 627 | ▶ | if (my $jar = $self->_jar_header) { $env->{HTTP_COOKIE} = $jar } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 247 | 627 | ▶ | %$env = (%$env, %{ $o{env} }) if $o{env}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 248 | 627 | return $env; | |||||||||||||||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||
| 251 | # ---- multipart --------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||
| 253 | # The `upload` option: form pairs and upload specs encoded as | ||||||||||||||||||||||||||||||||||||||||||
| 254 | # multipart/form-data. The body is never assembled - the parts become a | ||||||||||||||||||||||||||||||||||||||||||
| 255 | # list of items (header strings whole, file parts read a buffer at a | ||||||||||||||||||||||||||||||||||||||||||
| 256 | # time) drained through psgi.input - so a test of the server's spill | ||||||||||||||||||||||||||||||||||||||||||
| 257 | # path costs this process one read buffer, not the file. | ||||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||
| 259 | 56 | my @_BND = ('0' .. '9', 'A' .. 'Z', 'a' .. 'z'); | |||||||||||||||||||||||||||||||||||||||||
| 260 | 17 | ▶ | sub _mp_boundary { join '', 'PunkTest', map { $_BND[int rand @_BND] } 1 .. 16 } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_mp_boundary: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||
| 262 | # A name or filename into a Content-Disposition quoted-string: quotes and | ||||||||||||||||||||||||||||||||||||||||||
| 263 | # newlines percent-encoded, everything else (UTF-8 included) sent raw, | ||||||||||||||||||||||||||||||||||||||||||
| 264 | # which is RFC 7578 and what browsers do. The server-side parser stores | ||||||||||||||||||||||||||||||||||||||||||
| 265 | # what arrives; it does not decode. | ||||||||||||||||||||||||||||||||||||||||||
| 266 | 53 | ▶ | sub _mp_name { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_mp_name: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 267 | 53 | my ($s) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 268 | # uncoverable branch true | ||||||||||||||||||||||||||||||||||||||||||
| 269 | 53 | ▶ | $s = '' unless defined $s; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 270 | 53 | ▶ | utf8::encode($s) if utf8::is_utf8($s); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 271 | 53 | $s =~ s/(["\r\n])/sprintf '%%%02X', ord $1/ge; | |||||||||||||||||||||||||||||||||||||||||
| 272 | 53 | return $s; | |||||||||||||||||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||
| 275 | # Whether one content source contains the boundary. A file is scanned in | ||||||||||||||||||||||||||||||||||||||||||
| 276 | # chunks with a boundary-length overlap, because the hit this exists to | ||||||||||||||||||||||||||||||||||||||||||
| 277 | # catch is exactly the one that straddles a read. | ||||||||||||||||||||||||||||||||||||||||||
| 278 | 32 | ▶ | sub _mp_contains { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_mp_contains: called CC=6 SCAR=18.0
| |||||||||||||||||||||||||||||||||||||||||||
| 279 | 32 | my ($src, $bnd) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 280 | 32 | ▶ | return index($$src, $bnd) >= 0 if ref $src; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 281 | # uncoverable branch true | ||||||||||||||||||||||||||||||||||||||||||
| 282 | 2 | ▶ | open my $fh, '<:raw', $src or die "Punk::Test: cannot open '$src': $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 283 | 2 | my ($tail, $keep) = ('', length($bnd) - 1); | |||||||||||||||||||||||||||||||||||||||||
| 284 | 2 | ▶ | while (read $fh, my $chunk, 65536) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 285 | 5 | $chunk = $tail . $chunk; | |||||||||||||||||||||||||||||||||||||||||
| 286 | # uncoverable branch true | ||||||||||||||||||||||||||||||||||||||||||
| 287 | 5 | ▶ | return 1 if index($chunk, $bnd) >= 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 288 | 5 | ▶ | $tail = length $chunk > $keep ? substr($chunk, -$keep) : $chunk; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||||||||||||||
| 290 | 2 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||
| 293 | 20 | ▶ | sub _multipart_input { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_multipart_input: called CC=27 SCAR=33.1
| |||||||||||||||||||||||||||||||||||||||||||
| 294 | 20 | my ($self, $form, $upload) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 295 | # uncoverable branch true | ||||||||||||||||||||||||||||||||||||||||||
| 296 | 20 | ▶ | die "Punk::Test: upload takes a hashref of field => arrayref\n" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 297 | unless ref $upload eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||
| 298 | 20 | my (@parts, @scan); | |||||||||||||||||||||||||||||||||||||||||
| 299 | 20 | ▶ | for my $k (sort keys %{ $form || {} }) { | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$form || {}
MC/DC100%1/1
$form || {}
$form
Truth table100%2/2
A
A= $form
| |||||||||||||||||||||||||||||||||||||||||||
| 300 | 9 | my $val = $form->{$k}; | |||||||||||||||||||||||||||||||||||||||||
| 301 | # uncoverable branch true | ||||||||||||||||||||||||||||||||||||||||||
| 302 | 9 | ▶ | $val = '' unless defined $val; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 303 | # uncoverable branch true | ||||||||||||||||||||||||||||||||||||||||||
| 304 | 9 | ▶ | utf8::encode($val) if utf8::is_utf8($val); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 305 | 9 | push @parts, { name => $k, content => $val }; | |||||||||||||||||||||||||||||||||||||||||
| 306 | 9 | push @scan, \$val; | |||||||||||||||||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||||||||||||||||
| 308 | 20 | for my $field (sort keys %$upload) { | |||||||||||||||||||||||||||||||||||||||||
| 309 | 22 | my $v = $upload->{$field}; | |||||||||||||||||||||||||||||||||||||||||
| 310 | # uncoverable condition right | ||||||||||||||||||||||||||||||||||||||||||
| 311 | 22 | ▶ | die "Punk::Test: upload => { $field => ... } takes an arrayref: " | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/3
ref $v eq "ARRAY" and @$v
MC/DC100%1/2
ref $v eq "ARRAY" and @$v
ref $v eq "ARRAY"
@$v
Truth table100%2/3
A and B
A= ref $v eq "ARRAY"B= @$v
| |||||||||||||||||||||||||||||||||||||||||||
| 312 | . "a path or a scalar ref of content, then optional filename " | ||||||||||||||||||||||||||||||||||||||||||
| 313 | . "and type\n" unless ref $v eq 'ARRAY' && @$v; | ||||||||||||||||||||||||||||||||||||||||||
| 314 | 21 | ▶ | for my $spec (ref $v->[0] eq 'ARRAY' ? @$v : $v) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 315 | 23 | my ($src, $fname, $ftype) = @$spec; | |||||||||||||||||||||||||||||||||||||||||
| 316 | 23 | ▶ | my %p = (name => $field, | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$ftype // "application/octet-stream"
MC/DC100%1/1
$ftype // "application/octet-stream"
$ftype
Truth table100%2/2
A
A= $ftype
| |||||||||||||||||||||||||||||||||||||||||||
| 317 | type => $ftype // 'application/octet-stream'); | ||||||||||||||||||||||||||||||||||||||||||
| 318 | 23 | ▶ | if (ref $src eq 'SCALAR') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 319 | # uncoverable condition right | ||||||||||||||||||||||||||||||||||||||||||
| 320 | 20 | ▶ | my $bytes = $$src // ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%1/2
$$src // ""
MC/DC100%0/1
$$src // ""
$$src
Truth table100%1/2
A
A= $$src
| |||||||||||||||||||||||||||||||||||||||||||
| 321 | # uncoverable branch true | ||||||||||||||||||||||||||||||||||||||||||
| 322 | 20 | ▶ | utf8::encode($bytes) if utf8::is_utf8($bytes); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 323 | 20 | $p{content} = $bytes; | |||||||||||||||||||||||||||||||||||||||||
| 324 | # uncoverable condition false | ||||||||||||||||||||||||||||||||||||||||||
| 325 | 20 | ▶ | $p{filename} = $fname // $field; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/3
$fname // $field
MC/DC100%0/2
$fname // $field
$fname
$field
Truth table100%2/3
A // B
A= $fnameB= $field
| |||||||||||||||||||||||||||||||||||||||||||
| 326 | 20 | push @scan, \$bytes; | |||||||||||||||||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||||||||||||||||
| 328 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 329 | # uncoverable condition right count:1 | ||||||||||||||||||||||||||||||||||||||||||
| 330 | # uncoverable condition left count:2 | ||||||||||||||||||||||||||||||||||||||||||
| 331 | 3 | ▶ | die "Punk::Test: upload => { $field => ... }: no file at '" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition20%3/5
defined $src and -f $src
$src // ""
MC/DC50%1/2
defined $src and -f $src
defined $src
-f $src
MC/DC100%0/1
$src // ""
$src
Truth table33%2/3
A and B
A= defined $srcB= -f $src
Truth table0%1/2
A
A= $src
| |||||||||||||||||||||||||||||||||||||||||||
| 332 | . ($src // '') . "'\n" unless defined $src && -f $src; | ||||||||||||||||||||||||||||||||||||||||||
| 333 | 2 | $p{path} = $src; | |||||||||||||||||||||||||||||||||||||||||
| 334 | 2 | $p{size} = -s $src; | |||||||||||||||||||||||||||||||||||||||||
| 335 | # uncoverable condition false | ||||||||||||||||||||||||||||||||||||||||||
| 336 | 2 | ▶ | $p{filename} = $fname // ($src =~ m{([^/\\]+)\z})[0]; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/3
$fname // ($src =~ m(([^/\\]+)\z))[0]
MC/DC100%0/2
$fname // ($src =~ m(([^/\\]+)\z))[0]
$fname
($src =~ m(([^/\\]+)\z))[0]
Truth table100%2/3
A // B
A= $fnameB= ($src =~ m(([^/\\]+)\z))[0]
| |||||||||||||||||||||||||||||||||||||||||||
| 337 | 2 | push @scan, $src; | |||||||||||||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||||||||||||||
| 339 | 22 | push @parts, \%p; | |||||||||||||||||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||
| 343 | # The boundary must not appear in any part. Verified, not hoped: | ||||||||||||||||||||||||||||||||||||||||||
| 344 | # scanning also proves every named file readable before the request | ||||||||||||||||||||||||||||||||||||||||||
| 345 | # starts, so a bad path fails here and not as a truncated body. | ||||||||||||||||||||||||||||||||||||||||||
| 346 | 18 | my $bnd = _mp_boundary(); | |||||||||||||||||||||||||||||||||||||||||
| 347 | 18 | ▶ | for (my $tries = 1; grep { _mp_contains($_, $bnd) } @scan; $tries++) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 348 | # uncoverable branch true | ||||||||||||||||||||||||||||||||||||||||||
| 349 | 1 | ▶ | die "Punk::Test: could not pick a boundary absent from the " | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 350 | . "content\n" if $tries >= 16; | ||||||||||||||||||||||||||||||||||||||||||
| 351 | 1 | $bnd = _mp_boundary(); | |||||||||||||||||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||
| 354 | 18 | my ($len, @items) = (0); | |||||||||||||||||||||||||||||||||||||||||
| 355 | 18 | for my $p (@parts) { | |||||||||||||||||||||||||||||||||||||||||
| 356 | my $hdr = "--$bnd\r\nContent-Disposition: form-data; name=\"" | ||||||||||||||||||||||||||||||||||||||||||
| 357 | 31 | . _mp_name($p->{name}) . '"'; | |||||||||||||||||||||||||||||||||||||||||
| 358 | 31 | ▶ | if (exists $p->{filename}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 359 | 22 | $hdr .= '; filename="' . _mp_name($p->{filename}) . '"' | |||||||||||||||||||||||||||||||||||||||||
| 360 | . "\r\nContent-Type: $p->{type}"; | ||||||||||||||||||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||||||||||||||||
| 362 | 31 | $hdr .= "\r\n\r\n"; | |||||||||||||||||||||||||||||||||||||||||
| 363 | 31 | ▶ | if (defined $p->{path}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 364 | open my $fh, '<:raw', $p->{path} | ||||||||||||||||||||||||||||||||||||||||||
| 365 | # uncoverable branch true | ||||||||||||||||||||||||||||||||||||||||||
| 366 | 2 | ▶ | or die "Punk::Test: cannot open '$p->{path}': $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 367 | 2 | push @items, $hdr, { fh => $fh }; | |||||||||||||||||||||||||||||||||||||||||
| 368 | 2 | $len += $p->{size}; | |||||||||||||||||||||||||||||||||||||||||
| 369 | } | ||||||||||||||||||||||||||||||||||||||||||
| 370 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 371 | 29 | push @items, $hdr, $p->{content}; | |||||||||||||||||||||||||||||||||||||||||
| 372 | 29 | $len += length $p->{content}; | |||||||||||||||||||||||||||||||||||||||||
| 373 | } | ||||||||||||||||||||||||||||||||||||||||||
| 374 | 31 | push @items, "\r\n"; | |||||||||||||||||||||||||||||||||||||||||
| 375 | 31 | $len += length($hdr) + 2; | |||||||||||||||||||||||||||||||||||||||||
| 376 | } | ||||||||||||||||||||||||||||||||||||||||||
| 377 | 18 | push @items, "--$bnd--\r\n"; | |||||||||||||||||||||||||||||||||||||||||
| 378 | 18 | $len += length $items[-1]; | |||||||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||||||
| 380 | 18 | push @Punk::Test::_MPInput::QUEUE, \@items; | |||||||||||||||||||||||||||||||||||||||||
| 381 | # uncoverable branch true | ||||||||||||||||||||||||||||||||||||||||||
| 382 | 18 | ▶ | open my $in, '<:via(Punk::Test::_MPInput)', \(my $empty = '') | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.4
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 383 | or die "Punk::Test: $!"; | ||||||||||||||||||||||||||||||||||||||||||
| 384 | 18 | return ($in, $len, "multipart/form-data; boundary=$bnd"); | |||||||||||||||||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||
| 387 | 598 | ▶ | sub _request_ok { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_request_ok: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||
| 388 | 598 | my ($self, $method, $path, %o) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 389 | 598 | local $Test::Builder::Level = $Test::Builder::Level + 2; | |||||||||||||||||||||||||||||||||||||||||
| 390 | 598 | $path = $self->_resolve_path($path); | |||||||||||||||||||||||||||||||||||||||||
| 391 | 595 | my $env = $self->_build_env($method, $path, %o); | |||||||||||||||||||||||||||||||||||||||||
| 392 | 589 | my $r = eval { $self->{app}->($env) }; | |||||||||||||||||||||||||||||||||||||||||
| 393 | 589 | my $err = $@; | |||||||||||||||||||||||||||||||||||||||||
| 394 | 589 | ▶ | if (ref $r eq 'CODE') { # a psgi.streaming response | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 395 | 20 | $r = eval { $self->_drive_streaming($r) }; | |||||||||||||||||||||||||||||||||||||||||
| 396 | # uncoverable condition left | ||||||||||||||||||||||||||||||||||||||||||
| 397 | # uncoverable condition right | ||||||||||||||||||||||||||||||||||||||||||
| 398 | 20 | ▶ | $err ||= $@; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%1/3
$err ||= $@
MC/DC100%0/2
$err ||= $@
$err
$@
Truth table100%1/3
A ||= B
A= $errB= $@
| |||||||||||||||||||||||||||||||||||||||||||
| 399 | } | ||||||||||||||||||||||||||||||||||||||||||
| 400 | 589 | ▶ | if (ref $r eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 401 | 583 | $self->_set_response($r); | |||||||||||||||||||||||||||||||||||||||||
| 402 | # uncoverable condition false | ||||||||||||||||||||||||||||||||||||||||||
| 403 | 583 | ▶ | $TB->ok(1, $o{name} // "$method $path"); | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$o{"name"} // "$method $path"
MC/DC100%1/1
$o{"name"} // "$method $path"
$o{"name"}
Truth table100%2/2
A
A= $o{"name"}
| |||||||||||||||||||||||||||||||||||||||||||
| 404 | } | ||||||||||||||||||||||||||||||||||||||||||
| 405 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 406 | 6 | $self->{res} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 407 | # uncoverable condition left | ||||||||||||||||||||||||||||||||||||||||||
| 408 | # uncoverable condition false | ||||||||||||||||||||||||||||||||||||||||||
| 409 | 6 | ▶ | $TB->ok(0, $o{name} // "$method $path"); | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%1/2
$o{"name"} // "$method $path"
MC/DC100%0/1
$o{"name"} // "$method $path"
$o{"name"}
Truth table100%1/2
A
A= $o{"name"}
| |||||||||||||||||||||||||||||||||||||||||||
| 410 | 6 | ▶ | $TB->diag($err ? "the application died: $err" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 411 | : 'the application did not return a PSGI response'); | ||||||||||||||||||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||||||||||||||||
| 413 | 589 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 414 | } | ||||||||||||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||||||||||||
| 416 | # Drive a delayed-response coderef to completion, collecting the writes. | ||||||||||||||||||||||||||||||||||||||||||
| 417 | 49 | ▶ | sub _drive_streaming { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_drive_streaming: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 418 | 49 | my ($self, $code) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 419 | 49 | my ($status, $headers, @writes, $closed); | |||||||||||||||||||||||||||||||||||||||||
| 420 | 49 | my $max = $self->{max_bytes}; | |||||||||||||||||||||||||||||||||||||||||
| 421 | 49 | my $got = 0; | |||||||||||||||||||||||||||||||||||||||||
| 422 | 103 | ▶ | my $writer = Punk::Test::_Writer->new(sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 423 | 103 | $got += length $_[0]; | |||||||||||||||||||||||||||||||||||||||||
| 424 | # uncoverable branch true | ||||||||||||||||||||||||||||||||||||||||||
| 425 | 103 | ▶ | die "Punk::Test: stream exceeded $max bytes without closing\n" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 426 | if $got > $max; | ||||||||||||||||||||||||||||||||||||||||||
| 427 | 103 | push @writes, $_[0]; | |||||||||||||||||||||||||||||||||||||||||
| 428 | 49 | }, \$closed); | |||||||||||||||||||||||||||||||||||||||||
| 429 | 49 | ▶ | my $ret = $code->(sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 430 | 49 | my ($triplet) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 431 | 49 | ($status, $headers) = @$triplet[0, 1]; | |||||||||||||||||||||||||||||||||||||||||
| 432 | 49 | ▶ | return $writer if @$triplet < 3; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 433 | 7 | push @writes, @{ $triplet->[2] }; | |||||||||||||||||||||||||||||||||||||||||
| 434 | 7 | $closed = 1; | |||||||||||||||||||||||||||||||||||||||||
| 435 | 7 | return; | |||||||||||||||||||||||||||||||||||||||||
| 436 | 49 | }); | |||||||||||||||||||||||||||||||||||||||||
| 437 | # uncoverable condition right | ||||||||||||||||||||||||||||||||||||||||||
| 438 | 49 | ▶ | return [ $status, $headers // [], [ join '', @writes ] ]; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%1/2
$headers // []
MC/DC100%0/1
$headers // []
$headers
Truth table100%1/2
A
A= $headers
| |||||||||||||||||||||||||||||||||||||||||||
| 439 | } | ||||||||||||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||||||||||||
| 441 | 615 | ▶ | sub _set_response { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_set_response: called CC=12 SCAR=24.9
| |||||||||||||||||||||||||||||||||||||||||||
| 442 | 615 | my ($self, $r) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 443 | 615 | my $body = $r->[2]; | |||||||||||||||||||||||||||||||||||||||||
| 444 | # uncoverable condition right | ||||||||||||||||||||||||||||||||||||||||||
| 445 | 615 | ▶ | if (ref $body eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 446 | 590 | $body = join '', grep { defined } @$body; | |||||||||||||||||||||||||||||||||||||||||
| 447 | } | ||||||||||||||||||||||||||||||||||||||||||
| 448 | ▶ | elsif (Scalar::Util::blessed($body) && $body->can('getline')) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
builtin::blessed($body) and $body->can("getline")
MC/DC50%1/2
builtin::blessed($body) and $body->can("getline")
builtin::blessed($body)
$body->can("getline")
Truth table66%2/3
A and B
A= builtin::blessed($body)B= $body->can("getline")
| |||||||||||||||||||||||||||||||||||||||||||
| 449 | 8 | my @chunks; # a PSGI body object (send_file) | |||||||||||||||||||||||||||||||||||||||||
| 450 | 8 | ▶ | while (defined(my $chunk = $body->getline)) { push @chunks, $chunk } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 451 | 8 | eval { $body->close }; | |||||||||||||||||||||||||||||||||||||||||
| 452 | 8 | $body = join '', @chunks; | |||||||||||||||||||||||||||||||||||||||||
| 453 | } | ||||||||||||||||||||||||||||||||||||||||||
| 454 | else { # a filehandle (Punk::Static) | ||||||||||||||||||||||||||||||||||||||||||
| 455 | 17 | local $/; | |||||||||||||||||||||||||||||||||||||||||
| 456 | 17 | my $fh = $body; | |||||||||||||||||||||||||||||||||||||||||
| 457 | # uncoverable condition right | ||||||||||||||||||||||||||||||||||||||||||
| 458 | 17 | ▶ | $body = <$fh> // ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%1/2
readline $fh // ""
MC/DC100%0/1
readline $fh // ""
readline $fh
Truth table100%1/2
A
A= readline $fh
| |||||||||||||||||||||||||||||||||||||||||||
| 459 | 17 | eval { $fh->close }; | |||||||||||||||||||||||||||||||||||||||||
| 460 | } | ||||||||||||||||||||||||||||||||||||||||||
| 461 | 615 | $self->{res} = { status => $r->[0], headers => $r->[1], body => $body }; | |||||||||||||||||||||||||||||||||||||||||
| 462 | 615 | delete $self->{$_} for qw(json xml); | |||||||||||||||||||||||||||||||||||||||||
| 463 | 615 | my @h = @{ $r->[1] }; | |||||||||||||||||||||||||||||||||||||||||
| 464 | 615 | ▶ | while (my ($k, $v) = splice @h, 0, 2) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 465 | 1541 | ▶ | next unless lc $k eq 'set-cookie'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 466 | # uncoverable branch true | ||||||||||||||||||||||||||||||||||||||||||
| 467 | 88 | ▶ | my ($name, $value) = $v =~ /\A\s*([^=;\s]+)=([^;]*)/ or next; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 468 | # uncoverable condition right | ||||||||||||||||||||||||||||||||||||||||||
| 469 | 88 | ▶ | if ($value eq '' || $v =~ /;\s*Max-Age\s*=\s*0\s*(?:;|\z)/i) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/3
$value eq "" or $v =~ /;\s*Max-Age\s*=\s*0\s*(?:;|\z)/i
MC/DC100%1/2
$value eq "" or $v =~ /;\s*Max-Age\s*=\s*0\s*(?:;|\z)/i
$value eq ""
$v =~ /;\s*Max-Age\s*=\s*0\s*(?:;|\z)/i
Truth table100%2/3
A or B
A= $value eq ""B= $v =~ /;\s*Max-Age\s*=\s*0\s*(?:;|\z)/i
| |||||||||||||||||||||||||||||||||||||||||||
| 470 | 3 | delete $self->{jar}{$name}; | |||||||||||||||||||||||||||||||||||||||||
| 471 | } | ||||||||||||||||||||||||||||||||||||||||||
| 472 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 473 | 85 | $self->{jar}{$name} = $value; | |||||||||||||||||||||||||||||||||||||||||
| 474 | } | ||||||||||||||||||||||||||||||||||||||||||
| 475 | } | ||||||||||||||||||||||||||||||||||||||||||
| 476 | 615 | return; | |||||||||||||||||||||||||||||||||||||||||
| 477 | } | ||||||||||||||||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||||||||||||||||
| 479 | 684 | ▶ | sub _jar_header { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_jar_header: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 480 | 684 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 481 | 684 | my $jar = $self->{jar}; | |||||||||||||||||||||||||||||||||||||||||
| 482 | 684 | ▶ | return unless %$jar; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 483 | 118 | return join '; ', map { "$_=$jar->{$_}" } sort keys %$jar; | |||||||||||||||||||||||||||||||||||||||||
| 484 | } | ||||||||||||||||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||||||||||||||||
| 486 | # ---- the response ------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||||||||||||||||
| 488 | # uncoverable branch false | ||||||||||||||||||||||||||||||||||||||||||
| 489 | 5 | ▶ | sub status { $_[0]{res} ? $_[0]{res}{status} : undef } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
status: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 490 | # uncoverable branch false | ||||||||||||||||||||||||||||||||||||||||||
| 491 | 26 | ▶ | sub body { $_[0]{res} ? $_[0]{res}{body} : undef } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
body: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||||||||||||||||
| 493 | 167 | ▶ | sub header { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
header: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 494 | 167 | my ($self, $name) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 495 | # uncoverable branch true | ||||||||||||||||||||||||||||||||||||||||||
| 496 | 167 | ▶ | return unless $self->{res}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 497 | 167 | my @h = @{ $self->{res}{headers} }; | |||||||||||||||||||||||||||||||||||||||||
| 498 | 167 | ▶ | while (my ($k, $v) = splice @h, 0, 2) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 499 | 365 | ▶ | return $v if lc $k eq lc $name; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 500 | } | ||||||||||||||||||||||||||||||||||||||||||
| 501 | 17 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 502 | } | ||||||||||||||||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||||||||||||||||
| 504 | 164 | ▶ | sub json { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
json: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 505 | 164 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 506 | # uncoverable branch true | ||||||||||||||||||||||||||||||||||||||||||
| 507 | 164 | ▶ | return unless $self->{res}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 508 | 164 | ▶ | return $self->{json} //= eval { File::Raw::JSON::file_json_decode($self->{res}{body}) }; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$self->{"json"} //= eval {
do {
File::Raw::JSON::file_json_decode($self->{"res"}{"body"})
}
}
MC/DC100%2/2
$self->{"json"} //= eval {
do {
File::Raw::JSON::file_json_decode($self->{"res"}{"body"})
}
}
$self->{"json"}
eval {
do {
File::Raw::JSON::file_json_decode($self->{"res"}{"body"})
}
}
Truth table100%3/3
A //= B
A= $self->{"json"}B= eval {
do {
File::Raw::JSON::file_json_decode($self->{"res"}{"body"})
}
}
| |||||||||||||||||||||||||||||||||||||||||||
| 509 | } | ||||||||||||||||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||||||||||||||||
| 511 | 8 | ▶ | sub xml { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xml: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 512 | 8 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 513 | # uncoverable branch true | ||||||||||||||||||||||||||||||||||||||||||
| 514 | 8 | ▶ | return unless $self->{res}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 515 | 8 | ▶ | return $self->{xml} //= eval { | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$self->{"xml"} //= eval {
do {
File::Raw::XML::file_xml_decode($self->{"res"}{"body"})
}
}
MC/DC100%2/2
$self->{"xml"} //= eval {
do {
File::Raw::XML::file_xml_decode($self->{"res"}{"body"})
}
}
$self->{"xml"}
eval {
do {
File::Raw::XML::file_xml_decode($self->{"res"}{"body"})
}
}
Truth table100%3/3
A //= B
A= $self->{"xml"}B= eval {
do {
File::Raw::XML::file_xml_decode($self->{"res"}{"body"})
}
}
| |||||||||||||||||||||||||||||||||||||||||||
| 516 | 5 | File::Raw::XML::file_xml_decode($self->{res}{body}); | |||||||||||||||||||||||||||||||||||||||||
| 517 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 518 | } | ||||||||||||||||||||||||||||||||||||||||||
| 519 | |||||||||||||||||||||||||||||||||||||||||||
| 520 | 5 | ▶ | sub cookie { $_[0]{jar}{ $_[1] } } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cookie: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||||||||||||||||
| 522 | 13 | ▶ | sub csrf_token { $_[0]{jar}{ $_[0]{csrf_cookie} } } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
csrf_token: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 523 | |||||||||||||||||||||||||||||||||||||||||||
| 524 | 3 | ▶ | sub reset_session { %{ $_[0]{jar} } = (); $_[0] } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
reset_session: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||||||||||||||||
| 526 | # ---- assertions -------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||||||||||||||||
| 528 | 3 | ▶ | sub _no_response { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_no_response: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 529 | 3 | my ($self, $name) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 530 | 3 | local $Test::Builder::Level = $Test::Builder::Level + 1; | |||||||||||||||||||||||||||||||||||||||||
| 531 | 3 | $TB->ok(0, $name); | |||||||||||||||||||||||||||||||||||||||||
| 532 | 3 | $TB->diag('no response - did the last *_ok request fail?'); | |||||||||||||||||||||||||||||||||||||||||
| 533 | 3 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 534 | } | ||||||||||||||||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||||||||||||||||
| 536 | 413 | ▶ | sub status_is { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
status_is: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 537 | 413 | my ($self, $want, $name) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 538 | 413 | local $Test::Builder::Level = $Test::Builder::Level + 1; | |||||||||||||||||||||||||||||||||||||||||
| 539 | # uncoverable condition false | ||||||||||||||||||||||||||||||||||||||||||
| 540 | 413 | ▶ | $name //= "status is $want"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$name //= "status is $want"
MC/DC100%1/1
$name //= "status is $want"
$name
Truth table100%2/2
A
A= $name
| |||||||||||||||||||||||||||||||||||||||||||
| 541 | 413 | ▶ | return $self->_no_response($name) unless $self->{res}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 542 | 410 | ▶ | $TB->is_num($self->{res}{status}, $want, $name) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 543 | or $TB->diag('body: ' . $self->_body_head); | ||||||||||||||||||||||||||||||||||||||||||
| 544 | 410 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 545 | } | ||||||||||||||||||||||||||||||||||||||||||
| 546 | |||||||||||||||||||||||||||||||||||||||||||
| 547 | 10 | ▶ | sub status_isnt { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
status_isnt: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 548 | 10 | my ($self, $want, $name) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 549 | 10 | local $Test::Builder::Level = $Test::Builder::Level + 1; | |||||||||||||||||||||||||||||||||||||||||
| 550 | # uncoverable condition false | ||||||||||||||||||||||||||||||||||||||||||
| 551 | 10 | ▶ | $name //= "status is not $want"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$name //= "status is not $want"
MC/DC100%1/1
$name //= "status is not $want"
$name
Truth table100%2/2
A
A= $name
| |||||||||||||||||||||||||||||||||||||||||||
| 552 | # uncoverable branch true | ||||||||||||||||||||||||||||||||||||||||||
| 553 | 10 | ▶ | return $self->_no_response($name) unless $self->{res}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 554 | 10 | $TB->isnt_num($self->{res}{status}, $want, $name); | |||||||||||||||||||||||||||||||||||||||||
| 555 | 10 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 556 | } | ||||||||||||||||||||||||||||||||||||||||||
| 557 | |||||||||||||||||||||||||||||||||||||||||||
| 558 | 84 | ▶ | sub header_is { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
header_is: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 559 | 84 | my ($self, $h, $want, $name) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 560 | 84 | local $Test::Builder::Level = $Test::Builder::Level + 1; | |||||||||||||||||||||||||||||||||||||||||
| 561 | # uncoverable condition false | ||||||||||||||||||||||||||||||||||||||||||
| 562 | 84 | ▶ | $name //= "$h header is " . (defined $want ? "'$want'" : 'undef'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$name //= "$h header is " . (defined $want ? "'${want}'" : "undef")
MC/DC100%1/1
$name //= "$h header is " . (defined $want ? "'${want}'" : "undef")
$name
Truth table100%2/2
A
A= $name
| |||||||||||||||||||||||||||||||||||||||||||
| 563 | # uncoverable branch true | ||||||||||||||||||||||||||||||||||||||||||
| 564 | 84 | ▶ | return $self->_no_response($name) unless $self->{res}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 565 | 84 | $TB->is_eq($self->header($h), $want, $name); | |||||||||||||||||||||||||||||||||||||||||
| 566 | 84 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 567 | } | ||||||||||||||||||||||||||||||||||||||||||
| 568 | |||||||||||||||||||||||||||||||||||||||||||
| 569 | 10 | ▶ | sub header_like { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
header_like: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 570 | 10 | my ($self, $h, $re, $name) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 571 | 10 | local $Test::Builder::Level = $Test::Builder::Level + 1; | |||||||||||||||||||||||||||||||||||||||||
| 572 | # uncoverable condition false | ||||||||||||||||||||||||||||||||||||||||||
| 573 | 10 | ▶ | $name //= "$h header matches"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$name //= "$h header matches"
MC/DC100%1/1
$name //= "$h header matches"
$name
Truth table100%2/2
A
A= $name
| |||||||||||||||||||||||||||||||||||||||||||
| 574 | # uncoverable branch true | ||||||||||||||||||||||||||||||||||||||||||
| 575 | 10 | ▶ | return $self->_no_response($name) unless $self->{res}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 576 | # uncoverable condition right | ||||||||||||||||||||||||||||||||||||||||||
| 577 | 10 | ▶ | $TB->like($self->header($h) // '', $re, $name); | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%1/2
$self->header($h) // ""
MC/DC100%0/1
$self->header($h) // ""
$self->header($h)
Truth table100%1/2
A
A= $self->header($h)
| |||||||||||||||||||||||||||||||||||||||||||
| 578 | 10 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 579 | } | ||||||||||||||||||||||||||||||||||||||||||
| 580 | |||||||||||||||||||||||||||||||||||||||||||
| 581 | 1 | ▶ | sub header_exists { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
header_exists: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 582 | 1 | my ($self, $h, $name) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 583 | 1 | local $Test::Builder::Level = $Test::Builder::Level + 1; | |||||||||||||||||||||||||||||||||||||||||
| 584 | # uncoverable condition left | ||||||||||||||||||||||||||||||||||||||||||
| 585 | # uncoverable condition false | ||||||||||||||||||||||||||||||||||||||||||
| 586 | 1 | ▶ | $name //= "$h header exists"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%1/2
$name //= "$h header exists"
MC/DC100%0/1
$name //= "$h header exists"
$name
Truth table100%1/2
A
A= $name
| |||||||||||||||||||||||||||||||||||||||||||
| 587 | # uncoverable branch true | ||||||||||||||||||||||||||||||||||||||||||
| 588 | 1 | ▶ | return $self->_no_response($name) unless $self->{res}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 589 | 1 | $TB->ok(defined $self->header($h), $name); | |||||||||||||||||||||||||||||||||||||||||
| 590 | 1 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 591 | } | ||||||||||||||||||||||||||||||||||||||||||
| 592 | |||||||||||||||||||||||||||||||||||||||||||
| 593 | 115 | ▶ | sub content_is { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
content_is: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 594 | 115 | my ($self, $want, $name) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 595 | 115 | local $Test::Builder::Level = $Test::Builder::Level + 1; | |||||||||||||||||||||||||||||||||||||||||
| 596 | 115 | ▶ | $name //= 'exact body'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$name //= "exact body"
MC/DC100%1/1
$name //= "exact body"
$name
Truth table100%2/2
A
A= $name
| |||||||||||||||||||||||||||||||||||||||||||
| 597 | # uncoverable branch true | ||||||||||||||||||||||||||||||||||||||||||
| 598 | 115 | ▶ | return $self->_no_response($name) unless $self->{res}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 599 | 115 | $TB->is_eq($self->{res}{body}, $want, $name); | |||||||||||||||||||||||||||||||||||||||||
| 600 | 115 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 601 | } | ||||||||||||||||||||||||||||||||||||||||||
| 602 | |||||||||||||||||||||||||||||||||||||||||||
| 603 | 43 | ▶ | sub content_like { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
content_like: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 604 | 43 | my ($self, $re, $name) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 605 | 43 | local $Test::Builder::Level = $Test::Builder::Level + 1; | |||||||||||||||||||||||||||||||||||||||||
| 606 | 43 | ▶ | $name //= 'body matches'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$name //= "body matches"
MC/DC100%1/1
$name //= "body matches"
$name
Truth table100%2/2
A
A= $name
| |||||||||||||||||||||||||||||||||||||||||||
| 607 | # uncoverable branch true | ||||||||||||||||||||||||||||||||||||||||||
| 608 | 43 | ▶ | return $self->_no_response($name) unless $self->{res}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 609 | 43 | $TB->like($self->{res}{body}, $re, $name); | |||||||||||||||||||||||||||||||||||||||||
| 610 | 43 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 611 | } | ||||||||||||||||||||||||||||||||||||||||||
| 612 | |||||||||||||||||||||||||||||||||||||||||||
| 613 | 8 | ▶ | sub content_unlike { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
content_unlike: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 614 | 8 | my ($self, $re, $name) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 615 | 8 | local $Test::Builder::Level = $Test::Builder::Level + 1; | |||||||||||||||||||||||||||||||||||||||||
| 616 | 8 | ▶ | $name //= 'body does not match'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$name //= "body does not match"
MC/DC100%1/1
$name //= "body does not match"
$name
Truth table100%2/2
A
A= $name
| |||||||||||||||||||||||||||||||||||||||||||
| 617 | # uncoverable branch true | ||||||||||||||||||||||||||||||||||||||||||
| 618 | 8 | ▶ | return $self->_no_response($name) unless $self->{res}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 619 | 8 | $TB->unlike($self->{res}{body}, $re, $name); | |||||||||||||||||||||||||||||||||||||||||
| 620 | 8 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 621 | } | ||||||||||||||||||||||||||||||||||||||||||
| 622 | |||||||||||||||||||||||||||||||||||||||||||
| 623 | # RFC 6901: '' is the whole document, '/a/0/b' walks in. Returns | ||||||||||||||||||||||||||||||||||||||||||
| 624 | # (found, value). | ||||||||||||||||||||||||||||||||||||||||||
| 625 | 182 | ▶ | sub _ptr_get { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ptr_get: called CC=10 SCAR=23.0
| |||||||||||||||||||||||||||||||||||||||||||
| 626 | 182 | my ($doc, $ptr) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 627 | # uncoverable condition left | ||||||||||||||||||||||||||||||||||||||||||
| 628 | 182 | ▶ | return (1, $doc) if !defined $ptr || $ptr eq ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/3
not defined $ptr or $ptr eq ""
MC/DC100%1/2
not defined $ptr or $ptr eq ""
not defined $ptr
$ptr eq ""
Truth table100%2/3
not(A) or B
A= not defined $ptrB= $ptr eq ""
| |||||||||||||||||||||||||||||||||||||||||||
| 629 | # uncoverable branch true | ||||||||||||||||||||||||||||||||||||||||||
| 630 | 180 | ▶ | return (0, undef) unless $ptr =~ s{\A/}{}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 631 | 180 | for my $tok (split m{/}, $ptr, -1) { | |||||||||||||||||||||||||||||||||||||||||
| 632 | 269 | $tok =~ s/~1/\//g; | |||||||||||||||||||||||||||||||||||||||||
| 633 | 269 | $tok =~ s/~0/~/g; | |||||||||||||||||||||||||||||||||||||||||
| 634 | 269 | ▶ | if (ref $doc eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 635 | 236 | ▶ | return (0, undef) unless exists $doc->{$tok}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 636 | 230 | $doc = $doc->{$tok}; | |||||||||||||||||||||||||||||||||||||||||
| 637 | } | ||||||||||||||||||||||||||||||||||||||||||
| 638 | elsif (ref $doc eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||
| 639 | # uncoverable branch true | ||||||||||||||||||||||||||||||||||||||||||
| 640 | # uncoverable condition left | ||||||||||||||||||||||||||||||||||||||||||
| 641 | # uncoverable condition right | ||||||||||||||||||||||||||||||||||||||||||
| 642 | 30 | ▶ | return (0, undef) unless $tok =~ /\A\d+\z/ && $tok <= $#$doc; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%1/3
$tok =~ /\A\d+\z/ and $tok <= $doc->$#*
MC/DC100%0/2
$tok =~ /\A\d+\z/ and $tok <= $doc->$#*
$tok =~ /\A\d+\z/
$tok <= $doc->$#*
Truth table100%1/3
A and B
A= $tok =~ /\A\d+\z/B= $tok <= $doc->$#*
| |||||||||||||||||||||||||||||||||||||||||||
| 643 | 30 | $doc = $doc->[$tok]; | |||||||||||||||||||||||||||||||||||||||||
| 644 | } | ||||||||||||||||||||||||||||||||||||||||||
| 645 | 3 | else { return (0, undef) } | |||||||||||||||||||||||||||||||||||||||||
| 646 | } | ||||||||||||||||||||||||||||||||||||||||||
| 647 | 171 | return (1, $doc); | |||||||||||||||||||||||||||||||||||||||||
| 648 | } | ||||||||||||||||||||||||||||||||||||||||||
| 649 | |||||||||||||||||||||||||||||||||||||||||||
| 650 | 144 | ▶ | sub _json_at { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_json_at: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 651 | 144 | my ($self, $ptr, $name) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 652 | 144 | local $Test::Builder::Level = $Test::Builder::Level + 1; | |||||||||||||||||||||||||||||||||||||||||
| 653 | 144 | my $doc = $self->json; | |||||||||||||||||||||||||||||||||||||||||
| 654 | 144 | ▶ | unless (defined $doc) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 655 | 3 | $TB->ok(0, $name); | |||||||||||||||||||||||||||||||||||||||||
| 656 | 3 | $TB->diag('the body did not decode as JSON: ' . $self->_body_head); | |||||||||||||||||||||||||||||||||||||||||
| 657 | 3 | return; | |||||||||||||||||||||||||||||||||||||||||
| 658 | } | ||||||||||||||||||||||||||||||||||||||||||
| 659 | 141 | my ($found, $got) = _ptr_get($doc, $ptr); | |||||||||||||||||||||||||||||||||||||||||
| 660 | 141 | ▶ | unless ($found) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 661 | 6 | $TB->ok(0, $name); | |||||||||||||||||||||||||||||||||||||||||
| 662 | 6 | $TB->diag("nothing at JSON pointer '$ptr' in " . $self->_body_head); | |||||||||||||||||||||||||||||||||||||||||
| 663 | 6 | return; | |||||||||||||||||||||||||||||||||||||||||
| 664 | } | ||||||||||||||||||||||||||||||||||||||||||
| 665 | 135 | return \$got; | |||||||||||||||||||||||||||||||||||||||||
| 666 | } | ||||||||||||||||||||||||||||||||||||||||||
| 667 | |||||||||||||||||||||||||||||||||||||||||||
| 668 | 111 | ▶ | sub json_is { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
json_is: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 669 | 111 | my ($self, $ptr, $want, $name) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 670 | 111 | local $Test::Builder::Level = $Test::Builder::Level + 1; | |||||||||||||||||||||||||||||||||||||||||
| 671 | # uncoverable condition false | ||||||||||||||||||||||||||||||||||||||||||
| 672 | 111 | ▶ | $name //= "json at '$ptr'"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$name //= "json at '${ptr}'"
MC/DC100%1/1
$name //= "json at '${ptr}'"
$name
Truth table100%2/2
A
A= $name
| |||||||||||||||||||||||||||||||||||||||||||
| 673 | # uncoverable branch true | ||||||||||||||||||||||||||||||||||||||||||
| 674 | 111 | ▶ | return $self->_no_response($name) unless $self->{res}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 675 | 111 | ▶ | my $slot = $self->_json_at($ptr, $name) or return $self; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 676 | 102 | my $got = $$slot; | |||||||||||||||||||||||||||||||||||||||||
| 677 | # uncoverable condition right | ||||||||||||||||||||||||||||||||||||||||||
| 678 | 102 | ▶ | if (ref $got || ref $want) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/3
ref $got or ref $want
MC/DC100%1/2
ref $got or ref $want
ref $got
ref $want
Truth table100%2/3
A or B
A= ref $gotB= ref $want
| |||||||||||||||||||||||||||||||||||||||||||
| 679 | # deep-compare through canonical JSON, wrapped so scalars encode | ||||||||||||||||||||||||||||||||||||||||||
| 680 | 7 | $TB->is_eq(File::Raw::JSON::file_json_encode([$got], sort_keys => 1), | |||||||||||||||||||||||||||||||||||||||||
| 681 | File::Raw::JSON::file_json_encode([$want], sort_keys => 1), $name); | ||||||||||||||||||||||||||||||||||||||||||
| 682 | } | ||||||||||||||||||||||||||||||||||||||||||
| 683 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 684 | 95 | $TB->is_eq($got, $want, $name); | |||||||||||||||||||||||||||||||||||||||||
| 685 | } | ||||||||||||||||||||||||||||||||||||||||||
| 686 | 102 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 687 | } | ||||||||||||||||||||||||||||||||||||||||||
| 688 | |||||||||||||||||||||||||||||||||||||||||||
| 689 | 6 | ▶ | sub json_has { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
json_has: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 690 | 6 | my ($self, $ptr, $name) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 691 | 6 | local $Test::Builder::Level = $Test::Builder::Level + 1; | |||||||||||||||||||||||||||||||||||||||||
| 692 | # uncoverable condition false | ||||||||||||||||||||||||||||||||||||||||||
| 693 | 6 | ▶ | $name //= "json has '$ptr'"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$name //= "json has '${ptr}'"
MC/DC100%1/1
$name //= "json has '${ptr}'"
$name
Truth table100%2/2
A
A= $name
| |||||||||||||||||||||||||||||||||||||||||||
| 694 | # uncoverable branch true | ||||||||||||||||||||||||||||||||||||||||||
| 695 | 6 | ▶ | return $self->_no_response($name) unless $self->{res}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 696 | # uncoverable branch true | ||||||||||||||||||||||||||||||||||||||||||
| 697 | 6 | ▶ | my $slot = $self->_json_at($ptr, $name) or return $self; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 698 | 6 | $TB->ok(1, $name); | |||||||||||||||||||||||||||||||||||||||||
| 699 | 6 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 700 | } | ||||||||||||||||||||||||||||||||||||||||||
| 701 | |||||||||||||||||||||||||||||||||||||||||||
| 702 | 27 | ▶ | sub json_like { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
json_like: called CC=6 SCAR=18.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 703 | 27 | my ($self, $ptr, $re, $name) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 704 | 27 | local $Test::Builder::Level = $Test::Builder::Level + 1; | |||||||||||||||||||||||||||||||||||||||||
| 705 | # uncoverable condition false | ||||||||||||||||||||||||||||||||||||||||||
| 706 | 27 | ▶ | $name //= "json at '$ptr' matches"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$name //= "json at '${ptr}' matches"
MC/DC100%1/1
$name //= "json at '${ptr}' matches"
$name
Truth table100%2/2
A
A= $name
| |||||||||||||||||||||||||||||||||||||||||||
| 707 | # uncoverable branch true | ||||||||||||||||||||||||||||||||||||||||||
| 708 | 27 | ▶ | return $self->_no_response($name) unless $self->{res}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 709 | # uncoverable branch true | ||||||||||||||||||||||||||||||||||||||||||
| 710 | 27 | ▶ | my $slot = $self->_json_at($ptr, $name) or return $self; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 711 | # uncoverable branch false | ||||||||||||||||||||||||||||||||||||||||||
| 712 | # uncoverable condition left | ||||||||||||||||||||||||||||||||||||||||||
| 713 | # uncoverable condition right | ||||||||||||||||||||||||||||||||||||||||||
| 714 | 27 | ▶ | $TB->like(defined $$slot && !ref $$slot ? $$slot : '', $re, $name); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%1/3
defined $$slot and not ref $$slot
MC/DC100%0/2
defined $$slot and not ref $$slot
defined $$slot
not ref $$slot
Truth table100%1/3
A and not(B)
A= defined $$slotB= not ref $$slot
| |||||||||||||||||||||||||||||||||||||||||||
| 715 | 27 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 716 | } | ||||||||||||||||||||||||||||||||||||||||||
| 717 | |||||||||||||||||||||||||||||||||||||||||||
| 718 | 15 | ▶ | sub _body_head { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_body_head: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 719 | 15 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 720 | # uncoverable branch false | ||||||||||||||||||||||||||||||||||||||||||
| 721 | 15 | ▶ | my $b = $self->{res} ? $self->{res}{body} : ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 722 | 15 | ▶ | $b = substr($b, 0, 500) . '...' if length $b > 500; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 723 | # uncoverable branch false | ||||||||||||||||||||||||||||||||||||||||||
| 724 | 15 | ▶ | return length $b ? $b : '(empty body)'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 725 | } | ||||||||||||||||||||||||||||||||||||||||||
| 726 | |||||||||||||||||||||||||||||||||||||||||||
| 727 | # ---- server-sent events ------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||
| 728 | |||||||||||||||||||||||||||||||||||||||||||
| 729 | 38 | ▶ | sub sse_ok { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sse_ok: called CC=11 SCAR=24.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 730 | 38 | my ($self, $path, %o) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 731 | 38 | local $Test::Builder::Level = $Test::Builder::Level + 1; | |||||||||||||||||||||||||||||||||||||||||
| 732 | 38 | $path = $self->_resolve_path($path); | |||||||||||||||||||||||||||||||||||||||||
| 733 | # uncoverable condition left | ||||||||||||||||||||||||||||||||||||||||||
| 734 | # uncoverable condition false | ||||||||||||||||||||||||||||||||||||||||||
| 735 | 38 | ▶ | my $name = $o{name} // "SSE $path"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%1/2
$o{"name"} // "SSE $path"
MC/DC100%0/1
$o{"name"} // "SSE $path"
$o{"name"}
Truth table100%1/2
A
A= $o{"name"}
| |||||||||||||||||||||||||||||||||||||||||||
| 736 | # uncoverable condition left | ||||||||||||||||||||||||||||||||||||||||||
| 737 | 38 | ▶ | $o{headers}{Accept} //= 'text/event-stream'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%1/2
$o{"headers"}{"Accept"} //= "text/event-stream"
MC/DC100%0/1
$o{"headers"}{"Accept"} //= "text/event-stream"
$o{"headers"}{"Accept"}
Truth table100%1/2
A
A= $o{"headers"}{"Accept"}
| |||||||||||||||||||||||||||||||||||||||||||
| 738 | 38 | my $env = $self->_build_env(GET => $path, %o); | |||||||||||||||||||||||||||||||||||||||||
| 739 | 38 | $env->{'psgi.streaming'} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 740 | 38 | delete $self->{sse}; | |||||||||||||||||||||||||||||||||||||||||
| 741 | 38 | my $r = eval { $self->{app}->($env) }; | |||||||||||||||||||||||||||||||||||||||||
| 742 | 38 | my $err = $@; | |||||||||||||||||||||||||||||||||||||||||
| 743 | 38 | ▶ | if (ref $r eq 'CODE') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 744 | 29 | $r = eval { $self->_drive_streaming($r) }; | |||||||||||||||||||||||||||||||||||||||||
| 745 | # uncoverable condition left | ||||||||||||||||||||||||||||||||||||||||||
| 746 | # uncoverable condition right | ||||||||||||||||||||||||||||||||||||||||||
| 747 | 29 | ▶ | $err ||= $@; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%1/3
$err ||= $@
MC/DC100%0/2
$err ||= $@
$err
$@
Truth table100%1/3
A ||= B
A= $errB= $@
| |||||||||||||||||||||||||||||||||||||||||||
| 748 | } | ||||||||||||||||||||||||||||||||||||||||||
| 749 | 38 | ▶ | unless (ref $r eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 750 | 6 | $self->{res} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 751 | 6 | $TB->ok(0, $name); | |||||||||||||||||||||||||||||||||||||||||
| 752 | 6 | ▶ | $TB->diag($err ? "the application died: $err" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 753 | : 'no response from the sse route'); | ||||||||||||||||||||||||||||||||||||||||||
| 754 | 6 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 755 | } | ||||||||||||||||||||||||||||||||||||||||||
| 756 | 32 | $self->_set_response($r); | |||||||||||||||||||||||||||||||||||||||||
| 757 | # uncoverable condition right | ||||||||||||||||||||||||||||||||||||||||||
| 758 | 32 | ▶ | my $ct = $self->header('Content-Type') // ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%1/2
$self->header("Content-Type") // ""
MC/DC100%0/1
$self->header("Content-Type") // ""
$self->header("Content-Type")
Truth table100%1/2
A
A= $self->header("Content-Type")
| |||||||||||||||||||||||||||||||||||||||||||
| 759 | # uncoverable condition left | ||||||||||||||||||||||||||||||||||||||||||
| 760 | 32 | ▶ | if ($r->[0] == 200 && $ct =~ m{\Atext/event-stream}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/3
$r->[0] == 200 and $ct =~ m[\Atext/event-stream]
MC/DC100%1/2
$r->[0] == 200 and $ct =~ m[\Atext/event-stream]
$r->[0] == 200
$ct =~ m[\Atext/event-stream]
Truth table100%2/3
A and B
A= $r->[0] == 200B= $ct =~ m[\Atext/event-stream]
| |||||||||||||||||||||||||||||||||||||||||||
| 761 | 29 | $self->{sse} = _parse_sse($self->{res}{body}); | |||||||||||||||||||||||||||||||||||||||||
| 762 | 29 | $TB->ok(1, $name); | |||||||||||||||||||||||||||||||||||||||||
| 763 | } | ||||||||||||||||||||||||||||||||||||||||||
| 764 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 765 | 3 | $TB->ok(0, $name); | |||||||||||||||||||||||||||||||||||||||||
| 766 | # uncoverable condition right | ||||||||||||||||||||||||||||||||||||||||||
| 767 | 3 | ▶ | $TB->diag("expected a 200 text/event-stream, got $r->[0] " | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%1/2
$ct || '(no content type)'
MC/DC100%0/1
$ct || '(no content type)'
$ct
Truth table100%1/2
A
A= $ct
| |||||||||||||||||||||||||||||||||||||||||||
| 768 | . ($ct || '(no content type)') . ': ' . $self->_body_head); | ||||||||||||||||||||||||||||||||||||||||||
| 769 | } | ||||||||||||||||||||||||||||||||||||||||||
| 770 | 32 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 771 | } | ||||||||||||||||||||||||||||||||||||||||||
| 772 | |||||||||||||||||||||||||||||||||||||||||||
| 773 | # The spec's dispatch loop: fields accumulate, a blank line dispatches. | ||||||||||||||||||||||||||||||||||||||||||
| 774 | 29 | ▶ | sub _parse_sse { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_sse: called CC=11 SCAR=24.0
| |||||||||||||||||||||||||||||||||||||||||||
| 775 | 29 | my ($bytes) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 776 | 29 | my (@events, @comments, %cur); | |||||||||||||||||||||||||||||||||||||||||
| 777 | 29 | for my $line (split /\n/, $bytes, -1) { | |||||||||||||||||||||||||||||||||||||||||
| 778 | 172 | $line =~ s/\r\z//; | |||||||||||||||||||||||||||||||||||||||||
| 779 | 172 | ▶ | if ($line eq '') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 780 | 79 | ▶ | push @events, {%cur} if %cur; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 781 | 79 | %cur = (); | |||||||||||||||||||||||||||||||||||||||||
| 782 | 79 | next; | |||||||||||||||||||||||||||||||||||||||||
| 783 | } | ||||||||||||||||||||||||||||||||||||||||||
| 784 | 93 | ▶ | if ($line =~ /\A:\s?(.*)\z/s) { push @comments, $1; next } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 785 | 86 | my ($field, $value) = $line =~ /\A([^:]+)(?::\s?(.*))?\z/s; | |||||||||||||||||||||||||||||||||||||||||
| 786 | # uncoverable condition right | ||||||||||||||||||||||||||||||||||||||||||
| 787 | 86 | ▶ | $value //= ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%1/2
$value //= ""
MC/DC100%0/1
$value //= ""
$value
Truth table100%1/2
A
A= $value
| |||||||||||||||||||||||||||||||||||||||||||
| 788 | # uncoverable branch false count:4 | ||||||||||||||||||||||||||||||||||||||||||
| 789 | 86 | ▶ | if ($field eq 'data') { $cur{data} = defined $cur{data} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 790 | 57 | ▶ | ? "$cur{data}\n$value" : $value } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 791 | 16 | elsif ($field eq 'event') { $cur{event} = $value } | |||||||||||||||||||||||||||||||||||||||||
| 792 | 7 | elsif ($field eq 'id') { $cur{id} = $value } | |||||||||||||||||||||||||||||||||||||||||
| 793 | 6 | elsif ($field eq 'retry') { $cur{retry} = $value } | |||||||||||||||||||||||||||||||||||||||||
| 794 | } | ||||||||||||||||||||||||||||||||||||||||||
| 795 | 29 | return { events => \@events, comments => \@comments }; | |||||||||||||||||||||||||||||||||||||||||
| 796 | } | ||||||||||||||||||||||||||||||||||||||||||
| 797 | |||||||||||||||||||||||||||||||||||||||||||
| 798 | # uncoverable branch false | ||||||||||||||||||||||||||||||||||||||||||
| 799 | 17 | ▶ | sub sse_events { $_[0]{sse} ? $_[0]{sse}{events} : undef } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sse_events: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 800 | # uncoverable branch false | ||||||||||||||||||||||||||||||||||||||||||
| 801 | 7 | ▶ | sub sse_comments { $_[0]{sse} ? $_[0]{sse}{comments} : undef } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sse_comments: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 802 | |||||||||||||||||||||||||||||||||||||||||||
| 803 | 74 | ▶ | sub _sse_event { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_sse_event: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 804 | 74 | my ($self, $i, $name) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 805 | 74 | local $Test::Builder::Level = $Test::Builder::Level + 1; | |||||||||||||||||||||||||||||||||||||||||
| 806 | 74 | ▶ | unless ($self->{sse}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 807 | 3 | $TB->ok(0, $name); | |||||||||||||||||||||||||||||||||||||||||
| 808 | 3 | $TB->diag('no SSE stream - did sse_ok pass?'); | |||||||||||||||||||||||||||||||||||||||||
| 809 | 3 | return; | |||||||||||||||||||||||||||||||||||||||||
| 810 | } | ||||||||||||||||||||||||||||||||||||||||||
| 811 | 71 | my $ev = $self->{sse}{events}[$i]; | |||||||||||||||||||||||||||||||||||||||||
| 812 | 71 | ▶ | unless ($ev) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 813 | 3 | $TB->ok(0, $name); | |||||||||||||||||||||||||||||||||||||||||
| 814 | $TB->diag("no event $i - the stream held " | ||||||||||||||||||||||||||||||||||||||||||
| 815 | 3 | . scalar(@{ $self->{sse}{events} }) . ' event(s)'); | |||||||||||||||||||||||||||||||||||||||||
| 816 | 3 | return; | |||||||||||||||||||||||||||||||||||||||||
| 817 | } | ||||||||||||||||||||||||||||||||||||||||||
| 818 | 68 | return $ev; | |||||||||||||||||||||||||||||||||||||||||
| 819 | } | ||||||||||||||||||||||||||||||||||||||||||
| 820 | |||||||||||||||||||||||||||||||||||||||||||
| 821 | 16 | ▶ | sub sse_event_is { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sse_event_is: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 822 | 16 | my ($self, $i, $event, $data, $name) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 823 | 16 | local $Test::Builder::Level = $Test::Builder::Level + 1; | |||||||||||||||||||||||||||||||||||||||||
| 824 | # uncoverable condition left | ||||||||||||||||||||||||||||||||||||||||||
| 825 | # uncoverable condition false | ||||||||||||||||||||||||||||||||||||||||||
| 826 | 16 | ▶ | $name //= "event $i is $event"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%1/2
$name //= "event $i is $event"
MC/DC100%0/1
$name //= "event $i is $event"
$name
Truth table100%1/2
A
A= $name
| |||||||||||||||||||||||||||||||||||||||||||
| 827 | 16 | ▶ | my $ev = $self->_sse_event($i, $name) or return $self; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 828 | # uncoverable condition right | ||||||||||||||||||||||||||||||||||||||||||
| 829 | 10 | ▶ | if (($ev->{event} // '') eq $event) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%1/2
$ev->{"event"} // ""
MC/DC100%0/1
$ev->{"event"} // ""
$ev->{"event"}
Truth table100%1/2
A
A= $ev->{"event"}
| |||||||||||||||||||||||||||||||||||||||||||
| 830 | # uncoverable condition right | ||||||||||||||||||||||||||||||||||||||||||
| 831 | 7 | ▶ | $TB->is_eq($ev->{data} // '', $data, $name); | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%1/2
$ev->{"data"} // ""
MC/DC100%0/1
$ev->{"data"} // ""
$ev->{"data"}
Truth table100%1/2
A
A= $ev->{"data"}
| |||||||||||||||||||||||||||||||||||||||||||
| 832 | } | ||||||||||||||||||||||||||||||||||||||||||
| 833 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 834 | 3 | $TB->ok(0, $name); | |||||||||||||||||||||||||||||||||||||||||
| 835 | # uncoverable condition right | ||||||||||||||||||||||||||||||||||||||||||
| 836 | 3 | ▶ | $TB->diag("event $i is named '" . ($ev->{event} // '') | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%1/2
$ev->{"event"} // ""
MC/DC100%0/1
$ev->{"event"} // ""
$ev->{"event"}
Truth table100%1/2
A
A= $ev->{"event"}
| |||||||||||||||||||||||||||||||||||||||||||
| 837 | . "', not '$event'"); | ||||||||||||||||||||||||||||||||||||||||||
| 838 | } | ||||||||||||||||||||||||||||||||||||||||||
| 839 | 10 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 840 | } | ||||||||||||||||||||||||||||||||||||||||||
| 841 | |||||||||||||||||||||||||||||||||||||||||||
| 842 | 14 | ▶ | sub sse_data_is { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sse_data_is: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 843 | 14 | my ($self, $i, $data, $name) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 844 | 14 | local $Test::Builder::Level = $Test::Builder::Level + 1; | |||||||||||||||||||||||||||||||||||||||||
| 845 | # uncoverable condition false | ||||||||||||||||||||||||||||||||||||||||||
| 846 | 14 | ▶ | $name //= "event $i data"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$name //= "event $i data"
MC/DC100%1/1
$name //= "event $i data"
$name
Truth table100%2/2
A
A= $name
| |||||||||||||||||||||||||||||||||||||||||||
| 847 | # uncoverable branch true | ||||||||||||||||||||||||||||||||||||||||||
| 848 | 14 | ▶ | my $ev = $self->_sse_event($i, $name) or return $self; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 849 | # uncoverable condition right | ||||||||||||||||||||||||||||||||||||||||||
| 850 | 14 | ▶ | $TB->is_eq($ev->{data} // '', $data, $name); | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%1/2
$ev->{"data"} // ""
MC/DC100%0/1
$ev->{"data"} // ""
$ev->{"data"}
Truth table100%1/2
A
A= $ev->{"data"}
| |||||||||||||||||||||||||||||||||||||||||||
| 851 | 14 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 852 | } | ||||||||||||||||||||||||||||||||||||||||||
| 853 | |||||||||||||||||||||||||||||||||||||||||||
| 854 | 44 | ▶ | sub sse_json_is { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sse_json_is: called CC=9 SCAR=22.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 855 | 44 | my ($self, $i, $ptr, $want, $name) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 856 | 44 | local $Test::Builder::Level = $Test::Builder::Level + 1; | |||||||||||||||||||||||||||||||||||||||||
| 857 | # uncoverable condition false | ||||||||||||||||||||||||||||||||||||||||||
| 858 | 44 | ▶ | $name //= "event $i json at '$ptr'"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$name //= "event $i json at '${ptr}'"
MC/DC100%1/1
$name //= "event $i json at '${ptr}'"
$name
Truth table100%2/2
A
A= $name
| |||||||||||||||||||||||||||||||||||||||||||
| 859 | # uncoverable branch true | ||||||||||||||||||||||||||||||||||||||||||
| 860 | 44 | ▶ | my $ev = $self->_sse_event($i, $name) or return $self; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 861 | # uncoverable condition right | ||||||||||||||||||||||||||||||||||||||||||
| 862 | 44 | ▶ | my $doc = eval { File::Raw::JSON::file_json_decode($ev->{data} // '') }; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%1/2
$ev->{"data"} // ""
MC/DC100%0/1
$ev->{"data"} // ""
$ev->{"data"}
Truth table100%1/2
A
A= $ev->{"data"}
| |||||||||||||||||||||||||||||||||||||||||||
| 863 | 44 | ▶ | unless (defined $doc) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 864 | 3 | $TB->ok(0, $name); | |||||||||||||||||||||||||||||||||||||||||
| 865 | # uncoverable condition right | ||||||||||||||||||||||||||||||||||||||||||
| 866 | 3 | ▶ | $TB->diag("event $i data is not JSON: " . ($ev->{data} // '')); | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%1/2
$ev->{"data"} // ""
MC/DC100%0/1
$ev->{"data"} // ""
$ev->{"data"}
Truth table100%1/2
A
A= $ev->{"data"}
| |||||||||||||||||||||||||||||||||||||||||||
| 867 | 3 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 868 | } | ||||||||||||||||||||||||||||||||||||||||||
| 869 | 41 | my ($found, $got) = _ptr_get($doc, $ptr); | |||||||||||||||||||||||||||||||||||||||||
| 870 | 41 | ▶ | unless ($found) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 871 | 3 | $TB->ok(0, $name); | |||||||||||||||||||||||||||||||||||||||||
| 872 | 3 | $TB->diag("nothing at JSON pointer '$ptr' in event $i"); | |||||||||||||||||||||||||||||||||||||||||
| 873 | 3 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 874 | } | ||||||||||||||||||||||||||||||||||||||||||
| 875 | # uncoverable condition right | ||||||||||||||||||||||||||||||||||||||||||
| 876 | 38 | ▶ | if (ref $got || ref $want) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/3
ref $got or ref $want
MC/DC100%1/2
ref $got or ref $want
ref $got
ref $want
Truth table100%2/3
A or B
A= ref $gotB= ref $want
| |||||||||||||||||||||||||||||||||||||||||||
| 877 | 14 | $TB->is_eq(File::Raw::JSON::file_json_encode([$got], sort_keys => 1), | |||||||||||||||||||||||||||||||||||||||||
| 878 | File::Raw::JSON::file_json_encode([$want], sort_keys => 1), $name); | ||||||||||||||||||||||||||||||||||||||||||
| 879 | } | ||||||||||||||||||||||||||||||||||||||||||
| 880 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 881 | 24 | $TB->is_eq($got, $want, $name); | |||||||||||||||||||||||||||||||||||||||||
| 882 | } | ||||||||||||||||||||||||||||||||||||||||||
| 883 | 38 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 884 | } | ||||||||||||||||||||||||||||||||||||||||||
| 885 | |||||||||||||||||||||||||||||||||||||||||||
| 886 | # ---- websockets -------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 887 | |||||||||||||||||||||||||||||||||||||||||||
| 888 | # Whether the live (forked Hyperman) transport can run here at all - tests | ||||||||||||||||||||||||||||||||||||||||||
| 889 | # use this to SKIP, the same way t/1011-ws-live.t does. | ||||||||||||||||||||||||||||||||||||||||||
| 890 | 9 | ▶ | sub ws_live_available { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ws_live_available: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 891 | # uncoverable branch false | ||||||||||||||||||||||||||||||||||||||||||
| 892 | 9 | ▶ | return eval { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 893 | 9 | require Hyperman; | |||||||||||||||||||||||||||||||||||||||||
| 894 | 9 | require Punk::WebSocket; | |||||||||||||||||||||||||||||||||||||||||
| 895 | 9 | Punk::WebSocket::_hm_available(); | |||||||||||||||||||||||||||||||||||||||||
| 896 | } ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||
| 897 | } | ||||||||||||||||||||||||||||||||||||||||||
| 898 | |||||||||||||||||||||||||||||||||||||||||||
| 899 | 57 | ▶ | sub websocket_ok { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
websocket_ok: called CC=14 SCAR=26.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 900 | 57 | my ($self, $path, %o) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 901 | 57 | local $Test::Builder::Level = $Test::Builder::Level + 1; | |||||||||||||||||||||||||||||||||||||||||
| 902 | 57 | $path = $self->_resolve_path($path); | |||||||||||||||||||||||||||||||||||||||||
| 903 | # uncoverable condition left | ||||||||||||||||||||||||||||||||||||||||||
| 904 | # uncoverable condition false | ||||||||||||||||||||||||||||||||||||||||||
| 905 | 57 | ▶ | my $name = $o{name} // "websocket $path"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%1/2
$o{"name"} // "websocket $path"
MC/DC100%0/1
$o{"name"} // "websocket $path"
$o{"name"}
Truth table100%1/2
A
A= $o{"name"}
| |||||||||||||||||||||||||||||||||||||||||||
| 906 | 57 | $self->_ws_teardown; | |||||||||||||||||||||||||||||||||||||||||
| 907 | |||||||||||||||||||||||||||||||||||||||||||
| 908 | 57 | ▶ | if (!$o{live}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 909 | 55 | my ($conn, $hdr, $key, $status) = $self->_ws_inprocess($path, %o); | |||||||||||||||||||||||||||||||||||||||||
| 910 | 43 | ▶ | if ($status == 101) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 911 | 35 | my ($acc) = $hdr =~ /Sec-WebSocket-Accept: (\S+)/i; | |||||||||||||||||||||||||||||||||||||||||
| 912 | 35 | $self->{ws} = $conn; | |||||||||||||||||||||||||||||||||||||||||
| 913 | 35 | $self->{ws_hdr} = $hdr; | |||||||||||||||||||||||||||||||||||||||||
| 914 | # uncoverable condition right | ||||||||||||||||||||||||||||||||||||||||||
| 915 | 35 | ▶ | $TB->is_eq($acc // '', Punk::Test::WS::accept_key($key), $name); | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%1/2
$acc // ""
MC/DC100%0/1
$acc // ""
$acc
Truth table100%1/2
A
A= $acc
| |||||||||||||||||||||||||||||||||||||||||||
| 916 | 35 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 917 | } | ||||||||||||||||||||||||||||||||||||||||||
| 918 | # uncoverable branch false | ||||||||||||||||||||||||||||||||||||||||||
| 919 | 8 | ▶ | $conn->close if $conn; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 920 | 8 | ▶ | if ($status != 501) { # 501 = this transport cannot upgrade; go live | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 921 | 6 | $TB->ok(0, $name); | |||||||||||||||||||||||||||||||||||||||||
| 922 | # uncoverable branch false | ||||||||||||||||||||||||||||||||||||||||||
| 923 | 6 | ▶ | $TB->diag($status | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 924 | ? "the upgrade was answered with a $status:\n$hdr" | ||||||||||||||||||||||||||||||||||||||||||
| 925 | : 'no bytes came back from the upgrade request'); | ||||||||||||||||||||||||||||||||||||||||||
| 926 | 6 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 927 | } | ||||||||||||||||||||||||||||||||||||||||||
| 928 | } | ||||||||||||||||||||||||||||||||||||||||||
| 929 | |||||||||||||||||||||||||||||||||||||||||||
| 930 | # uncoverable branch true | ||||||||||||||||||||||||||||||||||||||||||
| 931 | 4 | ▶ | unless (ws_live_available()) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 932 | # uncoverable statement | ||||||||||||||||||||||||||||||||||||||||||
| 933 | 0 | $TB->ok(0, $name); | |||||||||||||||||||||||||||||||||||||||||
| 934 | # uncoverable statement | ||||||||||||||||||||||||||||||||||||||||||
| 935 | 0 | $TB->diag('this route needs the live transport (Hyperman 0.11+); ' | |||||||||||||||||||||||||||||||||||||||||
| 936 | . 'guard the test with Punk::Test::ws_live_available'); | ||||||||||||||||||||||||||||||||||||||||||
| 937 | # uncoverable statement | ||||||||||||||||||||||||||||||||||||||||||
| 938 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 939 | } | ||||||||||||||||||||||||||||||||||||||||||
| 940 | 4 | my ($conn, $hdr, $key) = $self->_ws_live($path, %o); | |||||||||||||||||||||||||||||||||||||||||
| 941 | # uncoverable branch true | ||||||||||||||||||||||||||||||||||||||||||
| 942 | 2 | ▶ | unless ($conn) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 943 | # uncoverable statement | ||||||||||||||||||||||||||||||||||||||||||
| 944 | 0 | $TB->ok(0, $name); | |||||||||||||||||||||||||||||||||||||||||
| 945 | # uncoverable statement | ||||||||||||||||||||||||||||||||||||||||||
| 946 | # uncoverable condition left | ||||||||||||||||||||||||||||||||||||||||||
| 947 | # uncoverable condition right | ||||||||||||||||||||||||||||||||||||||||||
| 948 | 0 | ▶ | $TB->diag($hdr // 'could not connect to the live worker'); | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%0/2
$hdr // "could not connect to the live worker"
MC/DC100%0/1
$hdr // "could not connect to the live worker"
$hdr
Truth table100%0/2
A
A= $hdr
| |||||||||||||||||||||||||||||||||||||||||||
| 949 | # uncoverable statement | ||||||||||||||||||||||||||||||||||||||||||
| 950 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 951 | } | ||||||||||||||||||||||||||||||||||||||||||
| 952 | 2 | ▶ | if ($hdr =~ m{\AHTTP/1\.1 101 }) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 953 | 1 | my ($acc) = $hdr =~ /Sec-WebSocket-Accept: (\S+)/i; | |||||||||||||||||||||||||||||||||||||||||
| 954 | 1 | $self->{ws} = $conn; | |||||||||||||||||||||||||||||||||||||||||
| 955 | 1 | $self->{ws_hdr} = $hdr; | |||||||||||||||||||||||||||||||||||||||||
| 956 | # uncoverable condition right | ||||||||||||||||||||||||||||||||||||||||||
| 957 | 1 | ▶ | $TB->is_eq($acc // '', Punk::Test::WS::accept_key($key), $name); | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%1/2
$acc // ""
MC/DC100%0/1
$acc // ""
$acc
Truth table100%1/2
A
A= $acc
| |||||||||||||||||||||||||||||||||||||||||||
| 958 | } | ||||||||||||||||||||||||||||||||||||||||||
| 959 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 960 | 1 | $conn->close; | |||||||||||||||||||||||||||||||||||||||||
| 961 | 1 | $TB->ok(0, $name); | |||||||||||||||||||||||||||||||||||||||||
| 962 | 1 | my ($line) = split /\r\n/, $hdr; | |||||||||||||||||||||||||||||||||||||||||
| 963 | # uncoverable condition right | ||||||||||||||||||||||||||||||||||||||||||
| 964 | 1 | ▶ | $TB->diag('the upgrade was answered with: ' . ($line // '(nothing)')); | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%1/2
$line // "(nothing)"
MC/DC100%0/1
$line // "(nothing)"
$line
Truth table100%1/2
A
A= $line
| |||||||||||||||||||||||||||||||||||||||||||
| 965 | } | ||||||||||||||||||||||||||||||||||||||||||
| 966 | 2 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 967 | } | ||||||||||||||||||||||||||||||||||||||||||
| 968 | |||||||||||||||||||||||||||||||||||||||||||
| 969 | # In-process transport: the app runs in a fork with one end of a socketpair | ||||||||||||||||||||||||||||||||||||||||||
| 970 | # as psgix.io - so a blocking => 1 route streams to us in real time while | ||||||||||||||||||||||||||||||||||||||||||
| 971 | # this side sends and asserts interactively. The child answers non-upgrade | ||||||||||||||||||||||||||||||||||||||||||
| 972 | # triplets (a guard's 403, the 501 of a route this transport cannot carry) | ||||||||||||||||||||||||||||||||||||||||||
| 973 | # as minimal HTTP so the parent can see why. | ||||||||||||||||||||||||||||||||||||||||||
| 974 | 55 | ▶ | sub _ws_inprocess { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ws_inprocess: called CC=13 SCAR=25.7
| |||||||||||||||||||||||||||||||||||||||||||
| 975 | 55 | my ($self, $path, %o) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 976 | my ($env, $key) = Punk::Test::WS::upgrade_env( | ||||||||||||||||||||||||||||||||||||||||||
| 977 | 55 | path => $path, query => $o{query}, protocol => $o{protocol}); | |||||||||||||||||||||||||||||||||||||||||
| 978 | 55 | ▶ | if (my $h = $o{headers}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 979 | 10 | for my $k (keys %$h) { | |||||||||||||||||||||||||||||||||||||||||
| 980 | 10 | my $ek = uc $k; $ek =~ tr/-/_/; | |||||||||||||||||||||||||||||||||||||||||
| 981 | 10 | $env->{"HTTP_$ek"} = $h->{$k}; | |||||||||||||||||||||||||||||||||||||||||
| 982 | } | ||||||||||||||||||||||||||||||||||||||||||
| 983 | } | ||||||||||||||||||||||||||||||||||||||||||
| 984 | 55 | ▶ | if (my $jar = $self->_jar_header) { $env->{HTTP_COOKIE} = $jar } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 985 | |||||||||||||||||||||||||||||||||||||||||||
| 986 | # uncoverable branch true | ||||||||||||||||||||||||||||||||||||||||||
| 987 | 55 | ▶ | socketpair(my $ours, my $theirs, AF_UNIX, SOCK_STREAM, PF_UNSPEC) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 988 | or die "Punk::Test: socketpair: $!"; | ||||||||||||||||||||||||||||||||||||||||||
| 989 | # uncoverable condition right | ||||||||||||||||||||||||||||||||||||||||||
| 990 | 55 | ▶ | my $pid = fork // die "Punk::Test: fork: $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%1/2
fork // die("Punk::Test: fork: $!")
MC/DC100%0/1
fork // die("Punk::Test: fork: $!")
fork
Truth table100%1/2
A
A= fork
| |||||||||||||||||||||||||||||||||||||||||||
| 991 | 55 | ▶ | if (!$pid) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 992 | # the child owns no test state: keep it off the TAP pipe entirely, | ||||||||||||||||||||||||||||||||||||||||||
| 993 | # and leave by exit with the test ending turned off, so the counters flush | ||||||||||||||||||||||||||||||||||||||||||
| 994 | 12 | close $ours; | |||||||||||||||||||||||||||||||||||||||||
| 995 | 12 | open STDIN, '<', '/dev/null'; | |||||||||||||||||||||||||||||||||||||||||
| 996 | 12 | open STDOUT, '>', '/dev/null'; | |||||||||||||||||||||||||||||||||||||||||
| 997 | 12 | open STDERR, '>', '/dev/null'; | |||||||||||||||||||||||||||||||||||||||||
| 998 | 12 | $env->{'psgix.io'} = $theirs; | |||||||||||||||||||||||||||||||||||||||||
| 999 | 12 | my $r = eval { $self->{app}->($env) }; | |||||||||||||||||||||||||||||||||||||||||
| 1000 | # uncoverable branch false count:2 | ||||||||||||||||||||||||||||||||||||||||||
| 1001 | 12 | ▶ | if (ref $r eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 1002 | # a successful blocking upgrade already spoke on the socket and | ||||||||||||||||||||||||||||||||||||||||||
| 1003 | # returns the empty 200 sentinel; anything else (a guard's 403, | ||||||||||||||||||||||||||||||||||||||||||
| 1004 | # the 501 of a route this transport cannot carry, a plain route | ||||||||||||||||||||||||||||||||||||||||||
| 1005 | # answering) is relayed as minimal HTTP so the parent sees why | ||||||||||||||||||||||||||||||||||||||||||
| 1006 | my $body = ref $r->[2] eq 'ARRAY' | ||||||||||||||||||||||||||||||||||||||||||
| 1007 | # uncoverable branch false | ||||||||||||||||||||||||||||||||||||||||||
| 1008 | 11 | ▶ | ? join('', grep { defined } @{ $r->[2] }) : ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1009 | # uncoverable condition right | ||||||||||||||||||||||||||||||||||||||||||
| 1010 | 11 | ▶ | syswrite $theirs, "HTTP/1.1 $r->[0] X\r\n" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/3
$r->[0] == 200 and not length $body
MC/DC100%1/2
$r->[0] == 200 and not length $body
$r->[0] == 200
not length $body
Truth table100%2/3
A and not(B)
A= $r->[0] == 200B= not length $body
| |||||||||||||||||||||||||||||||||||||||||||
| 1011 | . "Content-Length: " . length($body) . "\r\n" | ||||||||||||||||||||||||||||||||||||||||||
| 1012 | . "\r\n$body" | ||||||||||||||||||||||||||||||||||||||||||
| 1013 | unless $r->[0] == 200 && !length $body; | ||||||||||||||||||||||||||||||||||||||||||
| 1014 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1015 | elsif (!defined $r) { | ||||||||||||||||||||||||||||||||||||||||||
| 1016 | 1 | syswrite $theirs, "HTTP/1.1 500 X\r\n\r\n"; | |||||||||||||||||||||||||||||||||||||||||
| 1017 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1018 | 12 | Test::Builder->new->no_ending(1); | |||||||||||||||||||||||||||||||||||||||||
| 1019 | 12 | exit 0; | |||||||||||||||||||||||||||||||||||||||||
| 1020 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1021 | 43 | close $theirs; | |||||||||||||||||||||||||||||||||||||||||
| 1022 | my $conn = Punk::Test::WS::Conn->new( | ||||||||||||||||||||||||||||||||||||||||||
| 1023 | 43 | sock => $ours, timeout => $self->{timeout}, pid => $pid); | |||||||||||||||||||||||||||||||||||||||||
| 1024 | 43 | my $hdr = $conn->read_headers; | |||||||||||||||||||||||||||||||||||||||||
| 1025 | 43 | my ($status) = $hdr =~ m{\AHTTP/1\.1 (\d+)}; | |||||||||||||||||||||||||||||||||||||||||
| 1026 | # uncoverable condition right | ||||||||||||||||||||||||||||||||||||||||||
| 1027 | 43 | ▶ | return ($conn, $hdr, $key, $status // 0); | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%1/2
$status // 0
MC/DC100%0/1
$status // 0
$status
Truth table100%1/2
A
A= $status
| |||||||||||||||||||||||||||||||||||||||||||
| 1028 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1029 | |||||||||||||||||||||||||||||||||||||||||||
| 1030 | # Live transport: one forked Hyperman worker per client, started on first | ||||||||||||||||||||||||||||||||||||||||||
| 1031 | # use, speaking real TCP - fully interactive, and the same machinery as | ||||||||||||||||||||||||||||||||||||||||||
| 1032 | # t/1011-ws-live.t. | ||||||||||||||||||||||||||||||||||||||||||
| 1033 | 4 | ▶ | sub _ws_live { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ws_live: called CC=5 SCAR=16.3
| |||||||||||||||||||||||||||||||||||||||||||
| 1034 | 4 | my ($self, $path, %o) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1035 | # uncoverable branch true | ||||||||||||||||||||||||||||||||||||||||||
| 1036 | 4 | ▶ | my $host = $self->_live_host or return (undef, 'live worker failed to start'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1037 | 2 | require IO::Socket::INET; | |||||||||||||||||||||||||||||||||||||||||
| 1038 | # uncoverable branch true | ||||||||||||||||||||||||||||||||||||||||||
| 1039 | 2 | ▶ | my $sock = IO::Socket::INET->new(PeerAddr => $host) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1040 | or return (undef, "connect $host: $!"); | ||||||||||||||||||||||||||||||||||||||||||
| 1041 | 2 | $sock->autoflush(1); | |||||||||||||||||||||||||||||||||||||||||
| 1042 | 1 | my @extra = map { my $k = $_; "$k: $o{headers}{$k}" } | |||||||||||||||||||||||||||||||||||||||||
| 1043 | 2 | ▶ | keys %{ $o{headers} || {} }; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$o{'headers'} || {}
MC/DC100%1/1
$o{'headers'} || {}
$o{'headers'}
Truth table100%2/2
A
A= $o{'headers'}
| |||||||||||||||||||||||||||||||||||||||||||
| 1044 | 2 | ▶ | if (my $jar = $self->_jar_header) { push @extra, "Cookie: $jar" } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1045 | my ($req, $key) = Punk::Test::WS::handshake_request( | ||||||||||||||||||||||||||||||||||||||||||
| 1046 | host => $host, path => $path, protocol => $o{protocol}, | ||||||||||||||||||||||||||||||||||||||||||
| 1047 | 2 | extra => \@extra); | |||||||||||||||||||||||||||||||||||||||||
| 1048 | 2 | syswrite $sock, $req; | |||||||||||||||||||||||||||||||||||||||||
| 1049 | my $conn = Punk::Test::WS::Conn->new( | ||||||||||||||||||||||||||||||||||||||||||
| 1050 | 2 | sock => $sock, timeout => $self->{timeout}); | |||||||||||||||||||||||||||||||||||||||||
| 1051 | 2 | my $hdr = $conn->read_headers; | |||||||||||||||||||||||||||||||||||||||||
| 1052 | 2 | return ($conn, $hdr, $key); | |||||||||||||||||||||||||||||||||||||||||
| 1053 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1054 | |||||||||||||||||||||||||||||||||||||||||||
| 1055 | 4 | ▶ | sub _live_host { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_live_host: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 1056 | 4 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1057 | # uncoverable branch true | ||||||||||||||||||||||||||||||||||||||||||
| 1058 | 4 | ▶ | return $self->{live}{host} if $self->{live}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1059 | 4 | require IO::Socket::INET; | |||||||||||||||||||||||||||||||||||||||||
| 1060 | 4 | my $port = 27000 + ($$ % 400); | |||||||||||||||||||||||||||||||||||||||||
| 1061 | # uncoverable condition right | ||||||||||||||||||||||||||||||||||||||||||
| 1062 | 4 | ▶ | my $pid = fork // die "Punk::Test: fork: $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%1/2
fork // die("Punk::Test: fork: $!")
MC/DC100%0/1
fork // die("Punk::Test: fork: $!")
fork
Truth table100%1/2
A
A= fork
| |||||||||||||||||||||||||||||||||||||||||||
| 1063 | 4 | ▶ | if (!$pid) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1064 | 2 | open STDIN, '<', '/dev/null'; | |||||||||||||||||||||||||||||||||||||||||
| 1065 | 2 | open STDOUT, '>', '/dev/null'; | |||||||||||||||||||||||||||||||||||||||||
| 1066 | 2 | open STDERR, '>', '/dev/null'; | |||||||||||||||||||||||||||||||||||||||||
| 1067 | 2 | eval { | |||||||||||||||||||||||||||||||||||||||||
| 1068 | 2 | Hyperman->run(app => $self->{app}, host => '127.0.0.1', | |||||||||||||||||||||||||||||||||||||||||
| 1069 | port => $port, workers => 1); | ||||||||||||||||||||||||||||||||||||||||||
| 1070 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 1071 | 2 | Test::Builder->new->no_ending(1); | |||||||||||||||||||||||||||||||||||||||||
| 1072 | 2 | exit 0; | |||||||||||||||||||||||||||||||||||||||||
| 1073 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1074 | 2 | my $host = "127.0.0.1:$port"; | |||||||||||||||||||||||||||||||||||||||||
| 1075 | 2 | for (1 .. 100) { | |||||||||||||||||||||||||||||||||||||||||
| 1076 | 4 | my $s = IO::Socket::INET->new(PeerAddr => $host); | |||||||||||||||||||||||||||||||||||||||||
| 1077 | 4 | ▶ | if ($s) { close $s; $self->{live} = { pid => $pid, host => $host }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1078 | 2 | return $host } | |||||||||||||||||||||||||||||||||||||||||
| 1079 | 2 | select undef, undef, undef, 0.1; | |||||||||||||||||||||||||||||||||||||||||
| 1080 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1081 | # uncoverable statement | ||||||||||||||||||||||||||||||||||||||||||
| 1082 | 0 | kill 'KILL', $pid; | |||||||||||||||||||||||||||||||||||||||||
| 1083 | # uncoverable statement | ||||||||||||||||||||||||||||||||||||||||||
| 1084 | 0 | waitpid $pid, 0; | |||||||||||||||||||||||||||||||||||||||||
| 1085 | # uncoverable statement | ||||||||||||||||||||||||||||||||||||||||||
| 1086 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 1087 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1088 | |||||||||||||||||||||||||||||||||||||||||||
| 1089 | 40 | ▶ | sub send_ok { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
send_ok: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1090 | 40 | my ($self, $payload, %o) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1091 | 40 | local $Test::Builder::Level = $Test::Builder::Level + 1; | |||||||||||||||||||||||||||||||||||||||||
| 1092 | # uncoverable condition left | ||||||||||||||||||||||||||||||||||||||||||
| 1093 | 40 | ▶ | my $name = $o{name} // 'send'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%1/2
$o{"name"} // "send"
MC/DC100%0/1
$o{"name"} // "send"
$o{"name"}
Truth table100%1/2
A
A= $o{"name"}
| |||||||||||||||||||||||||||||||||||||||||||
| 1094 | 40 | ▶ | unless ($self->{ws}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1095 | 3 | $TB->ok(0, $name); | |||||||||||||||||||||||||||||||||||||||||
| 1096 | 3 | $TB->diag('no websocket - did websocket_ok pass?'); | |||||||||||||||||||||||||||||||||||||||||
| 1097 | 3 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 1098 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1099 | my $n = $self->{ws}->send_frame( | ||||||||||||||||||||||||||||||||||||||||||
| 1100 | # uncoverable condition left | ||||||||||||||||||||||||||||||||||||||||||
| 1101 | 37 | ▶ | opcode => $o{binary} ? 2 : ($o{opcode} // 1), | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%1/2
$o{"opcode"} // 1
MC/DC100%0/1
$o{"opcode"} // 1
$o{"opcode"}
Truth table100%1/2
A
A= $o{"opcode"}
| |||||||||||||||||||||||||||||||||||||||||||
| 1102 | payload => $payload); | ||||||||||||||||||||||||||||||||||||||||||
| 1103 | 37 | $TB->ok(defined $n, $name); | |||||||||||||||||||||||||||||||||||||||||
| 1104 | 37 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 1105 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1106 | |||||||||||||||||||||||||||||||||||||||||||
| 1107 | # The next data frame's payload, reassembling fragments, skipping pongs. | ||||||||||||||||||||||||||||||||||||||||||
| 1108 | 48 | ▶ | sub _next_message { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_next_message: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 1109 | 48 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1110 | 48 | my $payload = ''; | |||||||||||||||||||||||||||||||||||||||||
| 1111 | 48 | while (1) { | |||||||||||||||||||||||||||||||||||||||||
| 1112 | 48 | ▶ | my $f = $self->{ws}->read_frame or return undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1113 | # uncoverable branch true | ||||||||||||||||||||||||||||||||||||||||||
| 1114 | 45 | ▶ | next if $f->{opcode} == 10; # a pong | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1115 | 45 | ▶ | return { close => 1, frame => $f } if $f->{opcode} == 8; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1116 | 37 | $payload .= $f->{payload}; | |||||||||||||||||||||||||||||||||||||||||
| 1117 | # uncoverable branch false | ||||||||||||||||||||||||||||||||||||||||||
| 1118 | 37 | ▶ | return { payload => $payload, frame => $f } if $f->{fin}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1119 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1120 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1121 | |||||||||||||||||||||||||||||||||||||||||||
| 1122 | 42 | ▶ | sub message_is { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
message_is: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1123 | 42 | my ($self, $want, $name) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1124 | 42 | local $Test::Builder::Level = $Test::Builder::Level + 1; | |||||||||||||||||||||||||||||||||||||||||
| 1125 | 42 | ▶ | $name //= 'message'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$name //= "message"
MC/DC100%1/1
$name //= "message"
$name
Truth table100%2/2
A
A= $name
| |||||||||||||||||||||||||||||||||||||||||||
| 1126 | 42 | ▶ | unless ($self->{ws}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1127 | 3 | $TB->ok(0, $name); | |||||||||||||||||||||||||||||||||||||||||
| 1128 | 3 | $TB->diag('no websocket - did websocket_ok pass?'); | |||||||||||||||||||||||||||||||||||||||||
| 1129 | 3 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 1130 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1131 | 39 | my $m = $self->_next_message; | |||||||||||||||||||||||||||||||||||||||||
| 1132 | 39 | ▶ | if (!$m) { $TB->ok(0, $name); $TB->diag('no frame arrived (timeout or EOF)') } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 1133 | 5 | elsif ($m->{close}) { $TB->ok(0, $name); $TB->diag('the server closed instead') } | |||||||||||||||||||||||||||||||||||||||||
| 1134 | 33 | else { $TB->is_eq($m->{payload}, $want, $name) } | |||||||||||||||||||||||||||||||||||||||||
| 1135 | 39 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 1136 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1137 | |||||||||||||||||||||||||||||||||||||||||||
| 1138 | 12 | ▶ | sub message_like { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
message_like: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1139 | 12 | my ($self, $re, $name) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1140 | 12 | local $Test::Builder::Level = $Test::Builder::Level + 1; | |||||||||||||||||||||||||||||||||||||||||
| 1141 | 12 | ▶ | $name //= 'message matches'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$name //= "message matches"
MC/DC100%1/1
$name //= "message matches"
$name
Truth table100%2/2
A
A= $name
| |||||||||||||||||||||||||||||||||||||||||||
| 1142 | 12 | ▶ | unless ($self->{ws}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1143 | 3 | $TB->ok(0, $name); | |||||||||||||||||||||||||||||||||||||||||
| 1144 | 3 | $TB->diag('no websocket - did websocket_ok pass?'); | |||||||||||||||||||||||||||||||||||||||||
| 1145 | 3 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 1146 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1147 | 9 | my $m = $self->_next_message; | |||||||||||||||||||||||||||||||||||||||||
| 1148 | 9 | ▶ | if (!$m) { $TB->ok(0, $name); $TB->diag('no frame arrived (timeout or EOF)') } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 1149 | 3 | elsif ($m->{close}) { $TB->ok(0, $name); $TB->diag('the server closed instead') } | |||||||||||||||||||||||||||||||||||||||||
| 1150 | 4 | else { $TB->like($m->{payload}, $re, $name) } | |||||||||||||||||||||||||||||||||||||||||
| 1151 | 9 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 1152 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1153 | |||||||||||||||||||||||||||||||||||||||||||
| 1154 | 28 | ▶ | sub finish_ok { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
finish_ok: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1155 | 28 | my ($self, $name) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1156 | 28 | local $Test::Builder::Level = $Test::Builder::Level + 1; | |||||||||||||||||||||||||||||||||||||||||
| 1157 | # uncoverable condition left | ||||||||||||||||||||||||||||||||||||||||||
| 1158 | 28 | ▶ | $name //= 'clean close'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%1/2
$name //= "clean close"
MC/DC100%0/1
$name //= "clean close"
$name
Truth table100%1/2
A
A= $name
| |||||||||||||||||||||||||||||||||||||||||||
| 1159 | 28 | ▶ | unless ($self->{ws}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1160 | 3 | $TB->ok(0, $name); | |||||||||||||||||||||||||||||||||||||||||
| 1161 | 3 | $TB->diag('no websocket - did websocket_ok pass?'); | |||||||||||||||||||||||||||||||||||||||||
| 1162 | 3 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 1163 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1164 | 25 | $self->{ws}->send_frame(opcode => 8, payload => pack('n', 1000)); | |||||||||||||||||||||||||||||||||||||||||
| 1165 | 25 | my $echoed = 0; | |||||||||||||||||||||||||||||||||||||||||
| 1166 | 25 | ▶ | while (my $f = $self->{ws}->read_frame) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1167 | # uncoverable branch false | ||||||||||||||||||||||||||||||||||||||||||
| 1168 | 25 | ▶ | if ($f->{opcode} == 8) { $echoed = 1; last } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1169 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1170 | 25 | $TB->ok($echoed, $name); | |||||||||||||||||||||||||||||||||||||||||
| 1171 | # uncoverable branch true | ||||||||||||||||||||||||||||||||||||||||||
| 1172 | 25 | ▶ | $TB->diag('the close was never echoed') unless $echoed; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1173 | 25 | $self->_ws_teardown; | |||||||||||||||||||||||||||||||||||||||||
| 1174 | 25 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 1175 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1176 | |||||||||||||||||||||||||||||||||||||||||||
| 1177 | 258 | ▶ | sub _ws_teardown { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ws_teardown: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 1178 | 258 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1179 | 258 | ▶ | if (my $ws = delete $self->{ws}) { $ws->close } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1180 | 258 | delete $self->{ws_hdr}; | |||||||||||||||||||||||||||||||||||||||||
| 1181 | 258 | return; | |||||||||||||||||||||||||||||||||||||||||
| 1182 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1183 | |||||||||||||||||||||||||||||||||||||||||||
| 1184 | 176 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 1185 | 176 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1186 | 176 | $self->_ws_teardown; | |||||||||||||||||||||||||||||||||||||||||
| 1187 | 176 | ▶ | if (my $live = delete $self->{live}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1188 | 2 | kill 'TERM', $live->{pid}; | |||||||||||||||||||||||||||||||||||||||||
| 1189 | 2 | waitpid $live->{pid}, 0; | |||||||||||||||||||||||||||||||||||||||||
| 1190 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1191 | 176 | return; | |||||||||||||||||||||||||||||||||||||||||
| 1192 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1193 | |||||||||||||||||||||||||||||||||||||||||||
| 1194 | # psgi.input for a multipart request: a real PerlIO handle - the parser | ||||||||||||||||||||||||||||||||||||||||||
| 1195 | # reads it with PerlIO_read, which a tied handle never sees - whose FILL | ||||||||||||||||||||||||||||||||||||||||||
| 1196 | # drains the item list built by _multipart_input. @QUEUE hands the list | ||||||||||||||||||||||||||||||||||||||||||
| 1197 | # to PUSHED, because open() gives a via layer no arguments of ours. | ||||||||||||||||||||||||||||||||||||||||||
| 1198 | package | ||||||||||||||||||||||||||||||||||||||||||
| 1199 | Punk::Test::_MPInput; | ||||||||||||||||||||||||||||||||||||||||||
| 1200 | |||||||||||||||||||||||||||||||||||||||||||
| 1201 | 56 | our @QUEUE; | |||||||||||||||||||||||||||||||||||||||||
| 1202 | 18 | ▶ | sub PUSHED { bless { items => shift @QUEUE }, $_[0] } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
PUSHED: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1203 | 105 | ▶ | sub FILL { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
FILL: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 1204 | 105 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1205 | 105 | my $items = $self->{items}; | |||||||||||||||||||||||||||||||||||||||||
| 1206 | 105 | ▶ | while (@$items) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1207 | 112 | my $it = $items->[0]; | |||||||||||||||||||||||||||||||||||||||||
| 1208 | 112 | ▶ | unless (ref $it) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1209 | 105 | shift @$items; | |||||||||||||||||||||||||||||||||||||||||
| 1210 | 105 | ▶ | return $it if length $it; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1211 | 5 | next; | |||||||||||||||||||||||||||||||||||||||||
| 1212 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1213 | 7 | my $n = read $it->{fh}, my $chunk, 65536; | |||||||||||||||||||||||||||||||||||||||||
| 1214 | 7 | ▶ | return $chunk if $n; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1215 | 2 | close $it->{fh}; | |||||||||||||||||||||||||||||||||||||||||
| 1216 | 2 | shift @$items; | |||||||||||||||||||||||||||||||||||||||||
| 1217 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1218 | # uncoverable statement | ||||||||||||||||||||||||||||||||||||||||||
| 1219 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 1220 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1221 | |||||||||||||||||||||||||||||||||||||||||||
| 1222 | # The psgi.streaming writer handed to a delayed response. | ||||||||||||||||||||||||||||||||||||||||||
| 1223 | package | ||||||||||||||||||||||||||||||||||||||||||
| 1224 | Punk::Test::_Writer; | ||||||||||||||||||||||||||||||||||||||||||
| 1225 | 49 | ▶ | sub new { bless { w => $_[1], c => $_[2] }, $_[0] } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1226 | 103 | ▶ | sub write { $_[0]{w}->($_[1]) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
write: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1227 | 42 | ▶ | sub close { ${ $_[0]{c} } = 1 } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
close: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1228 | |||||||||||||||||||||||||||||||||||||||||||
| 1229 | package Punk::Test; | ||||||||||||||||||||||||||||||||||||||||||
| 1230 | |||||||||||||||||||||||||||||||||||||||||||
| 1231 | 56 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 1232 | |||||||||||||||||||||||||||||||||||||||||||
| 1233 | __END__ | ||||||||||||||||||||||||||||||||||||||||||