VerifiedIdentity.pm

filter: Statementstmt 9.8% 14 / 142 Branchbran 0.0% 0 / 74 Conditioncond 0.0% 0 / 10 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 14.2% 4 / 28 Podpod 73.3% 11 / 15 totaltotal 10.5% 29 / 275 CC 43 SCAR 43.7
CC
43
Cov
6%
_url_is_under
272.0
DisplayOfURL
72.0
new
42.0
CRAP 79.1
« ClaimedIdentity.pm ↑ Summary Association.pm »
1 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 6 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 ############################################################################
5 package Net::OpenID::VerifiedIdentity;
6 6 $Net::OpenID::VerifiedIdentity::VERSION = '1.18';
7 6 ▶use fields (
Subroutine BEGIN: called CC=1 SCAR=0.0
8 6 'identity', # the verified identity URL
9 'id_uri', # the verified identity's URI object
10  
11 'claimed_identity', # The ClaimedIdentity object that we've verified
12 'semantic_info', # The "semantic info" (RSS URLs, etc) at the verified identity URL
13  
14 'consumer', # The Net::OpenID::Consumer module which created us
15  
16 'signed_fields' , # hashref of key->value of things that were signed. without "openid." prefix
17 'signed_message', # the signed fields as an IndirectMessage object. Created when needed.
18 6 );
19 6 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 0 ▶sub new {
Subroutine new: not called CC=6 SCAR=37.4
Pod undocumented
22 0 my Net::OpenID::VerifiedIdentity $self = shift;
23 0 ▶ $self = fields::new( $self ) unless ref $self;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 0 0
24 0 my %opts = @_;
25  
26 0 $self->{'consumer'} = delete $opts{'consumer'};
27  
28 0 ▶ if ($self->{'claimed_identity'} = delete $opts{'claimed_identity'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"claimed_identity"} = delete $opts{"claimed_identity"}) 0 0 0
29 0 $self->{identity} = $self->{claimed_identity}->claimed_url;
30 0 ▶ unless ($self->{'id_uri'} = URI->new($self->{identity})) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"id_uri"} = "URI"->new($self->{"identity"})) 0 0 0
31 0 return $self->{'consumer'}->_fail("invalid_uri");
32 }
33 }
34  
35 0 for my $par (qw(signed_fields)) {
36 0 $self->$par(delete $opts{$par});
37 }
38  
39 0 ▶ Carp::croak("Unknown options: " . join(", ", keys %opts)) if %opts;
Branch: 1 branch
BranchTrueFalseTotal
if %opts 0 0 0
40 0 return $self;
41 }
42  
43 0 ▶sub url {
Subroutine url: not called CC=1 SCAR=6.9
Pod documented
44 0 my Net::OpenID::VerifiedIdentity $self = shift;
45 0 return $self->{'identity'};
46 }
47  
48 0 ▶sub display {
Subroutine display: not called CC=1 SCAR=6.9
Pod documented
49 0 my Net::OpenID::VerifiedIdentity $self = shift;
50 0 return DisplayOfURL($self->{'identity'});
51 }
52  
53 0 ▶sub _semantic_info_hash {
Subroutine _semantic_info_hash: not called CC=2 SCAR=17.9
54 0 my ($self) = @_;
55 0 ▶ return $self->{semantic_info} if $self->{semantic_info};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"semantic_info"} 0 0 0
56 0 my $sem_info = $self->{claimed_identity}->semantic_info;
57 $self->{semantic_info} = {
58 'foaf' => $self->_identity_relative_uri($sem_info->{"foaf"}),
59 'foafmaker' => $sem_info->{"foaf.maker"},
60 'rss' => $self->_identity_relative_uri($sem_info->{"rss"}),
61 0 'atom' => $self->_identity_relative_uri($sem_info->{"atom"}),
62 };
63 0 return $self->{semantic_info};
64 }
65  
66 0 ▶sub _identity_relative_uri {
Subroutine _identity_relative_uri: not called CC=3 SCAR=24.8
67 0 my $self = shift;
68 0 my $url = shift;
69  
70 0 ▶ return $url if ref $url;
Branch: 1 branch
BranchTrueFalseTotal
if ref $url 0 0 0
71 0 ▶ return undef unless $url;
Branch: 1 branch
BranchTrueFalseTotal
unless $url 0 0 0
72 0 return URI->new_abs($url, $self->{'id_uri'});
73 }
74  
75 0 ▶sub signed_fields { &_getset; }
Subroutine signed_fields: not called CC=1 SCAR=6.9
Pod undocumented
76  
77 0 ▶sub foaf { &_getset_semurl; }
Subroutine foaf: not called CC=1 SCAR=6.9
Pod documented
78 0 ▶sub rss { &_getset_semurl; }
Subroutine rss: not called CC=1 SCAR=6.9
Pod documented
79 0 ▶sub atom { &_getset_semurl; }
Subroutine atom: not called CC=1 SCAR=6.9
Pod documented
80 0 ▶sub foafmaker { &_getset_sem; }
Subroutine foafmaker: not called CC=1 SCAR=6.9
Pod documented
81  
82 0 ▶sub declared_foaf { &_dec_semurl; }
Subroutine declared_foaf: not called CC=1 SCAR=6.9
Pod documented
83 0 ▶sub declared_rss { &_dec_semurl; }
Subroutine declared_rss: not called CC=1 SCAR=6.9
Pod documented
84 0 ▶sub declared_atom { &_dec_semurl; }
Subroutine declared_atom: not called CC=1 SCAR=6.9
Pod documented
85  
86 0 ▶sub extension_fields {
Subroutine extension_fields: not called CC=1 SCAR=6.9
Pod documented
87 0 my ($self, $ns_uri) = @_;
88 0 return $self->_extension_fields($ns_uri, $self->{consumer}->message);
89 }
90  
91 0 ▶sub signed_extension_fields {
Subroutine signed_extension_fields: not called CC=1 SCAR=6.9
Pod documented
92 0 my ($self, $ns_uri) = @_;
93  
94 0 return $self->_extension_fields($ns_uri, $self->signed_message);
95 }
96  
97 0 ▶sub _extension_fields {
Subroutine _extension_fields: not called CC=1 SCAR=6.9
98 0 my ($self, $ns_uri, $args) = @_;
99  
100 0 return $args->get_ext($ns_uri);
101 }
102  
103 0 ▶sub signed_message {
Subroutine signed_message: not called CC=3 SCAR=24.8
Pod undocumented
104 0 my ($self) = @_;
105  
106 0 ▶ return $self->{signed_message} if $self->{signed_message};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"signed_message"} 0 0 0
107  
108 # This is maybe a bit hacky.
109 # We need to synthesize an IndirectMessage object
110 # representing the signed fields, which means
111 # that we need to fake up the mandatory message
112 # arguments that probably weren't signed.
113  
114 0 my %args = map { 'openid.'.$_ => $self->{signed_fields}{$_} } keys %{$self->{signed_fields}};
115  
116 0 my $real_message = $self->{consumer}->message;
117 0 ▶ if ($real_message->protocol_version == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($real_message->protocol_version == 1) { } 0 0 0
118 # OpenID 1.1 just needs a mode.
119 0 $args{'openid.mode'} = 'id_res';
120 }
121 else {
122 # OpenID 2.2 needs the namespace URI as well
123 0 $args{'openid.ns'} = 'http://specs.openid.net/auth/2.0';
124 0 $args{'openid.mode'} = 'id_res';
125 }
126  
127 0 my $message = Net::OpenID::IndirectMessage->new(\%args);
128  
129 0 return $self->{signed_message} = $message;
130 }
131  
132 0 ▶sub _getset {
Subroutine _getset: not called CC=3 SCAR=24.8
133 0 my $self = shift;
134 0 my $param = (caller(1))[3];
135 0 $param =~ s/.+:://;
136  
137 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
138 0 my $val = shift;
139 0 ▶ Carp::croak("Too many parameters") if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
140 0 $self->{$param} = $val;
141 }
142 0 return $self->{$param};
143 }
144  
145 0 ▶sub _getset_sem {
Subroutine _getset_sem: not called CC=3 SCAR=24.8
146 0 my $self = shift;
147 0 my $param = (caller(1))[3];
148 0 $param =~ s/.+:://;
149  
150 0 my $info = $self->_semantic_info_hash;
151  
152 0 ▶ if (my $value = shift) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $value = shift()) 0 0 0
153 0 ▶ Carp::croak("Too many parameters") if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
154 0 $info->{$param} = $value;
155 }
156 0 return $info->{$param};
157 }
158  
159 0 ▶sub _getset_semurl {
Subroutine _getset_semurl: not called CC=5 SCAR=34.0
160 0 my $self = shift;
161 0 my $param = (caller(1))[3];
162 0 $param =~ s/.+:://;
163  
164 0 my $info = $self->_semantic_info_hash;
165  
166 0 ▶ if (my $surl = shift) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $surl = shift()) 0 0 0
167 0 ▶ Carp::croak("Too many parameters") if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
168  
169 # TODO: make absolute URL from possibly relative one
170 0 my $abs = URI->new_abs($surl, $self->{'id_uri'});
171 0 $info->{$param} = $abs;
172 }
173  
174 0 my $uri = $info->{$param};
175 0 ▶ return $uri && _url_is_under($self->{'id_uri'}, $uri) ? $uri->as_string : undef;
Branch: 1 branch
BranchTrueFalseTotal
$uri && _url_is_under($self->{'id_uri'}, $uri) ? : 0 0 0
Condition0%0/3
$uri and _url_is_under($self->{"id_uri"}, $uri)
!ll&&!rl&&r
000
MC/DC0%0/2
$uri and _url_is_under($self->{"id_uri"}, $uri)
$uri _url_is_under($self->{"id_uri"}, $uri)
Truth table0%0/3
A and B
A= $uriB= _url_is_under($self->{"id_uri"}, $uri)
ABresult
0X0
100
111
176 }
177  
178 0 ▶sub _dec_semurl {
Subroutine _dec_semurl: not called CC=2 SCAR=17.9
179 0 my $self = shift;
180 0 my $param = (caller(1))[3];
181 0 $param =~ s/.+::declared_//;
182  
183 0 my $info = $self->_semantic_info_hash;
184  
185 0 my $uri = $info->{$param};
186 0 ▶ return $uri ? $uri->as_string : undef;
Branch: 1 branch
BranchTrueFalseTotal
$uri ? : 0 0 0
187 }
188  
189 0 ▶sub DisplayOfURL {
Subroutine DisplayOfURL: not called CC=8 SCAR=42.8
Pod undocumented
190 0 my $url = shift;
191 0 my $dev_mode = shift;
192  
193 0 ▶ return $url unless
Branch: 1 branch
BranchTrueFalseTotal
unless $url =~ m[^https?://([^/]+)(/.*)?$] 0 0 0
194 $url =~ m!^https?://([^/]+)(/.*)?$!;
195  
196 0 my ($host, $path) = ($1, $2);
197 0 $host = lc($host);
198  
199 0 ▶ if ($dev_mode) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dev_mode) 0 0 0
200 0 $host =~ s!^dev\.!!;
201 0 $host =~ s!:\d+!!;
202 }
203  
204 0 $host =~ s/:.+//;
205 0 $host =~ s/^www\.//i;
206  
207 0 ▶ if (length($path) <= 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $path <= 1) 0 0 0
208 0 return $host;
209 }
210  
211 # obvious username
212 0 ▶ if ($path =~ m!^/~([^/]+)/?$! ||
Branch: 1 branch
BranchTrueFalseTotal
if ($path =~ m[^/~([^/]+)/?$] or $path =~ m[^/(?:users?|members?)/([^/]+)/?$]) 0 0 0
Condition0%0/3
$path =~ m[^/~([^/]+)/?$] or $path =~ m[^/(?:users?|members?)/([^/]+)/?$]
l!l&&r!l&&!r
000
MC/DC0%0/2
$path =~ m[^/~([^/]+)/?$] or $path =~ m[^/(?:users?|members?)/([^/]+)/?$]
$path =~ m[^/~([^/]+)/?$] $path =~ m[^/(?:users?|members?)/([^/]+)/?$]
Truth table0%0/3
A or B
A= $path =~ m[^/~([^/]+)/?$]B= $path =~ m[^/(?:users?|members?)/([^/]+)/?$]
ABresult
1X1
011
000
213 $path =~ m!^/(?:users?|members?)/([^/]+)/?$!) {
214 0 return "$1 [$host]";
215 }
216  
217 0 ▶ if ($host =~ m!^profile\.(.+)!i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($host =~ /^profile\.(.+)/i) 0 0 0
218 0 my $site = $1;
219 0 ▶ if ($path =~ m!^/([^/]+)/?$!) {
Branch: 1 branch
BranchTrueFalseTotal
if ($path =~ m[^/([^/]+)/?$]) 0 0 0
220 0 return "$1 [$site]";
221 }
222 }
223  
224 0 return $url;
225 }
226  
227 # FIXME: duplicated in Net::OpenID::Server
228 0 ▶sub _url_is_under {
Subroutine _url_is_under: not called CC=16 SCAR=56.1
229 0 my ($root, $test, $err_ref) = @_;
230  
231 0 ▶ my $err = sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
232 0 ▶ $$err_ref = shift if $err_ref;
Branch: 1 branch
BranchTrueFalseTotal
if $err_ref 0 0 0
233 0 return undef;
234 0 };
235  
236 0 ▶ my $ru = ref $root ? $root : URI->new($root);
Branch: 1 branch
BranchTrueFalseTotal
ref $root ? : 0 0 0
237 0 ▶ return $err->("invalid root scheme") unless $ru->scheme =~ /^https?$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $ru->scheme =~ /^https?$/ 0 0 0
238 0 ▶ my $tu = ref $test ? $test : URI->new($test);
Branch: 1 branch
BranchTrueFalseTotal
ref $test ? : 0 0 0
239 0 ▶ return $err->("invalid test scheme") unless $tu->scheme =~ /^https?$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $tu->scheme =~ /^https?$/ 0 0 0
240 0 ▶ return $err->("schemes don't match") unless $ru->scheme eq $tu->scheme;
Branch: 1 branch
BranchTrueFalseTotal
unless $ru->scheme eq $tu->scheme 0 0 0
241 0 ▶ return $err->("ports don't match") unless $ru->port == $tu->port;
Branch: 1 branch
BranchTrueFalseTotal
unless $ru->port == $tu->port 0 0 0
242  
243 # check hostnames
244 0 my $ru_host = $ru->host;
245 0 my $tu_host = $tu->host;
246 0 my $wildcard_host = 0;
247 0 ▶ if ($ru_host =~ s!^\*\.!!) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ru_host =~ s/^\*\.//) 0 0 0
248 0 $wildcard_host = 1;
249 }
250 0 ▶ unless ($ru_host eq $tu_host) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ru_host eq $tu_host) 0 0 0
251 0 ▶ if ($wildcard_host) {
Branch: 1 branch
BranchTrueFalseTotal
if ($wildcard_host) { } 0 0 0
252 0 ▶ return $err->("host names don't match") unless
Branch: 1 branch
BranchTrueFalseTotal
unless $tu_host =~ /\.\Q$ru_host\E$/ 0 0 0
253 $tu_host =~ /\.\Q$ru_host\E$/;
254 } else {
255 0 return $err->("host names don't match");
256 }
257 }
258  
259 # check paths
260 0 ▶ my $ru_path = $ru->path || "/";
Condition0%0/2
$ru->path || '/'
l!l
00
MC/DC0%0/1
$ru->path || '/'
$ru->path
Truth table0%0/2
A
A= $ru->path
Aresult
11
00
261 0 ▶ my $tu_path = $tu->path || "/";
Condition0%0/2
$tu->path || '/'
l!l
00
MC/DC0%0/1
$tu->path || '/'
$tu->path
Truth table0%0/2
A
A= $tu->path
Aresult
11
00
262 0 ▶ $ru_path .= "/" unless $ru_path =~ m!/$!;
Branch: 1 branch
BranchTrueFalseTotal
unless $ru_path =~ m[/$] 0 0 0
263 0 ▶ $tu_path .= "/" unless $tu_path =~ m!/$!;
Branch: 1 branch
BranchTrueFalseTotal
unless $tu_path =~ m[/$] 0 0 0
264 0 ▶ return $err->("path not a subpath") unless $tu_path =~ m!^\Q$ru_path\E!;
Branch: 1 branch
BranchTrueFalseTotal
unless $tu_path =~ /^\Q$ru_path\E/ 0 0 0
265  
266 0 return 1;
267 }
268  
269 6 1;
270  
271 __END__
« ClaimedIdentity.pm ↑ Summary Association.pm »