SAML2/Protocol/AuthnRequest.pm

filter: Statementstmt 97.9% 96 / 98 Branchbran 95.4% 21 / 22 Conditioncond 66.6% 8 / 12 MC/DCmcdc 50.0% 4 / 8 Subroutinesub 100% 16 / 16 Podpod 100% 1 / 1 totaltotal 92.9% 146 / 157 CC 18 SCAR 14.9
CC
18
Cov
95%
as_xml
10.0
__ANON__
3.7
_set_name_policy_format
3.0
CRAP 4.5
« SAML2/SP.pm ↑ Summary SAML2/Protocol/LogoutRequest.pm »
1 package Net::SAML2::Protocol::AuthnRequest;
2 32 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 32 our $VERSION = '0.89'; # VERSION
5 32 ▶use MooseX::Types::URI qw/ Uri /;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 32 ▶use MooseX::Types::Common::String qw/ NonEmptySimpleStr /;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 32 ▶use XML::Generator;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 32 ▶use List::Util qw(any);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 32 ▶use URN::OASIS::SAML2 qw(:urn BINDING_HTTP_POST);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 32 ▶use Net::SAML2::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 32 with 'Net::SAML2::Role::ProtocolMessage';
13  
14 # ABSTRACT: SAML2 AuthnRequest object
15  
16  
17  
18 32 has 'nameid' => (
19 isa => NonEmptySimpleStr,
20 is => 'rw',
21 predicate => 'has_nameid'
22 );
23  
24 32 has 'nameidpolicy_format' => (
25 isa => 'Str',
26 is => 'rw',
27 predicate => 'has_nameidpolicy_format'
28 );
29  
30 32 has 'nameid_allow_create' => (
31 isa => 'Bool',
32 is => 'rw',
33 required => 0,
34 predicate => 'has_nameid_allow_create'
35 );
36  
37 32 has 'assertion_url' => (
38 isa => Uri,
39 is => 'rw',
40 coerce => 1,
41 predicate => 'has_assertion_url',
42 );
43  
44 32 has 'assertion_index' => (
45 isa => 'Int',
46 is => 'rw',
47 predicate => 'has_assertion_index',
48 );
49  
50 32 has 'attribute_index' => (
51 isa => 'Int',
52 is => 'rw',
53 predicate => 'has_attribute_index',
54 );
55  
56 32 has 'protocol_binding' => (
57 isa => Uri,
58 is => 'rw',
59 coerce => 1,
60 predicate => 'has_protocol_binding',
61 );
62 32 has 'provider_name' => (
63 isa => 'Str',
64 is => 'rw',
65 predicate => 'has_provider_name',
66 );
67  
68 has 'AuthnContextClassRef' => (
69 isa => 'ArrayRef[Str]',
70 is => 'rw',
71 11 ▶ default => sub { [] }
Subroutine __ANON__: called CC=1 SCAR=0.0
72 32 );
73  
74 has 'AuthnContextDeclRef' => (
75 isa => 'ArrayRef[Str]',
76 is => 'rw',
77 11 ▶ default => sub { [] }
Subroutine __ANON__: called CC=1 SCAR=0.0
78 32 );
79  
80 32 has 'RequestedAuthnContext_Comparison' => (
81 isa => 'Str',
82 is => 'rw',
83 default => 'exact'
84 );
85  
86 32 has 'force_authn' => (
87 isa => 'Bool',
88 is => 'ro',
89 predicate => 'has_force_authn',
90 );
91  
92 32 has 'is_passive' => (
93 isa => 'Bool',
94 is => 'ro',
95 predicate => 'has_is_passive',
96 );
97  
98 32 has identity_providers => (
99 isa => 'ArrayRef[Str]',
100 is => 'ro',
101 predicate => 'has_identity_providers',
102 );
103  
104 12 ▶around BUILDARGS => sub {
Subroutine __ANON__: called CC=3 SCAR=13.0
105 12 my $orig = shift;
106 12 my $self = shift;
107  
108 12 my %params = @_;
109 12 ▶ if ($params{nameid_format} && !defined $params{nameidpolicy_format}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params{"nameid_format"} and not defined $params{"nameidpolicy_format"}) 0 12 12
Condition33%1/3
$params{"nameid_format"} and not defined $params{"nameidpolicy_format"}
!ll&&!rl&&r
1200
MC/DC0%0/2
$params{"nameid_format"} and not defined $params{"nameidpolicy_format"}
$params{"nameid_format"} not defined $params{"nameidpolicy_format"}
Truth table33%1/3
A and not(B)
A= $params{"nameid_format"}B= not defined $params{"nameidpolicy_format"}
ABresult
0X0
100
111
110 0 Net::SAML2::Util::deprecation_warning "You are using nameid_format, "
111 . "this field has changed to nameidpolicy_format. This field will "
112 . "be used for other purposes in an upcoming release. Please change "
113 . "your code ASAP.";
114 0 $params{nameidpolicy_format} = $params{nameid_format};
115 }
116  
117 12 return $self->$orig(%params);
118 32 };
119  
120  
121 32 my $samlp = ['samlp' => URN_PROTOCOL];
122 32 my $saml = ['saml' => URN_ASSERTION];
123  
124 12 ▶sub as_xml {
Subroutine as_xml: called CC=10 SCAR=23.0
Pod documented
125 12 my ($self) = @_;
126  
127 12 my $x = XML::Generator->new(':std');
128  
129 12 my %req_atts = (
130 ID => $self->id,
131 IssueInstant => $self->issue_instant,
132 Version => '2.0',
133 );
134  
135 12 my %issuer_attrs = ();
136  
137 12 my %protocol_bindings
138 = ('HTTP-POST' => BINDING_HTTP_POST);
139  
140 12 my %att_map = (
141 'assertion_url' => 'AssertionConsumerServiceURL',
142 'assertion_index' => 'AssertionConsumerServiceIndex',
143 'attribute_index' => 'AttributeConsumingServiceIndex',
144 'protocol_binding' => 'ProtocolBinding',
145 'provider_name' => 'ProviderName',
146 'destination' => 'Destination',
147 'issuer_namequalifier' => 'NameQualifier',
148 'issuer_format' => 'Format',
149 'force_authn' => 'ForceAuthn',
150 'is_passive' => 'IsPassive',
151 );
152  
153 12 my @opts = qw(
154 assertion_url assertion_index protocol_binding
155 attribute_index provider_name destination
156 force_authn is_passive
157 );
158  
159 12 foreach my $opt (@opts) {
160 96 my $predicate = 'has_' . $opt;
161 96 ▶ next if !$self->can($predicate) || !$self->$predicate;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->can($predicate) and $self->$predicate 73 23 96
Condition66%2/3
$self->can($predicate) and $self->$predicate
!ll&&!rl&&r
07323
MC/DC50%1/2
$self->can($predicate) and $self->$predicate
$self->can($predicate) $self->$predicate
Truth table66%2/3
A and B
A= $self->can($predicate)B= $self->$predicate
ABresult
0X0
100
111
162  
163 23 my $val = $self->$opt;
164 23 ▶ if ($opt eq 'protocol_binding') {
Branch: 2 branches
BranchTrueFalseTotal
if ($opt eq 'protocol_binding') { } 1 22 23
elsif (&any(sub { $opt eq $_; } , 'force_authn', 'is_passive')) { } 6 16 22
165 1 $req_atts{ $att_map{$opt} } = $protocol_bindings{$val};
166 }
167 41 ▶ elsif (any { $opt eq $_ } qw(force_authn is_passive)) {
Subroutine __ANON__: called CC=1 SCAR=0.0
168 6 ▶ $req_atts{ $att_map{$opt} } = ($val ? 'true' : 'false');
Branch: 1 branch
BranchTrueFalseTotal
$val ? : 3 3 6
169 }
170 else {
171 16 $req_atts{ $att_map{$opt} } = $val;
172 }
173 }
174  
175 12 foreach my $opt (qw(issuer_namequalifier issuer_format)) {
176 24 my $predicate = 'has_' . $opt;
177 24 ▶ next if !$self->can($predicate) || !$self->$predicate;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->can($predicate) and $self->$predicate 22 2 24
Condition66%2/3
$self->can($predicate) and $self->$predicate
!ll&&!rl&&r
0222
MC/DC50%1/2
$self->can($predicate) and $self->$predicate
$self->can($predicate) $self->$predicate
Truth table66%2/3
A and B
A= $self->can($predicate)B= $self->$predicate
ABresult
0X0
100
111
178  
179 2 my $val = $self->$opt;
180 2 $issuer_attrs{ $att_map{$opt} } = $val;
181 }
182  
183 12 return $x->AuthnRequest($samlp,
184 \%req_atts,
185 $x->Issuer($saml, \%issuer_attrs, $self->issuer),
186 $self->_set_name_id($x),
187 $self->_set_name_policy_format($x),
188 $self->_set_requested_authn_context($x),
189 $self->_set_scoping($x),
190 );
191  
192 }
193  
194 12 ▶sub _set_scoping {
Subroutine _set_scoping: called CC=2 SCAR=6.9
195 12 my $self = shift;
196 12 ▶ return unless $self->has_identity_providers;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_identity_providers 11 1 12
197 1 my $x = shift;
198  
199 3 my @providers = map { $x->IDPEntry($samlp, { ProviderID => $_ }) }
200 1 @{ $self->identity_providers };
201 1 return $x->Scoping($samlp, $x->IDPList($samlp, @providers));
202 }
203  
204 12 ▶sub _set_name_id {
Subroutine _set_name_id: called CC=2 SCAR=6.9
205 12 my $self = shift;
206 12 ▶ return unless $self->has_nameid;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_nameid 11 1 12
207 1 my $x = shift;
208 1 return $x->Subject($saml, $x->NameID($saml, {NameQualifier => $self->nameid}));
209 }
210  
211 12 ▶sub _set_name_policy_format {
Subroutine _set_name_policy_format: called CC=3 SCAR=11.0
212 12 my $self = shift;
213 12 ▶ return unless $self->has_nameidpolicy_format;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_nameidpolicy_format 7 5 12
214 5 my $x = shift;
215 5 ▶ return $x->NameIDPolicy(
Branch: 1 branch
BranchTrueFalseTotal
$self->has_nameid_allow_create ? : 1 4 5
216 $samlp,
217 {
218 Format => $self->nameidpolicy_format,
219 $self->has_nameid_allow_create
220 ? (AllowCreate => $self->nameid_allow_create)
221 : (),
222 }
223 );
224  
225 }
226  
227 12 ▶sub _set_requested_authn_context {
Subroutine _set_requested_authn_context: called CC=3 SCAR=11.0
228 12 my ($self, $x) = @_;
229  
230 return
231 12 if !@{ $self->AuthnContextClassRef }
232 12 ▶ && !@{ $self->AuthnContextDeclRef };
Branch: 1 branch
BranchTrueFalseTotal
unless @{$self->AuthnContextClassRef;} or @{$self->AuthnContextDeclRef;} 10 2 12
Condition100%3/3
@{$self->AuthnContextClassRef;} or @{$self->AuthnContextDeclRef;}
l!l&&r!l&&!r
1110
MC/DC100%2/2
@{$self->AuthnContextClassRef;} or @{$self->AuthnContextDeclRef;}
@{$self->AuthnContextClassRef;} @{$self->AuthnContextDeclRef;}
Truth table100%3/3
A or B
A= @{$self->AuthnContextClassRef;}B= @{$self->AuthnContextDeclRef;}
ABresult
1X1
011
000
233  
234 2 my @class = map { $x->AuthnContextClassRef($saml, undef, $_) }
235 2 @{ $self->AuthnContextClassRef };
236  
237 2 my @decl = map { $x->AuthnContextDeclRef($saml, undef, $_) }
238 2 @{ $self->AuthnContextDeclRef };
239  
240 2 return $x->RequestedAuthnContext(
241 $samlp,
242 { Comparison => $self->RequestedAuthnContext_Comparison },
243 @class, @decl
244 );
245 }
246  
247 32 __PACKAGE__->meta->make_immutable;
248  
249 __END__
« SAML2/SP.pm ↑ Summary SAML2/Protocol/LogoutRequest.pm »