| 1 | package OpenSearch::PPLQuery::Connection; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 27 | $OpenSearch::PPLQuery::Connection::VERSION = '1.1.0'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # Internal connection-header parser and source merger for bin/pplquery. The | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # functions intentionally retain source-specific behavior: query headers can | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # select a connection, while --connection-file is an explicitly selected, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # standalone connection source. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | # resolve_connection is the entry point. It reads the query and its metadata, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | # merges every connection source, and is the one sequence both bin/pplquery | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | # and the tests run, so the order errors are reported in cannot drift. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 27 | ▶ | use v5.36; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 27 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 27 | ▶ | use File::Basename qw(dirname); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 27 | ▶ | use File::Spec (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 27 | ▶ | use OpenSearch::PPLQuery (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 27 | my $SEPARATOR_HELP = "Add a line containing nothing, or only spaces and tabs, between the last header field and the query.\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 27 | my $LINE_ENDING_HELP = "Save the file with LF or CRLF line endings; a lone CR is not a line ending here.\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 146 | ▶ | sub resolve_connection { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
resolve_connection: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 146 | my ($cli, $connection_file, $source, $stdin) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 146 | my $selected = defined $connection_file; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 146 | ▶ | my $header = $selected ? read_connection_file($connection_file) : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 135 | my ($query, $query_header) = read_query($source, $stdin, $selected); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 77 | ▶ | if ($query !~ /\S/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 3 | ▶ | die 'Query is empty: ' . ($source eq '-' ? 'standard input' : "query file $source") . " has no PPL text.\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | . "A connection header and its separator line are metadata, not query text.\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 74 | ▶ | return ($query, direct_connection($cli, $selected ? $header : $query_header, $selected)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 135 | ▶ | sub read_query { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_query: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 135 | my ($path, $stdin, $strip_lax_header) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 135 | my ($query, $directory); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 135 | ▶ | if ($path eq '-') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 129 | $query = read_utf8_handle($stdin, 'standard input'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 128 | $directory = File::Spec->rel2abs('.'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 6 | $query = read_utf8_file($path, "query file $path"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 5 | $directory = File::Spec->rel2abs(dirname($path)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 133 | ▶ | return (strip_query_header_lax($query), undef) if $strip_lax_header; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 113 | return parse_query_header($query, $directory); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 31 | ▶ | sub read_connection_file { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_connection_file: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 31 | my ($path) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 31 | my $text = read_utf8_file($path, "connection file $path"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | # Normalizing the end of the file covers every way it can terminate, so | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | # the parser below only ever sees a header followed by a blank line. A | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | # bare CR that matters is still rejected on the sentinel or field line. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 29 | $text =~ s/[ \t\r\n]+\z//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 29 | $text .= "\n\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 29 | my ($body, $header) = parse_query_header($text, File::Spec->rel2abs(dirname($path)), 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 21 | ▶ | if ($body =~ /\S/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 1 | my ($first) = $body =~ /^[ \t]*(\S.*?)[ \t]*$/m; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 1 | ▶ | die "Connection file $path must contain only one connection header and whitespace, but text follows its separator line: " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$first // ""
MC/DC0%0/1
$first // ""
$first
Truth table50%1/2
A
A= $first
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | . OpenSearch::PPLQuery::terminal_text($first // '') . "\nA connection file holds no query. Move the query to its own file.\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 20 | return $header; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 52 | ▶ | sub read_utf8_file { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_utf8_file: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 52 | my ($path, $label) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 52 | ▶ | open my $handle, '<:raw', $path or die "Cannot open $label: $!\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 48 | my $text = read_utf8_handle($handle, $label); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 45 | ▶ | close $handle or die "Cannot close $label: $!\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 45 | return $text; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 177 | ▶ | sub read_utf8_handle { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_utf8_handle: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 177 | my ($handle, $label) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 177 | return OpenSearch::PPLQuery::decode_utf8(read_octets_handle($handle, $label), $label); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 177 | ▶ | sub read_octets_handle { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_octets_handle: called CC=4 SCAR=15.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 177 | my ($handle, $label) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 177 | my $octets = do { local $/; <$handle> }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 177 | ▶ | die "Cannot read $label: $!\n" if !defined($octets) && $!; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $octets and $!
MC/DC0%0/2
not defined $octets and $!
not defined $octets
$!
Truth table33%1/3
not(A) and B
A= not defined $octetsB= $!
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 177 | ▶ | return $octets // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$octets // ""
MC/DC0%0/1
$octets // ""
$octets
Truth table50%1/2
A
A= $octets
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 142 | ▶ | sub parse_query_header { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_query_header: called CC=28 SCAR=33.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 142 | my ($query, $directory, $required) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 142 | ▶ | if ($query =~ /\A\/\/ pplquery[ \t]*\r(?!\n)/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 2 | die "The pplquery header uses an unsupported bare CR line ending on line 1\n$LINE_ENDING_HELP"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 140 | ▶ | if ($query !~ /\A\/\/ pplquery[ \t]*\r?\n/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 23 | ▶ | die "The pplquery header requires a blank separator line, but the input ends at the sentinel.\n$SEPARATOR_HELP" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | if $query =~ /\A\/\/ pplquery[ \t]*\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 23 | ▶ | die "Connection file must begin with a complete pplquery header sentinel.\nLine 1 must be exactly '// pplquery'.\n" if $required; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 22 | reject_misplaced_sentinel($query); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 19 | return ($query, undef); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 117 | my $offset = $+[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 117 | my $number = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 117 | my @field_lines; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 117 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 330 | my $newline = index($query, "\n", $offset); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 330 | $number++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | # $number has already advanced to the line that does not exist, so the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | # last line actually read is the one worth naming. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 330 | ▶ | die 'The pplquery header requires a blank separator line, but the input ended at line ' . ($number - 1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | . " while still inside the header.\n$SEPARATOR_HELP" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | if $newline < 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 328 | my $line = substr($query, $offset, $newline - $offset); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 328 | $offset = $newline + 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 328 | $line =~ s/\r\z//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 328 | ▶ | die "The pplquery header uses an unsupported bare CR line ending on line $number\n$LINE_ENDING_HELP" if $line =~ /\r/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 328 | ▶ | last if $line =~ /\A[ \t]*\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 213 | push @field_lines, [$number, $line]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 115 | my @supported = qw(url user password-environment password-file ca-file tls-verify timeout); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 115 | my %supported = map { $_ => 1 } @supported; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 115 | my %header; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 115 | for my $field_line (@field_lines) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 209 | my ($line_number, $line) = @$field_line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 209 | my $shown = 'line ' . $line_number . ': ' . OpenSearch::PPLQuery::terminal_text($line); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 209 | ▶ | if ($line !~ /\A\/\/ ([a-z][a-z0-9-]*):(.*)\z/s) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 11 | ▶ | if ($line =~ /\A\/\/ ([^:]*):/s) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 4 | ▶ | die "Header field key must contain only ASCII characters, on $shown\n" if $1 =~ /[^\x00-\x7f]/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 3 | ▶ | die "Header field key must be lowercase, on $shown\n" if $1 =~ /[A-Z]/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 9 | die "Malformed pplquery header field on $shown\nEvery header line must be written exactly '// key: value', with one space after the slashes and no space before the colon.\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 198 | my ($key, $value) = ($1, $2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 198 | ▶ | die "Unknown pplquery header field '$key' on $shown\nSupported fields are " . join(', ', @supported) . ".\n" if !$supported{$key}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 192 | ▶ | die "Duplicate pplquery header field '$key' on $shown\nIt was already given earlier in this header; keep only one.\n" if exists $header{$key}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 190 | $value =~ s/\A[ \t]+//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 190 | $value =~ s/[ \t]+\z//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 190 | ▶ | die "Header field '$key' must not be empty, on $shown\nGive it a value, or remove the line to fall back to the next connection source.\n" if $value eq ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 182 | ▶ | die "Header field 'password-environment' must name PPLQUERY_[A-Z][A-Z0-9_]*, not '" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$key eq "password-environment" and not $value =~ /\APPLQUERY_[A-Z][A-Z0-9_]*\z/u
MC/DC100%2/2
$key eq "password-environment" and not $value =~ /\APPLQUERY_[A-Z][A-Z0-9_]*\z/u
$key eq "password-environment"
not $value =~ /\APPLQUERY_[A-Z][A-Z0-9_]*\z/u
Truth table100%3/3
A and not(B)
A= $key eq "password-environment"B= not $value =~ /\APPLQUERY_[A-Z][A-Z0-9_]*\z/u
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | . OpenSearch::PPLQuery::terminal_text($value) . "', on $shown\nIt names the environment variable holding the password, never the password itself.\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | if $key eq 'password-environment' && $value !~ /\APPLQUERY_[A-Z][A-Z0-9_]*\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 177 | ▶ | die "Header field 'tls-verify' must be exactly 'true' or 'false', not '" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$key eq "tls-verify" and $value ne "true" and $value ne "false"
$key eq "tls-verify" and $value ne "true"
MC/DC100%3/3
$key eq "tls-verify" and $value ne "true" and $value ne "false"
$key eq "tls-verify"
$value ne "true"
$value ne "false"
Truth table100%4/4
A and B and C
A= $key eq "tls-verify"B= $value ne "true"C= $value ne "false"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | . OpenSearch::PPLQuery::terminal_text($value) . "', on $shown\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | if $key eq 'tls-verify' && $value ne 'true' && $value ne 'false'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 171 | ▶ | OpenSearch::PPLQuery::validate_timeout($value, "Header field 'timeout' on $shown") if $key eq 'timeout'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 163 | ▶ | $header{$key} = $key eq 'timeout' ? 0 + $value : $value; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | die "Header fields 'password-environment' and 'password-file' are mutually exclusive; specify only one\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 69 | ▶ | if exists($header{'password-environment'}) && exists($header{'password-file'}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
exists $header{"password-environment"} and exists $header{"password-file"}
MC/DC100%2/2
exists $header{"password-environment"} and exists $header{"password-file"}
exists $header{"password-environment"}
exists $header{"password-file"}
Truth table100%3/3
A and B
A= exists $header{"password-environment"}B= exists $header{"password-file"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 68 | for my $key (qw(password-file ca-file)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 136 | ▶ | next if !exists($header{$key}) || File::Spec->file_name_is_absolute($header{$key}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not exists $header{$key} or "File::Spec"->file_name_is_absolute($header{$key})
MC/DC100%2/2
not exists $header{$key} or "File::Spec"->file_name_is_absolute($header{$key})
not exists $header{$key}
"File::Spec"->file_name_is_absolute($header{$key})
Truth table100%3/3
not(A) or B
A= not exists $header{$key}B= "File::Spec"->file_name_is_absolute($header{$key})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 13 | $header{$key} = File::Spec->rel2abs($header{$key}, $directory); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 68 | validate_header_connection(\%header); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 60 | my $remainder = substr($query, $offset); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 60 | reject_misplaced_sentinel($remainder, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 59 | return ($remainder, \%header); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 20 | ▶ | sub strip_query_header_lax { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
strip_query_header_lax: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 20 | my ($query) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 20 | ▶ | return $query if $query !~ /\A\/\/ pplquery[ \t]*\r?\n.*?^[ \t]*\r?\n/ms; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 4 | return substr($query, $+[0]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | # One validation of the header as a whole. A header that omits url is checked | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | # against a placeholder https URL, so its other fields are still validated | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | # individually; the password fields are not client options and take no part. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 68 | ▶ | sub validate_header_connection { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
validate_header_connection: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 68 | my ($header) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | OpenSearch::PPLQuery::validate_options({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | url => $header->{url} // 'https://header-validation.invalid', timeout => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | (exists($header->{user}) ? (user => $header->{user}, password => 'validation') : ()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | (exists($header->{'ca-file'}) ? (ca_file => $header->{'ca-file'}) : ()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 68 | ▶ | (exists($header->{'tls-verify'}) && $header->{'tls-verify'} eq 'false' ? (insecure => 1) : ()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition100%5/5
$header->{"url"} // "https://header-validation.invalid"
exists $header->{"tls-verify"} and $header->{"tls-verify"} eq "false"
MC/DC100%1/1
$header->{"url"} // "https://header-validation.invalid"
$header->{"url"}
MC/DC100%2/2
exists $header->{"tls-verify"} and $header->{"tls-verify"} eq "false"
exists $header->{"tls-verify"}
$header->{"tls-verify"} eq "false"
Truth table100%2/2
A
A= $header->{"url"}
Truth table100%3/3
A and B
A= exists $header->{"tls-verify"}B= $header->{"tls-verify"} eq "false"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 82 | ▶ | sub reject_misplaced_sentinel { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
reject_misplaced_sentinel: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 82 | my ($query, $after_header) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 82 | ▶ | die "The pplquery sentinel cannot have leading whitespace and must appear on line 1\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | . "Move '// pplquery' to the very start of the input, with nothing before it.\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | if $query =~ /(?:\A|\n)[ \t]+\/\/ pplquery[ \t]*(?=\r?(?:\n|\z))/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 81 | ▶ | if ($query =~ /(?:\A|\n)\/\/ pplquery[ \t]*(?=\r?(?:\n|\z))/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 3 | ▶ | die $after_header | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | ? "A repeated pplquery sentinel is not allowed later in the query\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | . "One connection header is permitted, at the top of the input.\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | : "The pplquery sentinel must appear on line 1\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | . "A '// pplquery' line anywhere else is refused so that connection metadata cannot hide further down a query.\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 120 | ▶ | sub direct_connection { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
direct_connection: called CC=42 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 120 | my ($cli, $header, $connection_file_selected) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 120 | ▶ | $header //= {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$header //= {}
MC/DC100%1/1
$header //= {}
$header
Truth table100%2/2
A
A= $header
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 120 | ▶ | my $header_url_selected = !$connection_file_selected && !defined($cli->{url}) && exists($header->{url}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%6/6
!($connection_file_selected || defined $cli->{'url'}) && exists $header->{'url'}
$connection_file_selected || defined $cli->{'url'}
MC/DC100%3/3
!($connection_file_selected || defined $cli->{'url'}) && exists $header->{'url'}
$connection_file_selected
defined $cli->{'url'}
exists $header->{'url'}
Truth table100%4/4
not(A || B) && C
A= $connection_file_selectedB= defined $cli->{'url'}C= exists $header->{'url'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | my $url = defined($cli->{url}) ? $cli->{url} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | : exists($header->{url}) ? $header->{url} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 120 | ▶ | : environment_nonempty('PPLQUERY_URL'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | my $user = defined($cli->{user}) ? $cli->{user} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | : exists($header->{user}) ? $header->{user} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 119 | ▶ | : !$header_url_selected ? environment_nonempty('PPLQUERY_USER') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | # A query header decides transport trust only for a URL it selected | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | # itself. A connection file is exempt: the operator chose it explicitly. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | # A header field the command line overrides is never applied, so there is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | # nothing to refuse. Checked before any password source is resolved, so a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | # header that fails here never causes a secret to be read. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 118 | ▶ | my $header_owns_tls = $connection_file_selected || $header_url_selected; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$connection_file_selected || $header_url_selected
MC/DC100%2/2
$connection_file_selected || $header_url_selected
$connection_file_selected
$header_url_selected
Truth table100%3/3
A || B
A= $connection_file_selectedB= $header_url_selected
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 118 | my $trust_help = "Give the header its own 'url' field so it controls the endpoint it is changing trust for, move the setting to the command line, or select the connection with --connection-file.\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | die "A query header may not choose the CA for a URL it does not select.\n$trust_help" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 118 | ▶ | if !$header_owns_tls && !defined($cli->{ca_file}) && exists $header->{'ca-file'}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
not $header_owns_tls || defined $cli->{"ca_file"} and exists $header->{"ca-file"}
$header_owns_tls || defined $cli->{'ca_file'}
MC/DC100%3/3
not $header_owns_tls || defined $cli->{"ca_file"} and exists $header->{"ca-file"}
$header_owns_tls
defined $cli->{'ca_file'}
exists $header->{"ca-file"}
Truth table100%4/4
not(A || B) and C
A= $header_owns_tlsB= defined $cli->{'ca_file'}C= exists $header->{"ca-file"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | die "A query header may not disable TLS verification for a URL it does not select.\n$trust_help" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | if !$header_owns_tls && !defined($cli->{insecure}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 117 | ▶ | && exists($header->{'tls-verify'}) && $header->{'tls-verify'} eq 'false'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%9/9
not $header_owns_tls || defined $cli->{"insecure"} and exists $header->{"tls-verify"} and $header->{"tls-verify"} eq "false"
not $header_owns_tls || defined $cli->{"insecure"} and exists $header->{"tls-verify"}
$header_owns_tls || defined $cli->{'insecure'}
MC/DC100%4/4
not $header_owns_tls || defined $cli->{"insecure"} and exists $header->{"tls-verify"} and $header->{"tls-verify"} eq "false"
$header_owns_tls
defined $cli->{'insecure'}
exists $header->{"tls-verify"}
$header->{"tls-verify"} eq "false"
Truth table100%5/5
not(A || B) and C and D
A= $header_owns_tlsB= defined $cli->{'insecure'}C= exists $header->{"tls-verify"}D= $header->{"tls-verify"} eq "false"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 115 | my ($password, $password_file); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 115 | ▶ | if (defined $cli->{password_file}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 4 | $password_file = $cli->{password_file}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | } elsif (exists $header->{'password-environment'}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 13 | my $name = $header->{'password-environment'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | die "$name must be set for header password-environment, but it is not present in the environment.\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | . "The header names it as the password source, so no other source is tried. Export $name, or point the header at a variable that is set.\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 13 | ▶ | if !exists $ENV{$name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 11 | $password = environment_nonempty($name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | } elsif (exists $header->{'password-file'}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 10 | $password_file = $header->{'password-file'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | } elsif (!$header_url_selected) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 81 | $password = environment_nonempty('PPLQUERY_PASSWORD'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 80 | $password_file = environment_nonempty('PPLQUERY_PASSWORD_FILE'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 79 | ▶ | die "PPLQUERY_PASSWORD and PPLQUERY_PASSWORD_FILE cannot both be set; use one password source\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $password and defined $password_file
MC/DC100%2/2
defined $password and defined $password_file
defined $password
defined $password_file
Truth table100%3/3
A and B
A= defined $passwordB= defined $password_file
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | if defined($password) && defined($password_file); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 109 | ▶ | if (defined($user) != (defined($password) || defined($password_file))) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $password || defined $password_file
MC/DC100%2/2
defined $password || defined $password_file
defined $password
defined $password_file
Truth table100%3/3
A || B
A= defined $passwordB= defined $password_file
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 11 | ▶ | my $isolation = $header_url_selected | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | ? "The query header selected the URL, so PPLQUERY_USER, PPLQUERY_PASSWORD, and PPLQUERY_PASSWORD_FILE are deliberately not used for it. Supply both halves in the header, or take control of the URL with --url.\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 11 | ▶ | die defined($user) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | ? "Basic-auth username and password must be set together, but only a username was supplied.\n${isolation}Add a password with --password-file, a 'password-environment' or 'password-file' header field, PPLQUERY_PASSWORD, or PPLQUERY_PASSWORD_FILE.\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | : "Basic-auth username and password must be set together, but only a password was supplied.\n${isolation}Add a username with --user, a 'user' header field, or PPLQUERY_USER.\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 98 | ▶ | $password = read_password_file($password_file) if defined $password_file; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | my $ca_file = defined($cli->{ca_file}) ? $cli->{ca_file} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 92 | ▶ | : exists($header->{'ca-file'}) ? $header->{'ca-file'} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | : environment_nonempty('PPLQUERY_CA_FILE'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 91 | my $insecure = $cli->{insecure}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 91 | ▶ | if (!defined $insecure) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | my $tls_verify = exists($header->{'tls-verify'}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 88 | ▶ | ? $header->{'tls-verify'} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | : environment_nonempty('PPLQUERY_TLS_VERIFY'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 87 | ▶ | if (defined $tls_verify) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 21 | ▶ | die "PPLQUERY_TLS_VERIFY must be exactly 'true' or 'false', not '" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$tls_verify ne "true" and $tls_verify ne "false"
MC/DC100%2/2
$tls_verify ne "true" and $tls_verify ne "false"
$tls_verify ne "true"
$tls_verify ne "false"
Truth table100%3/3
A and B
A= $tls_verify ne "true"B= $tls_verify ne "false"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | . OpenSearch::PPLQuery::terminal_text($tls_verify) . "'\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | if $tls_verify ne 'true' && $tls_verify ne 'false'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 13 | ▶ | $insecure = $tls_verify eq 'false' ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 82 | my $timeout = $cli->{timeout}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 82 | ▶ | if (!defined $timeout) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 78 | ▶ | if (exists $header->{timeout}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 7 | $timeout = $header->{timeout}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 71 | $timeout = environment_nonempty('PPLQUERY_TIMEOUT'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 70 | ▶ | $timeout = OpenSearch::PPLQuery::validate_timeout($timeout, 'PPLQUERY_TIMEOUT') if defined $timeout; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 72 | ▶ | my %connection = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%4/4
$url // "http://127.0.0.1:9200"
$timeout // 60
MC/DC100%1/1
$url // "http://127.0.0.1:9200"
$url
MC/DC100%1/1
$timeout // 60
$timeout
Truth table100%2/2
A
A= $url
Truth table100%2/2
A
A= $timeout
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | url => $url // 'http://127.0.0.1:9200', timeout => $timeout // 60, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | user => $user, password => $password, ca_file => $ca_file, insecure => $insecure, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 72 | delete @connection{grep { !defined $connection{$_} } keys %connection}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 72 | return \%connection; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 15 | ▶ | sub read_password_file { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_password_file: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 15 | my ($path) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 15 | my $password = read_utf8_file($path, "password file $path"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | # Trailing line endings are a property of how the file was written, never | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | # of the password. Trailing spaces may be part of it, so they stay. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 11 | $password =~ s/[\r\n]+\z//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 11 | ▶ | die "Password file $path must not be empty\n" if $password eq ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 10 | ▶ | die "Password file $path must contain a single line, but it holds a line break or control character.\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | . "Trailing line endings are removed automatically; a file with more than one line is a mistake rather than a multi-line password.\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | if $password =~ /[\x00-\x1f\x7f]/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 9 | return $password; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 552 | ▶ | sub environment_text { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
environment_text: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 552 | my ($name) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 552 | ▶ | return undef if !exists $ENV{$name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 125 | return OpenSearch::PPLQuery::decode_utf8($ENV{$name}, "environment variable $name"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 552 | ▶ | sub environment_nonempty { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
environment_nonempty: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 552 | my ($name) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 552 | my $value = environment_text($name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 552 | ▶ | die "$name must not be empty. Unset it entirely to fall back to the next connection source, or give it a value.\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $value and $value eq ""
MC/DC100%2/2
defined $value and $value eq ""
defined $value
$value eq ""
Truth table100%3/3
A and B
A= defined $valueB= $value eq ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | if defined($value) && $value eq ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 544 | return $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 27 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||