| 1 | package Net::DAV::LockManager; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 27 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 27 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 27 | ▶ | use File::Spec (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 27 | ▶ | use Net::DAV::UUID; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 27 | ▶ | use Net::DAV::Lock; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 27 | our $VERSION = '1.304'; | |||||||||||||||||||||||||||||||||||||||||
| 11 | 27 | $VERSION = eval $VERSION; | |||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | sub new { | ||||||||||||||||||||||||||||||||||||||||||
| 14 | 140 | ▶ | my ($class, $db) = (shift, shift); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 140 | my %obj = @_; | |||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 140 | $obj{'db'} = $db; | |||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | 140 | return bless \%obj, $class; | |||||||||||||||||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | sub can_modify { | ||||||||||||||||||||||||||||||||||||||||||
| 23 | 178 | ▶ | my ($self, $req) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
can_modify: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | 178 | _validate_lock_request( $req, 'user' ); | |||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | 159 | my ($resource, $token) = @{$req}{qw/path token/}; | |||||||||||||||||||||||||||||||||||||||||
| 28 | 159 | ▶ | my $lock = $self->_get_lock( $resource ) || $self->_get_indirect_lock( $resource ); | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$self->_get_lock($resource) || $self->_get_indirect_lock($resource)
MC/DC100%2/2
$self->_get_lock($resource) || $self->_get_indirect_lock($resource)
$self->_get_lock($resource)
$self->_get_indirect_lock($resource)
Truth table100%3/3
A || B
A= $self->_get_lock($resource)B= $self->_get_indirect_lock($resource)
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | 159 | ▶ | return 1 unless $lock; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 58 | ▶ | return 0 unless $token; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | 29 | return _is_permitted( $req, $lock ); | |||||||||||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | sub lock { | ||||||||||||||||||||||||||||||||||||||||||
| 37 | 118 | ▶ | my ($self, $req) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
lock: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | 118 | _validate_lock_request( $req, 'user', 'owner' ); | |||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | 91 | my $path = $req->{'path'}; | |||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 91 | ▶ | return undef unless $self->can_modify( $req ) && !$self->_get_lock( $path ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->can_modify($req) and not $self->_get_lock($path)
MC/DC100%2/2
$self->can_modify($req) and not $self->_get_lock($path)
$self->can_modify($req)
not $self->_get_lock($path)
Truth table100%3/3
A and not(B)
A= $self->can_modify($req)B= not $self->_get_lock($path)
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 79 | foreach my $lock ( $self->{'db'}->list_descendants( $path ) ) { | |||||||||||||||||||||||||||||||||||||||||
| 45 | 4 | ▶ | return undef unless _is_permitted( $req, $lock ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | return $self->_add_lock(Net::DAV::Lock->new({ | ||||||||||||||||||||||||||||||||||||||||||
| 49 | 'path' => $path, | ||||||||||||||||||||||||||||||||||||||||||
| 50 | (defined $req->{'timeout'} ? ('expiry' => time() + $req->{'timeout'}) : ()), | ||||||||||||||||||||||||||||||||||||||||||
| 51 | 'creator' => $req->{'user'}, | ||||||||||||||||||||||||||||||||||||||||||
| 52 | 'owner' => $req->{'owner'}, | ||||||||||||||||||||||||||||||||||||||||||
| 53 | (defined $req->{'depth'} ? ('depth' => $req->{'depth'}) : ()), | ||||||||||||||||||||||||||||||||||||||||||
| 54 | 76 | ▶ | (defined $req->{'scope'} ? ('scope' => $req->{'scope'}) : ()), | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | })); | ||||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | sub refresh_lock { | ||||||||||||||||||||||||||||||||||||||||||
| 59 | 28 | ▶ | my ($self, $req) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
refresh_lock: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | 28 | _validate_lock_request( $req, 'user', 'token' ); | |||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | 9 | my $lock = $self->_get_lock( $req->{'path'} ); | |||||||||||||||||||||||||||||||||||||||||
| 63 | 9 | ▶ | return undef unless $lock; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 7 | ▶ | return undef unless _is_permitted( $req, $lock ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | 3 | ▶ | $lock->renew( time() + ($req->{'timeout'} || $Net::DAV::Lock::DEFAULT_LOCK_TIMEOUT) ); | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$req->{'timeout'} || $Net::DAV::Lock::DEFAULT_LOCK_TIMEOUT
MC/DC0%0/2
$req->{'timeout'} || $Net::DAV::Lock::DEFAULT_LOCK_TIMEOUT
$req->{'timeout'}
$Net::DAV::Lock::DEFAULT_LOCK_TIMEOUT
Truth table66%2/3
A || B
A= $req->{'timeout'}B= $Net::DAV::Lock::DEFAULT_LOCK_TIMEOUT
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | 3 | return $self->_update_lock( $lock ); | |||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | sub unlock { | ||||||||||||||||||||||||||||||||||||||||||
| 72 | 37 | ▶ | my ($self, $req) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unlock: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | 37 | _validate_lock_request( $req, 'user', 'token' ); | |||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | 18 | my $lock = $self->_get_lock( $req->{'path'} ); | |||||||||||||||||||||||||||||||||||||||||
| 76 | 18 | ▶ | return 0 unless $lock; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | 14 | ▶ | return 0 unless _is_permitted( $req, $lock ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | 11 | $self->_remove_lock( $lock ); | |||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | 11 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | sub find_lock { | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 13 | ▶ | my ($self, $req) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
find_lock: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | 13 | _validate_lock_request( $req ); | |||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | 13 | my $path = $req->{'path'}; | |||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | 13 | ▶ | return $self->_get_lock( $path ) || $self->_get_indirect_lock( $path ); | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$self->_get_lock($path) || $self->_get_indirect_lock($path)
MC/DC100%2/2
$self->_get_lock($path) || $self->_get_indirect_lock($path)
$self->_get_lock($path)
$self->_get_indirect_lock($path)
Truth table100%3/3
A || B
A= $self->_get_lock($path)B= $self->_get_indirect_lock($path)
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | sub list_all_locks { | ||||||||||||||||||||||||||||||||||||||||||
| 95 | 24 | ▶ | my ($self, $req) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
list_all_locks: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | 24 | _validate_lock_request( $req ); | |||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | 24 | my $path = $req->{'path'}; | |||||||||||||||||||||||||||||||||||||||||
| 100 | 24 | my @locks; | |||||||||||||||||||||||||||||||||||||||||
| 101 | 24 | my $lock = $self->_get_lock( $path ); | |||||||||||||||||||||||||||||||||||||||||
| 102 | 24 | ▶ | push @locks, $lock if defined $lock; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | 24 | ▶ | while ( $path =~ s{/[^/]+$}{} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | 29 | ▶ | $path = '/' unless length $path; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | 29 | my $lock = $self->_get_lock( $path ); | |||||||||||||||||||||||||||||||||||||||||
| 108 | 29 | ▶ | push @locks, $lock if $lock && $lock->depth eq 'infinity'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$lock and $lock->depth eq "infinity"
MC/DC100%2/2
$lock and $lock->depth eq "infinity"
$lock
$lock->depth eq "infinity"
Truth table100%3/3
A and B
A= $lockB= $lock->depth eq "infinity"
| |||||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | 24 | return @locks; | |||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | # | ||||||||||||||||||||||||||||||||||||||||||
| 115 | # Retrieve a lock from the lock database, given the path to the lock. | ||||||||||||||||||||||||||||||||||||||||||
| 116 | # Return undef if none. This method also has the side effect of expiring | ||||||||||||||||||||||||||||||||||||||||||
| 117 | # any old locks persisted upon fetching. | ||||||||||||||||||||||||||||||||||||||||||
| 118 | # | ||||||||||||||||||||||||||||||||||||||||||
| 119 | sub _get_lock { | ||||||||||||||||||||||||||||||||||||||||||
| 120 | 558 | ▶ | my ($self, $path) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_lock: called CC=3 SCAR=11.6
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||
| 122 | 558 | my $lock = $self->{'db'}->get( $path ); | |||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | 558 | ▶ | return undef unless $lock; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||
| 126 | 112 | ▶ | if (time() >= $lock->expiry) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | $self->_remove_lock($lock); | |||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | 112 | return $lock; | |||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||
| 135 | # | ||||||||||||||||||||||||||||||||||||||||||
| 136 | # Add the given lock to the database. | ||||||||||||||||||||||||||||||||||||||||||
| 137 | # | ||||||||||||||||||||||||||||||||||||||||||
| 138 | sub _add_lock { | ||||||||||||||||||||||||||||||||||||||||||
| 139 | 76 | ▶ | my ($self, $lock) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_add_lock: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||
| 141 | 76 | return $self->{'db'}->add($lock); | |||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||
| 144 | # | ||||||||||||||||||||||||||||||||||||||||||
| 145 | # Update the lock provided. | ||||||||||||||||||||||||||||||||||||||||||
| 146 | # | ||||||||||||||||||||||||||||||||||||||||||
| 147 | sub _update_lock { | ||||||||||||||||||||||||||||||||||||||||||
| 148 | 3 | ▶ | my ($self, $lock) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_update_lock: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||
| 150 | 3 | return $self->{'db'}->update($lock); | |||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | # | ||||||||||||||||||||||||||||||||||||||||||
| 154 | # Remove the lock object passed from the database. | ||||||||||||||||||||||||||||||||||||||||||
| 155 | # | ||||||||||||||||||||||||||||||||||||||||||
| 156 | sub _remove_lock { | ||||||||||||||||||||||||||||||||||||||||||
| 157 | 11 | ▶ | my ($self, $lock) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_remove_lock: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||
| 159 | 11 | $self->{'db'}->remove($lock); | |||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||
| 161 | 11 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||
| 164 | # | ||||||||||||||||||||||||||||||||||||||||||
| 165 | # Get the lock of the nearest ancestor that applies to this resource. | ||||||||||||||||||||||||||||||||||||||||||
| 166 | # Returns undef if none found. | ||||||||||||||||||||||||||||||||||||||||||
| 167 | # | ||||||||||||||||||||||||||||||||||||||||||
| 168 | sub _get_indirect_lock { | ||||||||||||||||||||||||||||||||||||||||||
| 169 | 139 | ▶ | my ($self, $res) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_indirect_lock: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||
| 171 | 139 | ▶ | while ( $res =~ s{/[^/]+$}{} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 172 | 225 | ▶ | $res = '/' unless length $res; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | 225 | my $lock = $self->_get_lock( $res ); | |||||||||||||||||||||||||||||||||||||||||
| 175 | 225 | ▶ | return $lock if $lock && $lock->depth eq 'infinity'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$lock and $lock->depth eq "infinity"
MC/DC100%2/2
$lock and $lock->depth eq "infinity"
$lock
$lock->depth eq "infinity"
Truth table100%3/3
A and B
A= $lockB= $lock->depth eq "infinity"
| |||||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||
| 178 | 105 | return; | |||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||
| 181 | # | ||||||||||||||||||||||||||||||||||||||||||
| 182 | # Return true or false depending on whether or not the information reflected | ||||||||||||||||||||||||||||||||||||||||||
| 183 | # in the request is appropriate for the lock obtained from the database. In | ||||||||||||||||||||||||||||||||||||||||||
| 184 | # other words, make sure the token and user match the request. | ||||||||||||||||||||||||||||||||||||||||||
| 185 | # | ||||||||||||||||||||||||||||||||||||||||||
| 186 | sub _is_permitted { | ||||||||||||||||||||||||||||||||||||||||||
| 187 | 54 | ▶ | my ($req, $lock) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_permitted: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||
| 189 | 54 | ▶ | return 0 unless $req->{'user'} eq $lock->creator; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | 40 | ▶ | return 0 if !defined $req->{'token'}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 191 | 39 | ▶ | if ( 'ARRAY' eq ref $req->{'token'} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 192 | 7 | ▶ | return 0 unless grep { $_ eq $lock->token } @{$req->{'token'}}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||||||||||
| 194 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 195 | 32 | ▶ | return 0 unless $req->{'token'} eq $lock->token; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||
| 198 | 28 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||
| 201 | # | ||||||||||||||||||||||||||||||||||||||||||
| 202 | # Perform general parameter validation. | ||||||||||||||||||||||||||||||||||||||||||
| 203 | # | ||||||||||||||||||||||||||||||||||||||||||
| 204 | # The parameter passed in should be a hash reference to be validated. The | ||||||||||||||||||||||||||||||||||||||||||
| 205 | # optional list that follows are names of required parameters besides the | ||||||||||||||||||||||||||||||||||||||||||
| 206 | # 'path' and 'user' parameters that are always required. | ||||||||||||||||||||||||||||||||||||||||||
| 207 | # | ||||||||||||||||||||||||||||||||||||||||||
| 208 | # Throws exception on failure. | ||||||||||||||||||||||||||||||||||||||||||
| 209 | # | ||||||||||||||||||||||||||||||||||||||||||
| 210 | sub _validate_lock_request { | ||||||||||||||||||||||||||||||||||||||||||
| 211 | 411 | ▶ | my ($req, @required) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_lock_request: called CC=20 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 212 | 411 | ▶ | die "Parameter should be a hash reference.\n" unless 'HASH' eq ref $req; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||
| 214 | 403 | foreach my $arg ( qw/path/, @required ) { | |||||||||||||||||||||||||||||||||||||||||
| 215 | 916 | ▶ | die "Missing required '$arg' parameter.\n" unless exists $req->{$arg}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||
| 218 | 388 | ▶ | die "Not a clean path\n" if $req->{'path'} =~ m{(?:^|/)\.\.?(?:$|/)}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 219 | 363 | ▶ | die "Not a clean path\n" if $req->{'path'} !~ m{^/} && !($req->{'path'} =~ s{^https?://[^/]+/}{/}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$req->{"path"} =~ m[^/] or $req->{"path"} =~ s[^https?://[^/]+/][/]
MC/DC100%2/2
$req->{"path"} =~ m[^/] or $req->{"path"} =~ s[^https?://[^/]+/][/]
$req->{"path"} =~ m[^/]
$req->{"path"} =~ s[^https?://[^/]+/][/]
Truth table100%3/3
A or B
A= $req->{"path"} =~ m[^/]B= $req->{"path"} =~ s[^https?://[^/]+/][/]
| |||||||||||||||||||||||||||||||||||||||||||
| 220 | 350 | ▶ | if( defined $req->{'user'} && $req->{'user'} !~ m{^[0-9a-z_.][-a-z0-9_.]*$}i ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $req->{"user"} and not $req->{"user"} =~ /^[0-9a-z_.][-a-z0-9_.]*$/i
MC/DC100%2/2
defined $req->{"user"} and not $req->{"user"} =~ /^[0-9a-z_.][-a-z0-9_.]*$/i
defined $req->{"user"}
not $req->{"user"} =~ /^[0-9a-z_.][-a-z0-9_.]*$/i
Truth table100%3/3
A and not(B)
A= defined $req->{"user"}B= not $req->{"user"} =~ /^[0-9a-z_.][-a-z0-9_.]*$/i
| |||||||||||||||||||||||||||||||||||||||||||
| 221 | 20 | die "Not a valid user name.\n"; # May need better validation. | |||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||
| 224 | # Validate optional parameters as necessary. | ||||||||||||||||||||||||||||||||||||||||||
| 225 | 330 | ▶ | if( defined $req->{'scope'} && $Net::DAV::Lock::DEFAULT_SCOPE ne $req->{'scope'} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $req->{"scope"} and $Net::DAV::Lock::DEFAULT_SCOPE ne $req->{"scope"}
MC/DC100%2/2
defined $req->{"scope"} and $Net::DAV::Lock::DEFAULT_SCOPE ne $req->{"scope"}
defined $req->{"scope"}
$Net::DAV::Lock::DEFAULT_SCOPE ne $req->{"scope"}
Truth table100%3/3
A and B
A= defined $req->{"scope"}B= $Net::DAV::Lock::DEFAULT_SCOPE ne $req->{"scope"}
| |||||||||||||||||||||||||||||||||||||||||||
| 226 | 2 | die "'$req->{'scope'}' is not a supported value for scope.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||
| 229 | 328 | ▶ | if( defined $req->{'depth'} && '0' ne $req->{'depth'} && 'infinity' ne $req->{'depth'} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
defined $req->{"depth"} and 0 ne $req->{"depth"} and "infinity" ne $req->{"depth"}
defined $req->{"depth"} and 0 ne $req->{"depth"}
MC/DC100%3/3
defined $req->{"depth"} and 0 ne $req->{"depth"} and "infinity" ne $req->{"depth"}
defined $req->{"depth"}
0 ne $req->{"depth"}
"infinity" ne $req->{"depth"}
Truth table100%4/4
A and B and C
A= defined $req->{"depth"}B= 0 ne $req->{"depth"}C= "infinity" ne $req->{"depth"}
| |||||||||||||||||||||||||||||||||||||||||||
| 230 | 2 | die "'$req->{'depth'}' is not a supported value for depth.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||
| 233 | 326 | ▶ | if( defined $req->{'timeout'} && $req->{'timeout'} =~ /\D/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $req->{"timeout"} and $req->{"timeout"} =~ /\D/
MC/DC100%2/2
defined $req->{"timeout"} and $req->{"timeout"} =~ /\D/
defined $req->{"timeout"}
$req->{"timeout"} =~ /\D/
Truth table100%3/3
A and B
A= defined $req->{"timeout"}B= $req->{"timeout"} =~ /\D/
| |||||||||||||||||||||||||||||||||||||||||||
| 234 | 3 | die "'$req->{'timeout'}' is not a supported value for timeout.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||
| 237 | 323 | ▶ | if ( defined $req->{'token'} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 238 | 74 | ▶ | unless ( !ref $req->{'token'} || 'ARRAY' eq ref $req->{'token'} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not ref $req->{"token"} or "ARRAY" eq ref $req->{"token"}
MC/DC100%2/2
not ref $req->{"token"} or "ARRAY" eq ref $req->{"token"}
not ref $req->{"token"}
"ARRAY" eq ref $req->{"token"}
Truth table100%3/3
not(A) or B
A= not ref $req->{"token"}B= "ARRAY" eq ref $req->{"token"}
| |||||||||||||||||||||||||||||||||||||||||||
| 239 | 1 | die "Invalid token, not a string or array reference.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||
| 243 | # Remove trailing / from path to make pathnames canonical. | ||||||||||||||||||||||||||||||||||||||||||
| 244 | 322 | ▶ | $req->{'path'} =~ s{/$}{} unless $req->{'path'} eq '/'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||
| 246 | 322 | return; | |||||||||||||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||
| 249 | 27 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||
| 251 | __END__ | ||||||||||||||||||||||||||||||||||||||||||