| 1 | # Copyright 2014 - present MongoDB, Inc. | ||||||||||||||||||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||||||||||||||||||
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); | ||||||||||||||||||||||||||||||||||||||
| 4 | # you may not use this file except in compliance with the License. | ||||||||||||||||||||||||||||||||||||||
| 5 | # You may obtain a copy of the License at | ||||||||||||||||||||||||||||||||||||||
| 6 | # | ||||||||||||||||||||||||||||||||||||||
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 | ||||||||||||||||||||||||||||||||||||||
| 8 | # | ||||||||||||||||||||||||||||||||||||||
| 9 | # Unless required by applicable law or agreed to in writing, software | ||||||||||||||||||||||||||||||||||||||
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, | ||||||||||||||||||||||||||||||||||||||
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||||||||||||||||||||||||||||||||||
| 12 | # See the License for the specific language governing permissions and | ||||||||||||||||||||||||||||||||||||||
| 13 | # limitations under the License. | ||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||
| 15 | 60 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 16 | 60 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||
| 18 | package MongoDB::_Credential; | ||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||
| 20 | 60 | ▶ | use version; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 21 | 60 | our $VERSION = 'v2.2.2'; | |||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||
| 23 | 60 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 24 | 60 | ▶ | use MongoDB::Error; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 25 | 60 | ▶ | use MongoDB::Op::_Command; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 26 | 60 | ▶ | use MongoDB::_Types qw( | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 27 | AuthMechanism | ||||||||||||||||||||||||||||||||||||||
| 28 | NonEmptyStr | ||||||||||||||||||||||||||||||||||||||
| 29 | 60 | ); | |||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||
| 31 | 60 | ▶ | use Digest::MD5 qw/md5_hex/; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 32 | 60 | ▶ | use Encode qw/encode/; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 33 | 60 | ▶ | use MIME::Base64 qw/encode_base64 decode_base64/; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 34 | 60 | ▶ | use Safe::Isa; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 35 | 60 | ▶ | use Tie::IxHash; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 36 | 60 | ▶ | use MongoDB::_Types qw( | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 37 | Boolish | ||||||||||||||||||||||||||||||||||||||
| 38 | 60 | ); | |||||||||||||||||||||||||||||||||||||
| 39 | 60 | ▶ | use Types::Standard qw( | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 40 | CodeRef | ||||||||||||||||||||||||||||||||||||||
| 41 | HashRef | ||||||||||||||||||||||||||||||||||||||
| 42 | InstanceOf | ||||||||||||||||||||||||||||||||||||||
| 43 | Maybe | ||||||||||||||||||||||||||||||||||||||
| 44 | Str | ||||||||||||||||||||||||||||||||||||||
| 45 | 60 | ); | |||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||
| 47 | 60 | ▶ | use namespace::clean -except => 'meta'; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||
| 49 | # Required so we're sure it's passed explicitly, even if undef, so we don't | ||||||||||||||||||||||||||||||||||||||
| 50 | # miss wiring it up. | ||||||||||||||||||||||||||||||||||||||
| 51 | 60 | has monitoring_callback => ( | |||||||||||||||||||||||||||||||||||||
| 52 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||
| 53 | required => 1, | ||||||||||||||||||||||||||||||||||||||
| 54 | isa => Maybe[CodeRef], | ||||||||||||||||||||||||||||||||||||||
| 55 | ); | ||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||
| 57 | 60 | has mechanism => ( | |||||||||||||||||||||||||||||||||||||
| 58 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||
| 59 | isa => AuthMechanism, | ||||||||||||||||||||||||||||||||||||||
| 60 | required => 1, | ||||||||||||||||||||||||||||||||||||||
| 61 | ); | ||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||
| 63 | 60 | has username => ( | |||||||||||||||||||||||||||||||||||||
| 64 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||
| 65 | isa => Str, | ||||||||||||||||||||||||||||||||||||||
| 66 | ); | ||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||
| 68 | 60 | has source => ( | |||||||||||||||||||||||||||||||||||||
| 69 | is => 'lazy', | ||||||||||||||||||||||||||||||||||||||
| 70 | isa => NonEmptyStr, | ||||||||||||||||||||||||||||||||||||||
| 71 | builder => '_build_source', | ||||||||||||||||||||||||||||||||||||||
| 72 | ); | ||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||
| 74 | 60 | has db_name => ( | |||||||||||||||||||||||||||||||||||||
| 75 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||
| 76 | isa => Str, | ||||||||||||||||||||||||||||||||||||||
| 77 | ); | ||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||
| 79 | 60 | has password => ( | |||||||||||||||||||||||||||||||||||||
| 80 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||
| 81 | isa => Str, | ||||||||||||||||||||||||||||||||||||||
| 82 | ); | ||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||
| 84 | 60 | has pw_is_digest => ( | |||||||||||||||||||||||||||||||||||||
| 85 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||
| 86 | isa => Boolish, | ||||||||||||||||||||||||||||||||||||||
| 87 | ); | ||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||
| 89 | has mechanism_properties => ( | ||||||||||||||||||||||||||||||||||||||
| 90 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||
| 91 | isa => HashRef, | ||||||||||||||||||||||||||||||||||||||
| 92 | 157 | ▶ | default => sub { {} }, | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 93 | 60 | ); | |||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||
| 95 | 60 | has _digested_password => ( | |||||||||||||||||||||||||||||||||||||
| 96 | is => 'lazy', | ||||||||||||||||||||||||||||||||||||||
| 97 | isa => Str, | ||||||||||||||||||||||||||||||||||||||
| 98 | builder => '_build__digested_password', | ||||||||||||||||||||||||||||||||||||||
| 99 | ); | ||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||
| 101 | 60 | has _scram_sha1_client => ( | |||||||||||||||||||||||||||||||||||||
| 102 | is => 'lazy', | ||||||||||||||||||||||||||||||||||||||
| 103 | isa => InstanceOf ['Authen::SCRAM::Client'], | ||||||||||||||||||||||||||||||||||||||
| 104 | builder => '_build__scram_sha1_client', | ||||||||||||||||||||||||||||||||||||||
| 105 | ); | ||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||
| 107 | 60 | has _scram_sha256_client => ( | |||||||||||||||||||||||||||||||||||||
| 108 | is => 'lazy', | ||||||||||||||||||||||||||||||||||||||
| 109 | isa => InstanceOf ['Authen::SCRAM::Client'], | ||||||||||||||||||||||||||||||||||||||
| 110 | builder => '_build__scram_sha256_client', | ||||||||||||||||||||||||||||||||||||||
| 111 | ); | ||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||
| 113 | 0 | ▶ | sub _build__scram_sha1_client { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_build__scram_sha1_client: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 114 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||
| 115 | # loaded only demand as it has a long load time relative to other | ||||||||||||||||||||||||||||||||||||||
| 116 | # modules | ||||||||||||||||||||||||||||||||||||||
| 117 | 0 | require Authen::SCRAM::Client; | |||||||||||||||||||||||||||||||||||||
| 118 | 0 | Authen::SCRAM::Client->VERSION(0.011); | |||||||||||||||||||||||||||||||||||||
| 119 | 0 | return Authen::SCRAM::Client->new( | |||||||||||||||||||||||||||||||||||||
| 120 | username => $self->username, | ||||||||||||||||||||||||||||||||||||||
| 121 | password => $self->_digested_password, | ||||||||||||||||||||||||||||||||||||||
| 122 | digest => 'SHA-1', | ||||||||||||||||||||||||||||||||||||||
| 123 | minimum_iteration_count => 4096, | ||||||||||||||||||||||||||||||||||||||
| 124 | skip_saslprep => 1, | ||||||||||||||||||||||||||||||||||||||
| 125 | ); | ||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||
| 128 | 0 | ▶ | sub _build__scram_sha256_client { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_build__scram_sha256_client: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 129 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||
| 130 | # loaded only demand as it has a long load time relative to other | ||||||||||||||||||||||||||||||||||||||
| 131 | # modules | ||||||||||||||||||||||||||||||||||||||
| 132 | 0 | require Authen::SCRAM::Client; | |||||||||||||||||||||||||||||||||||||
| 133 | 0 | Authen::SCRAM::Client->VERSION(0.007); | |||||||||||||||||||||||||||||||||||||
| 134 | 0 | require Authen::SASL::SASLprep; | |||||||||||||||||||||||||||||||||||||
| 135 | 0 | return Authen::SCRAM::Client->new( | |||||||||||||||||||||||||||||||||||||
| 136 | username => $self->username, | ||||||||||||||||||||||||||||||||||||||
| 137 | password => Authen::SASL::SASLprep::saslprep($self->password), | ||||||||||||||||||||||||||||||||||||||
| 138 | digest => 'SHA-256', | ||||||||||||||||||||||||||||||||||||||
| 139 | minimum_iteration_count => 4096, | ||||||||||||||||||||||||||||||||||||||
| 140 | skip_saslprep => 1, | ||||||||||||||||||||||||||||||||||||||
| 141 | ); | ||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||
| 144 | 0 | ▶ | sub _build__digested_password { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_build__digested_password: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||
| 145 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||
| 146 | 0 | ▶ | return $self->password if $self->pw_is_digest; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 147 | 0 | return md5_hex( encode( "UTF-8", $self->username . ":mongo:" . $self->password ) ); | |||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||
| 150 | 21 | ▶ | sub _build_source { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_source: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||
| 151 | 21 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||
| 152 | 21 | my $mech = $self->mechanism; | |||||||||||||||||||||||||||||||||||||
| 153 | 21 | ▶ | if ( $mech eq 'PLAIN' ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 154 | 2 | ▶ | return $self->db_name // '$external'; | ||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->db_name // "\$external"
MC/DC100%1/1
$self->db_name // "\$external"
$self->db_name
Truth table100%2/2
A
A= $self->db_name
| |||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||
| 156 | 19 | ▶ | return $mech eq 'MONGODB-X509' | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%5/5
$mech eq "MONGODB-X509" or $mech eq "GSSAPI"
$self->db_name // "admin"
MC/DC100%2/2
$mech eq "MONGODB-X509" or $mech eq "GSSAPI"
$mech eq "MONGODB-X509"
$mech eq "GSSAPI"
MC/DC100%1/1
$self->db_name // "admin"
$self->db_name
Truth table100%3/3
A or B
A= $mech eq "MONGODB-X509"B= $mech eq "GSSAPI"
Truth table100%2/2
A
A= $self->db_name
| |||||||||||||||||||||||||||||||||||||||
| 157 | || $mech eq 'GSSAPI' ? '$external' : $self->db_name // 'admin'; | ||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||
| 160 | #<<< No perltidy | ||||||||||||||||||||||||||||||||||||||
| 161 | my %CONSTRAINTS = ( | ||||||||||||||||||||||||||||||||||||||
| 162 | 'MONGODB-CR' => { | ||||||||||||||||||||||||||||||||||||||
| 163 | 3 | ▶ | username => sub { length }, | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 164 | 4 | ▶ | password => sub { defined }, | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 165 | 3 | ▶ | source => sub { length }, | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 166 | 4 | ▶ | mechanism_properties => sub { !keys %$_ }, | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 167 | }, | ||||||||||||||||||||||||||||||||||||||
| 168 | 'MONGODB-X509' => { | ||||||||||||||||||||||||||||||||||||||
| 169 | 6 | ▶ | password => sub { ! defined }, | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 170 | 5 | ▶ | source => sub { $_ eq '$external' }, | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 171 | 6 | ▶ | mechanism_properties => sub { !keys %$_ }, | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 172 | }, | ||||||||||||||||||||||||||||||||||||||
| 173 | 'GSSAPI' => { | ||||||||||||||||||||||||||||||||||||||
| 174 | 8 | ▶ | username => sub { length }, | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 175 | 9 | ▶ | source => sub { $_ eq '$external' }, | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 176 | }, | ||||||||||||||||||||||||||||||||||||||
| 177 | 'PLAIN' => { | ||||||||||||||||||||||||||||||||||||||
| 178 | 3 | ▶ | username => sub { length }, | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 179 | 4 | ▶ | password => sub { defined }, | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 180 | 3 | ▶ | source => sub { length }, | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 181 | 4 | ▶ | mechanism_properties => sub { !keys %$_ }, | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 182 | }, | ||||||||||||||||||||||||||||||||||||||
| 183 | 'SCRAM-SHA-1' => { | ||||||||||||||||||||||||||||||||||||||
| 184 | 3 | ▶ | username => sub { length }, | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 185 | 4 | ▶ | password => sub { defined }, | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 186 | 3 | ▶ | source => sub { length }, | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 187 | 4 | ▶ | mechanism_properties => sub { !keys %$_ }, | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 188 | }, | ||||||||||||||||||||||||||||||||||||||
| 189 | 'SCRAM-SHA-256' => { | ||||||||||||||||||||||||||||||||||||||
| 190 | 3 | ▶ | username => sub { length }, | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 191 | 4 | ▶ | password => sub { defined }, | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 192 | 3 | ▶ | source => sub { length }, | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 193 | 4 | ▶ | mechanism_properties => sub { !keys %$_ }, | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 194 | }, | ||||||||||||||||||||||||||||||||||||||
| 195 | 'DEFAULT' => { | ||||||||||||||||||||||||||||||||||||||
| 196 | 5 | ▶ | username => sub { length }, | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 197 | 6 | ▶ | password => sub { defined }, | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 198 | 5 | ▶ | source => sub { length }, | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 199 | 6 | ▶ | mechanism_properties => sub { !keys %$_ }, | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 200 | }, | ||||||||||||||||||||||||||||||||||||||
| 201 | 60 | ); | |||||||||||||||||||||||||||||||||||||
| 202 | #>>> | ||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||
| 204 | 340 | ▶ | sub BUILD { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 205 | 340 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||
| 207 | 340 | my $mech = $self->mechanism; | |||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||
| 209 | # validate attributes for given mechanism | ||||||||||||||||||||||||||||||||||||||
| 210 | 340 | for my $key ( sort keys %{ $CONSTRAINTS{$mech} } ) { | |||||||||||||||||||||||||||||||||||||
| 211 | 112 | my $validator = $CONSTRAINTS{$mech}{$key}; | |||||||||||||||||||||||||||||||||||||
| 212 | 112 | local $_ = $self->$key; | |||||||||||||||||||||||||||||||||||||
| 213 | 112 | ▶ | unless ( $validator->() ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 214 | 9 | ▶ | $_ //= ""; | ||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$_ //= ""
MC/DC100%1/1
$_ //= ""
$_
Truth table100%2/2
A
A= $_
| |||||||||||||||||||||||||||||||||||||||
| 215 | 9 | MongoDB::UsageError->throw("invalid field $key with value '$_' in $mech credential"); | |||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||
| 219 | # fix up GSSAPI property defaults if not given | ||||||||||||||||||||||||||||||||||||||
| 220 | 331 | ▶ | if ( $mech eq 'GSSAPI' ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 221 | 7 | my $mp = $self->mechanism_properties; | |||||||||||||||||||||||||||||||||||||
| 222 | 7 | ▶ | $mp->{SERVICE_NAME} ||= 'mongodb'; | ||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$mp->{"SERVICE_NAME"} ||= "mongodb"
MC/DC100%1/1
$mp->{"SERVICE_NAME"} ||= "mongodb"
$mp->{"SERVICE_NAME"}
Truth table100%2/2
A
A= $mp->{"SERVICE_NAME"}
| |||||||||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||
| 225 | 331 | return; | |||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||
| 228 | 0 | ▶ | sub authenticate { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
authenticate: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 229 | 0 | my ( $self, $server, $link, $bson_codec ) = @_; | |||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||
| 231 | 0 | my $mech = $self->mechanism; | |||||||||||||||||||||||||||||||||||||
| 232 | 0 | ▶ | if ( $mech eq 'DEFAULT' ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 233 | 0 | $mech = $self->_get_default_mechanism($server, $link); | |||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||
| 235 | 0 | my $method = "_authenticate_$mech"; | |||||||||||||||||||||||||||||||||||||
| 236 | 0 | $method =~ s/-/_/g; | |||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||
| 238 | 0 | return $self->$method( $link, $bson_codec ); | |||||||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||
| 241 | #--------------------------------------------------------------------------# | ||||||||||||||||||||||||||||||||||||||
| 242 | # authentication mechanisms | ||||||||||||||||||||||||||||||||||||||
| 243 | #--------------------------------------------------------------------------# | ||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||
| 245 | sub _authenticate_NONE () { 1 } | ||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||
| 247 | 0 | ▶ | sub _authenticate_MONGODB_CR { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_authenticate_MONGODB_CR: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 248 | 0 | my ( $self, $link, $bson_codec ) = @_; | |||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||
| 250 | my $nonce = $self->_send_command( $link, $bson_codec, 'admin', { getnonce => 1 } ) | ||||||||||||||||||||||||||||||||||||||
| 251 | 0 | ->output->{nonce}; | |||||||||||||||||||||||||||||||||||||
| 252 | 0 | my $key = | |||||||||||||||||||||||||||||||||||||
| 253 | md5_hex( encode( "UTF-8", $nonce . $self->username . $self->_digested_password ) ); | ||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||
| 255 | 0 | my $command = Tie::IxHash->new( | |||||||||||||||||||||||||||||||||||||
| 256 | authenticate => 1, | ||||||||||||||||||||||||||||||||||||||
| 257 | user => $self->username, | ||||||||||||||||||||||||||||||||||||||
| 258 | nonce => $nonce, | ||||||||||||||||||||||||||||||||||||||
| 259 | key => $key | ||||||||||||||||||||||||||||||||||||||
| 260 | ); | ||||||||||||||||||||||||||||||||||||||
| 261 | 0 | $self->_send_command( $link, $bson_codec, $self->source, $command ); | |||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||
| 263 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||
| 266 | 0 | ▶ | sub _authenticate_MONGODB_X509 { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_authenticate_MONGODB_X509: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||
| 267 | 0 | my ( $self, $link, $bson_codec ) = @_; | |||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||
| 269 | 0 | my $username = $self->username; | |||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||
| 271 | 0 | ▶ | if ( !$username && !$link->supports_x509_user_from_cert ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$username or $link->supports_x509_user_from_cert
MC/DC0%0/2
$username or $link->supports_x509_user_from_cert
$username
$link->supports_x509_user_from_cert
Truth table0%0/3
A or B
A= $usernameB= $link->supports_x509_user_from_cert
| |||||||||||||||||||||||||||||||||||||||
| 272 | 0 | ▶ | $username = $link->client_certificate_subject | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 273 | or MongoDB::UsageError->throw( | ||||||||||||||||||||||||||||||||||||||
| 274 | "Could not extract subject from client SSL certificate"); | ||||||||||||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||
| 277 | 0 | ▶ | my $command = Tie::IxHash->new( | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 278 | authenticate => 1, | ||||||||||||||||||||||||||||||||||||||
| 279 | mechanism => "MONGODB-X509", | ||||||||||||||||||||||||||||||||||||||
| 280 | ( $username ? ( user => $username ) : () ), | ||||||||||||||||||||||||||||||||||||||
| 281 | ); | ||||||||||||||||||||||||||||||||||||||
| 282 | 0 | $self->_send_command( $link, $bson_codec, $self->source, $command ); | |||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||
| 284 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||
| 287 | 0 | ▶ | sub _authenticate_PLAIN { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_authenticate_PLAIN: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 288 | 0 | my ( $self, $link, $bson_codec ) = @_; | |||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||
| 290 | 0 | my $auth_bytes = | |||||||||||||||||||||||||||||||||||||
| 291 | encode( "UTF-8", "\x00" . $self->username . "\x00" . $self->password ); | ||||||||||||||||||||||||||||||||||||||
| 292 | 0 | $self->_sasl_start( $link, $bson_codec, $auth_bytes, "PLAIN" ); | |||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||
| 294 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||
| 297 | 0 | ▶ | sub _authenticate_GSSAPI { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_authenticate_GSSAPI: not called CC=9 SCAR=45.0
| |||||||||||||||||||||||||||||||||||||||
| 298 | 0 | my ( $self, $link, $bson_codec ) = @_; | |||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||
| 300 | 0 | ▶ | eval { require Authen::SASL; 1 } | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 301 | or MongoDB::AuthError->throw( | ||||||||||||||||||||||||||||||||||||||
| 302 | "GSSAPI requires Authen::SASL and GSSAPI or Authen::SASL::XS from CPAN"); | ||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||
| 304 | 0 | my ( $sasl, $client ); | |||||||||||||||||||||||||||||||||||||
| 305 | eval { | ||||||||||||||||||||||||||||||||||||||
| 306 | 0 | $sasl = Authen::SASL->new( | |||||||||||||||||||||||||||||||||||||
| 307 | mechanism => 'GSSAPI', | ||||||||||||||||||||||||||||||||||||||
| 308 | callback => { | ||||||||||||||||||||||||||||||||||||||
| 309 | user => $self->username, | ||||||||||||||||||||||||||||||||||||||
| 310 | authname => $self->username, | ||||||||||||||||||||||||||||||||||||||
| 311 | }, | ||||||||||||||||||||||||||||||||||||||
| 312 | ); | ||||||||||||||||||||||||||||||||||||||
| 313 | $client = | ||||||||||||||||||||||||||||||||||||||
| 314 | 0 | $sasl->client_new( $self->mechanism_properties->{SERVICE_NAME}, $link->host ); | |||||||||||||||||||||||||||||||||||||
| 315 | 0 | 1; | |||||||||||||||||||||||||||||||||||||
| 316 | 0 | ▶ | } or do { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 317 | 0 | ▶ | my $error = $@ || "Unknown error"; | ||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$@ || 'Unknown error'
MC/DC0%0/1
$@ || 'Unknown error'
$@
Truth table0%0/2
A
A= $@
| |||||||||||||||||||||||||||||||||||||||
| 318 | 0 | MongoDB::AuthError->throw( | |||||||||||||||||||||||||||||||||||||
| 319 | "Failed to initialize a GSSAPI backend (did you install GSSAPI or Authen::SASL::XS?) Error was: $error" | ||||||||||||||||||||||||||||||||||||||
| 320 | ); | ||||||||||||||||||||||||||||||||||||||
| 321 | }; | ||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||
| 323 | eval { | ||||||||||||||||||||||||||||||||||||||
| 324 | # start conversation | ||||||||||||||||||||||||||||||||||||||
| 325 | 0 | my $step = $client->client_start; | |||||||||||||||||||||||||||||||||||||
| 326 | 0 | $self->_assert_gssapi( $client, | |||||||||||||||||||||||||||||||||||||
| 327 | "Could not start GSSAPI. Did you run kinit? Error was: " ); | ||||||||||||||||||||||||||||||||||||||
| 328 | 0 | my ( $sasl_resp, $conv_id, $done ) = | |||||||||||||||||||||||||||||||||||||
| 329 | $self->_sasl_start( $link, $bson_codec, $step, 'GSSAPI' ); | ||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||
| 331 | # iterate, but with maximum number of exchanges to prevent endless loop | ||||||||||||||||||||||||||||||||||||||
| 332 | 0 | for my $i ( 1 .. 10 ) { | |||||||||||||||||||||||||||||||||||||
| 333 | 0 | ▶ | last if $done; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 334 | 0 | $step = $client->client_step($sasl_resp); | |||||||||||||||||||||||||||||||||||||
| 335 | 0 | $self->_assert_gssapi( $client, "GSSAPI step error: " ); | |||||||||||||||||||||||||||||||||||||
| 336 | 0 | ( $sasl_resp, $conv_id, $done ) = | |||||||||||||||||||||||||||||||||||||
| 337 | $self->_sasl_continue( $link, $bson_codec, $step, $conv_id ); | ||||||||||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||||||||||
| 339 | 0 | 1; | |||||||||||||||||||||||||||||||||||||
| 340 | 0 | ▶ | } or do { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 341 | 0 | ▶ | my $error = $@ || "Unknown error"; | ||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$@ || 'Unknown error'
MC/DC0%0/1
$@ || 'Unknown error'
$@
Truth table0%0/2
A
A= $@
| |||||||||||||||||||||||||||||||||||||||
| 342 | 0 | ▶ | my $msg = $error->$_isa("MongoDB::Error") ? $error->message : "$error"; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 343 | 0 | MongoDB::AuthError->throw("GSSAPI error: $msg"); | |||||||||||||||||||||||||||||||||||||
| 344 | }; | ||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||
| 346 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||
| 349 | 0 | ▶ | sub _authenticate_SCRAM_SHA_1 { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_authenticate_SCRAM_SHA_1: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 350 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||
| 352 | 0 | $self->_scram_auth(@_, $self->_scram_sha1_client, 'SCRAM-SHA-1'); | |||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||
| 354 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||
| 357 | 0 | ▶ | sub _authenticate_SCRAM_SHA_256 { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_authenticate_SCRAM_SHA_256: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 358 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||
| 360 | 0 | $self->_scram_auth(@_, $self->_scram_sha256_client, 'SCRAM-SHA-256'); | |||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||
| 362 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||||
| 365 | 0 | ▶ | sub _get_default_mechanism { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_default_mechanism: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||
| 366 | 0 | my ( $self, $server, $link ) = @_; | |||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||
| 368 | 0 | ▶ | if ( my $supported = $server->is_master->{saslSupportedMechs} ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 369 | 0 | ▶ | if ( grep { $_ eq 'SCRAM-SHA-256' } @$supported ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 370 | 0 | return 'SCRAM-SHA-256'; | |||||||||||||||||||||||||||||||||||||
| 371 | } | ||||||||||||||||||||||||||||||||||||||
| 372 | 0 | return 'SCRAM-SHA-1'; | |||||||||||||||||||||||||||||||||||||
| 373 | } | ||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||
| 375 | 0 | ▶ | if ( $link->supports_scram_sha1 ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 376 | 0 | return 'SCRAM-SHA-1'; | |||||||||||||||||||||||||||||||||||||
| 377 | } | ||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||
| 379 | 0 | return 'MONGODB-CR'; | |||||||||||||||||||||||||||||||||||||
| 380 | } | ||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||
| 382 | #--------------------------------------------------------------------------# | ||||||||||||||||||||||||||||||||||||||
| 383 | # GSSAPI/SASL methods | ||||||||||||||||||||||||||||||||||||||
| 384 | #--------------------------------------------------------------------------# | ||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||
| 386 | # GSSAPI backends report status/errors differently | ||||||||||||||||||||||||||||||||||||||
| 387 | 0 | ▶ | sub _assert_gssapi { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_assert_gssapi: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||
| 388 | 0 | my ( $self, $client, $prefix ) = @_; | |||||||||||||||||||||||||||||||||||||
| 389 | 0 | my $type = ref $client; | |||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||
| 391 | 0 | ▶ | if ( $type =~ m{^Authen::SASL::(?:XS|Cyrus)$} ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 392 | 0 | my $code = $client->code; | |||||||||||||||||||||||||||||||||||||
| 393 | 0 | ▶ | if ( $code != 0 && $code != 1 ) { # not OK or CONTINUE | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$code != 0 and $code != 1
MC/DC0%0/2
$code != 0 and $code != 1
$code != 0
$code != 1
Truth table0%0/3
A and B
A= $code != 0B= $code != 1
| |||||||||||||||||||||||||||||||||||||||
| 394 | 0 | my $error = join( "; ", $client->error ); | |||||||||||||||||||||||||||||||||||||
| 395 | 0 | MongoDB::AuthError->throw("$prefix$error"); | |||||||||||||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||||||||||||
| 397 | } | ||||||||||||||||||||||||||||||||||||||
| 398 | else { | ||||||||||||||||||||||||||||||||||||||
| 399 | # Authen::SASL::Perl::GSSAPI or some unknown backend | ||||||||||||||||||||||||||||||||||||||
| 400 | 0 | ▶ | if ( my $error = $client->error ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 401 | 0 | MongoDB::AuthError->throw("$prefix$error"); | |||||||||||||||||||||||||||||||||||||
| 402 | } | ||||||||||||||||||||||||||||||||||||||
| 403 | } | ||||||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||||||
| 405 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||
| 406 | } | ||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||
| 408 | # PERL-801: GSSAPI broke in some cases after switching to binary | ||||||||||||||||||||||||||||||||||||||
| 409 | # payloads, so fall back to base64 encoding for that mechanism. | ||||||||||||||||||||||||||||||||||||||
| 410 | 0 | ▶ | sub _sasl_encode_payload { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_sasl_encode_payload: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||
| 411 | 0 | my ( $self, $payload ) = @_; | |||||||||||||||||||||||||||||||||||||
| 412 | 0 | ▶ | $payload = "" unless defined $payload; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 413 | 0 | ▶ | return encode_base64( $payload, "" ) if $self->mechanism eq 'GSSAPI'; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 414 | 0 | $payload = encode( "UTF-8", $payload ); | |||||||||||||||||||||||||||||||||||||
| 415 | 0 | return \$payload; | |||||||||||||||||||||||||||||||||||||
| 416 | } | ||||||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||||||
| 418 | 0 | ▶ | sub _sasl_decode_payload { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_sasl_decode_payload: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||
| 419 | 0 | my ( $self, $payload ) = @_; | |||||||||||||||||||||||||||||||||||||
| 420 | 0 | ▶ | return "" unless defined $payload && length $payload; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $payload and length $payload
MC/DC0%0/2
defined $payload and length $payload
defined $payload
length $payload
Truth table0%0/3
A and B
A= defined $payloadB= length $payload
| |||||||||||||||||||||||||||||||||||||||
| 421 | 0 | ▶ | return $payload->data if ref $payload; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 422 | 0 | return decode_base64($payload); | |||||||||||||||||||||||||||||||||||||
| 423 | } | ||||||||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||||||||
| 425 | 0 | ▶ | sub _sasl_start { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_sasl_start: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 426 | 0 | my ( $self, $link, $bson_codec, $payload, $mechanism ) = @_; | |||||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||||||
| 428 | 0 | my $command = Tie::IxHash->new( | |||||||||||||||||||||||||||||||||||||
| 429 | saslStart => 1, | ||||||||||||||||||||||||||||||||||||||
| 430 | mechanism => $mechanism, | ||||||||||||||||||||||||||||||||||||||
| 431 | payload => $self->_sasl_encode_payload($payload), | ||||||||||||||||||||||||||||||||||||||
| 432 | autoAuthorize => 1, | ||||||||||||||||||||||||||||||||||||||
| 433 | ); | ||||||||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||||||||
| 435 | 0 | return $self->_sasl_send( $link, $bson_codec, $command ); | |||||||||||||||||||||||||||||||||||||
| 436 | } | ||||||||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||||||||
| 438 | 0 | ▶ | sub _sasl_continue { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_sasl_continue: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 439 | 0 | my ( $self, $link, $bson_codec, $payload, $conv_id ) = @_; | |||||||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||||||||
| 441 | 0 | my $command = Tie::IxHash->new( | |||||||||||||||||||||||||||||||||||||
| 442 | saslContinue => 1, | ||||||||||||||||||||||||||||||||||||||
| 443 | conversationId => $conv_id, | ||||||||||||||||||||||||||||||||||||||
| 444 | payload => $self->_sasl_encode_payload($payload), | ||||||||||||||||||||||||||||||||||||||
| 445 | ); | ||||||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||||||
| 447 | 0 | return $self->_sasl_send( $link, $bson_codec, $command ); | |||||||||||||||||||||||||||||||||||||
| 448 | } | ||||||||||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||||||||
| 450 | 0 | ▶ | sub _sasl_send { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_sasl_send: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 451 | 0 | my ( $self, $link, $bson_codec, $command ) = @_; | |||||||||||||||||||||||||||||||||||||
| 452 | 0 | my $output = | |||||||||||||||||||||||||||||||||||||
| 453 | $self->_send_command( $link, $bson_codec, $self->source, $command )->output; | ||||||||||||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||||||||||||
| 455 | return ( | ||||||||||||||||||||||||||||||||||||||
| 456 | $self->_sasl_decode_payload( $output->{payload} ), | ||||||||||||||||||||||||||||||||||||||
| 457 | $output->{conversationId}, | ||||||||||||||||||||||||||||||||||||||
| 458 | $output->{done} | ||||||||||||||||||||||||||||||||||||||
| 459 | 0 | ); | |||||||||||||||||||||||||||||||||||||
| 460 | } | ||||||||||||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||||||||||||
| 462 | 0 | ▶ | sub _scram_auth { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_scram_auth: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||
| 463 | 0 | my ( $self, $link, $bson_codec, $client, $mech ) = @_; | |||||||||||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||||||||||||
| 465 | 0 | my ( $msg, $sasl_resp, $conv_id, $done ); | |||||||||||||||||||||||||||||||||||||
| 466 | eval { | ||||||||||||||||||||||||||||||||||||||
| 467 | 0 | $msg = $client->first_msg; | |||||||||||||||||||||||||||||||||||||
| 468 | 0 | ( $sasl_resp, $conv_id, $done ) = | |||||||||||||||||||||||||||||||||||||
| 469 | $self->_sasl_start( $link, $bson_codec, $msg, $mech ); | ||||||||||||||||||||||||||||||||||||||
| 470 | 0 | $msg = $client->final_msg($sasl_resp); | |||||||||||||||||||||||||||||||||||||
| 471 | 0 | ( $sasl_resp, $conv_id, $done ) = | |||||||||||||||||||||||||||||||||||||
| 472 | $self->_sasl_continue( $link, $bson_codec, $msg, $conv_id ); | ||||||||||||||||||||||||||||||||||||||
| 473 | 0 | $client->validate($sasl_resp); | |||||||||||||||||||||||||||||||||||||
| 474 | # might require an empty payload to complete SASL conversation | ||||||||||||||||||||||||||||||||||||||
| 475 | 0 | ▶ | $self->_sasl_continue( $link, $bson_codec, "", $conv_id ) if !$done; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 476 | 0 | 1; | |||||||||||||||||||||||||||||||||||||
| 477 | 0 | ▶ | } or do { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 478 | 0 | ▶ | my $error = $@ || "Unknown error"; | ||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$@ || 'Unknown error'
MC/DC0%0/1
$@ || 'Unknown error'
$@
Truth table0%0/2
A
A= $@
| |||||||||||||||||||||||||||||||||||||||
| 479 | 0 | ▶ | my $msg = $error->$_isa("MongoDB::Error") ? $error->message : "$error"; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 480 | 0 | MongoDB::AuthError->throw("$mech error: $msg"); | |||||||||||||||||||||||||||||||||||||
| 481 | }; | ||||||||||||||||||||||||||||||||||||||
| 482 | } | ||||||||||||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||||||||||||
| 484 | 0 | ▶ | sub _send_command { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_send_command: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 485 | 0 | my ( $self, $link, $bson_codec, $db_name, $command ) = @_; | |||||||||||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||||||||||||
| 487 | 0 | my $op = MongoDB::Op::_Command->_new( | |||||||||||||||||||||||||||||||||||||
| 488 | db_name => $db_name, | ||||||||||||||||||||||||||||||||||||||
| 489 | query => $command, | ||||||||||||||||||||||||||||||||||||||
| 490 | query_flags => {}, | ||||||||||||||||||||||||||||||||||||||
| 491 | bson_codec => $bson_codec, | ||||||||||||||||||||||||||||||||||||||
| 492 | monitoring_callback => $self->monitoring_callback, | ||||||||||||||||||||||||||||||||||||||
| 493 | ); | ||||||||||||||||||||||||||||||||||||||
| 494 | 0 | my $res = $op->execute($link); | |||||||||||||||||||||||||||||||||||||
| 495 | 0 | return $res; | |||||||||||||||||||||||||||||||||||||
| 496 | } | ||||||||||||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||||||||||||
| 498 | 60 | 1; | |||||||||||||||||||||||||||||||||||||