ClaimedIdentity.pm

filter: Statementstmt 14.1% 14 / 99 Branchbran 0.0% 0 / 60 Conditioncond 0.0% 0 / 14 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 33.3% 4 / 12 Podpod 75.0% 6 / 8 totaltotal 11.8% 24 / 202 CC 39 SCAR 54.6
CC
39
Cov
8%
check_url
506.0
new
56.0
set_extension_args
30.0
CRAP 236.1
↑ Summary VerifiedIdentity.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::ClaimedIdentity;
6 6 $Net::OpenID::ClaimedIdentity::VERSION = '1.18';
7 6 ▶use fields (
Subroutine BEGIN: called CC=1 SCAR=0.0
8 6 'identity', # the canonical URL that was found, following redirects
9 'server', # author-identity identity provider endpoint
10 'consumer', # ref up to the Net::OpenID::Consumer which generated us
11 'delegate', # the delegated URL actually asserted by the provider
12 'protocol_version', # The version of the OpenID Authentication Protocol that is used
13 'semantic_info', # Stuff that we've discovered in the identifier page's metadata
14 'extension_args', # Extension arguments that the caller wants to add to the request
15 6 );
16  
17 6 ▶use Digest::SHA qw(hmac_sha1_hex);
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 0 ▶sub new {
Subroutine new: not called CC=7 SCAR=40.3
Pod undocumented
20 0 my Net::OpenID::ClaimedIdentity $self = shift;
21 0 ▶ $self = fields::new( $self ) unless ref $self;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 0 0
22 0 my %opts = @_;
23 0 for my $f (qw( identity server consumer delegate protocol_version semantic_info )) {
24 0 $self->{$f} = delete $opts{$f};
25 }
26  
27 0 ▶ $self->{protocol_version} ||= 1;
Condition0%0/2
$self->{"protocol_version"} ||= 1
l!l
00
MC/DC0%0/1
$self->{"protocol_version"} ||= 1
$self->{"protocol_version"}
Truth table0%0/2
A
A= $self->{"protocol_version"}
Aresult
11
00
28 0 ▶ unless ($self->{protocol_version} == 1 || $self->{protocol_version} == 2) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"protocol_version"} == 1 or $self->{"protocol_version"} == 2) 0 0 0
Condition0%0/3
$self->{"protocol_version"} == 1 or $self->{"protocol_version"} == 2
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"protocol_version"} == 1 or $self->{"protocol_version"} == 2
$self->{"protocol_version"} == 1 $self->{"protocol_version"} == 2
Truth table0%0/3
A or B
A= $self->{"protocol_version"} == 1B= $self->{"protocol_version"} == 2
ABresult
1X1
011
000
29 0 Carp::croak("Unsupported protocol version");
30 }
31  
32 # lowercase the scheme and hostname
33 0 $self->{'identity'} =~ s!^(https?://.+?)(/(?:.*))?$!lc($1) . $2!ie;
34  
35 0 $self->{extension_args} = {};
36  
37 0 ▶ Carp::croak("unknown options: " . join(", ", keys %opts)) if %opts;
Branch: 1 branch
BranchTrueFalseTotal
if %opts 0 0 0
38 0 return $self;
39 }
40  
41 0 ▶sub claimed_url {
Subroutine claimed_url: not called CC=2 SCAR=17.9
Pod documented
42 0 my Net::OpenID::ClaimedIdentity $self = shift;
43 0 ▶ Carp::croak("Too many parameters") if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
44 0 return $self->{'identity'};
45 }
46  
47 0 ▶sub delegated_url {
Subroutine delegated_url: not called CC=2 SCAR=17.9
Pod documented
48 0 my Net::OpenID::ClaimedIdentity $self = shift;
49 0 ▶ Carp::croak("Too many parameters") if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
50 0 return $self->{'delegate'};
51 }
52  
53 0 ▶sub identity_server {
Subroutine identity_server: not called CC=2 SCAR=17.9
Pod documented
54 0 my Net::OpenID::ClaimedIdentity $self = shift;
55 0 ▶ Carp::croak("Too many parameters") if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
56 0 return $self->{server};
57 }
58  
59 0 ▶sub protocol_version {
Subroutine protocol_version: not called CC=2 SCAR=17.9
Pod documented
60 0 my Net::OpenID::ClaimedIdentity $self = shift;
61 0 ▶ Carp::croak("Too many parameters") if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
62 0 return $self->{protocol_version};
63 }
64  
65 0 ▶sub semantic_info {
Subroutine semantic_info: not called CC=4 SCAR=30.0
Pod undocumented
66 0 my Net::OpenID::ClaimedIdentity $self = shift;
67 0 ▶ Carp::croak("Too many parameters") if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
68 0 ▶ return $self->{semantic_info} if $self->{semantic_info};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"semantic_info"} 0 0 0
69 0 my $final_url = '';
70 0 my $info = $self->{consumer}->_find_semantic_info($self->claimed_url, \$final_url);
71 # Don't return anything if the URL has changed. Something bad may be happening.
72 0 ▶ $info = {} if $final_url ne $self->claimed_url;
Branch: 1 branch
BranchTrueFalseTotal
if $final_url ne $self->claimed_url 0 0 0
73 0 return $self->{semantic_info} = $info;
74 }
75  
76 0 ▶sub set_extension_args {
Subroutine set_extension_args: not called CC=5 SCAR=34.0
Pod documented
77 0 my Net::OpenID::ClaimedIdentity $self = shift;
78 0 my $ext_uri = shift;
79 0 my $args = shift;
80 0 ▶ Carp::croak("Too many parameters") if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
81 0 ▶ Carp::croak("No extension URI given") unless $ext_uri;
Branch: 1 branch
BranchTrueFalseTotal
unless $ext_uri 0 0 0
82 0 ▶ Carp::croak("Expecting hashref of args") if defined($args) && ref $args ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if defined $args and ref $args ne "HASH" 0 0 0
Condition0%0/3
defined $args and ref $args ne "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $args and ref $args ne "HASH"
defined $args ref $args ne "HASH"
Truth table0%0/3
A and B
A= defined $argsB= ref $args ne "HASH"
ABresult
0X0
100
111
83  
84 0 $self->{extension_args}{$ext_uri} = $args;
85 }
86  
87 0 ▶sub check_url {
Subroutine check_url: not called CC=22 SCAR=62.3
Pod documented
88 0 my Net::OpenID::ClaimedIdentity $self = shift;
89 0 my (%opts) = @_;
90  
91 0 my $return_to = delete $opts{'return_to'};
92 0 my $trust_root = delete $opts{'trust_root'};
93 0 my $delayed_ret = delete $opts{'delayed_return'};
94 0 my $force_reassociate = delete $opts{'force_reassociate'};
95 0 my $use_assoc_handle = delete $opts{'use_assoc_handle'};
96 0 my $actually_return_association = delete $opts{'actually_return_association'};
97  
98 0 ▶ Carp::croak("Unknown options: " . join(", ", keys %opts)) if %opts;
Branch: 1 branch
BranchTrueFalseTotal
if %opts 0 0 0
99 0 ▶ Carp::croak("Invalid/missing return_to") unless $return_to =~ m!^https?://!;
Branch: 1 branch
BranchTrueFalseTotal
unless $return_to =~ m[^https?://] 0 0 0
100  
101 0 my $csr = $self->{consumer};
102  
103 my $ident_server = $self->{server} or
104 0 ▶ Carp::croak("No identity server");
Branch: 1 branch
BranchTrueFalseTotal
my $ident_server = $self->{"server"} or Carp::croak("No identity server") 0 0 0
105  
106 # get an assoc (or undef for dumb mode)
107 0 my $assoc;
108 0 ▶ if ($use_assoc_handle) {
Branch: 1 branch
BranchTrueFalseTotal
if ($use_assoc_handle) { } 0 0 0
109 0 $assoc = Net::OpenID::Association::handle_assoc($csr, $ident_server, $use_assoc_handle);
110 } else {
111 $assoc = Net::OpenID::Association::server_assoc($csr, $ident_server, $force_reassociate, (
112 0 %{$csr->assoc_options},
113 protocol_version => $self->protocol_version,
114 ));
115 }
116  
117 # for the openid-test project: (doing interop testing)
118 0 ▶ if ($actually_return_association) {
Branch: 1 branch
BranchTrueFalseTotal
if ($actually_return_association) 0 0 0
119 0 return $assoc;
120 }
121  
122 0 ▶ my $identity_arg = $self->{'delegate'} || $self->{'identity'};
Condition0%0/3
$self->{'delegate'} || $self->{'identity'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{'delegate'} || $self->{'identity'}
$self->{'delegate'} $self->{'identity'}
Truth table0%0/3
A || B
A= $self->{'delegate'}B= $self->{'identity'}
ABresult
1X1
011
000
123  
124 # make a note back to ourselves that we're using a delegate
125 # but only in the 1.1 case because 2.0 has a core field for this
126 0 ▶ if ($self->{'delegate'} && $self->protocol_version == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"delegate"} and $self->protocol_version == 1) 0 0 0
Condition0%0/3
$self->{"delegate"} and $self->protocol_version == 1
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"delegate"} and $self->protocol_version == 1
$self->{"delegate"} $self->protocol_version == 1
Truth table0%0/3
A and B
A= $self->{"delegate"}B= $self->protocol_version == 1
ABresult
0X0
100
111
127 OpenID::util::push_url_arg(\$return_to,
128 0 "oic.identity", $self->{identity});
129 }
130  
131 # add a HMAC-signed time so we can verify the return_to URL wasn't spoofed
132 0 my $sig_time = time();
133 0 my $c_secret = $csr->_get_consumer_secret($sig_time);
134 0 my $sig = substr(hmac_sha1_hex($sig_time, $c_secret), 0, 20);
135 0 OpenID::util::push_url_arg(\$return_to,
136 "oic.time", "${sig_time}-$sig");
137  
138 0 my $curl = $ident_server;
139 0 ▶ if ($self->protocol_version == 1) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->protocol_version == 1) { } 0 0 0
elsif ($self->protocol_version == 2) { } 0 0 0
140 0 ▶ OpenID::util::push_url_arg(\$curl,
Branch: 3 branches
BranchTrueFalseTotal
$delayed_ret ? : 0 0 0
$trust_root ? : 0 0 0
$assoc ? : 0 0 0
141 "openid.mode" => ($delayed_ret ? "checkid_setup" : "checkid_immediate"),
142 "openid.identity" => $identity_arg,
143 "openid.return_to" => $return_to,
144  
145 ($trust_root ? (
146 "openid.trust_root" => $trust_root
147 ) : ()),
148  
149 ($assoc ? (
150 "openid.assoc_handle" => $assoc->handle
151 ) : ()),
152 );
153 }
154 elsif ($self->protocol_version == 2) {
155 # NOTE: OpenID Auth 2.0 uses different terminology for a bunch
156 # of things than 1.1 did. This library still uses the 1.1 terminology
157 # in its API.
158 0 ▶ OpenID::util::push_openid2_url_arg(\$curl,
Branch: 3 branches
BranchTrueFalseTotal
$delayed_ret ? : 0 0 0
$trust_root ? : 0 0 0
$assoc ? : 0 0 0
159 "mode" => ($delayed_ret ? "checkid_setup" : "checkid_immediate"),
160 "claimed_id" => $self->claimed_url,
161 "identity" => $identity_arg,
162 "return_to" => $return_to,
163  
164 ($trust_root ? (
165 "realm" => $trust_root
166 ) : ()),
167  
168 ($assoc ? (
169 "assoc_handle" => $assoc->handle
170 ) : ()),
171 );
172 }
173  
174 # Finally we add in the extension arguments, if any
175 0 my %ext_url_args = ();
176 0 my $ext_idx = 1;
177 0 foreach my $ext_uri (keys %{$self->{extension_args}}) {
178 0 my $ext_alias;
179  
180 0 ▶ if ($ext_uri eq "http://openid.net/extensions/sreg/1.1") {
Branch: 2 branches
BranchTrueFalseTotal
if ($ext_uri eq 'http://openid.net/extensions/sreg/1.1') { } 0 0 0
elsif ($self->protocol_version < 2) { } 0 0 0
181 # For OpenID 1.1 only the "SREG" extension is allowed,
182 # and it must use the "openid.sreg." prefix.
183 0 $ext_alias = "sreg";
184 }
185 elsif ($self->protocol_version < 2) {
186 0 next;
187 }
188 else {
189 0 $ext_alias = 'e'.($ext_idx++);
190 }
191 0 $ext_url_args{'openid.ns.'.$ext_alias} = $ext_uri;
192  
193 0 foreach my $k (keys %{$self->{extension_args}{$ext_uri}}) {
194 0 $ext_url_args{'openid.'.$ext_alias.'.'.$k} = $self->{extension_args}{$ext_uri}{$k};
195 }
196 }
197 0 ▶ OpenID::util::push_url_arg(\$curl, %ext_url_args) if %ext_url_args;
Branch: 1 branch
BranchTrueFalseTotal
if %ext_url_args 0 0 0
198  
199 0 $self->{consumer}->_debug("check_url for (del=$self->{delegate}, id=$self->{identity}) = $curl");
200 0 return $curl;
201 }
202  
203  
204 6 1;
205  
206 __END__
↑ Summary VerifiedIdentity.pm »