Mojo/SAML/Document/AuthnRequest.pm untested

filter: Statementstmt 0.0% 0 / 41 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 4 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 77 CC 11 SCAR 41.1
CC
11
Cov
0%
tag_attrs
90.0
before_render
12.0
BEGIN
2.0
CRAP 60.7
1 package Mojo::SAML::Document::AuthnRequest;
2  
3 use Mojo::Base 'Mojo::SAML::Document';
4  
5 use Mojo::SAML::Names;
6  
7 has template => sub { shift->build_template(<<'XML') };
8 %= tag 'samlp:AuthnRequest' => $self->tag_attrs => begin
9 % if (defined(my $issuer = $self->issuer)) {
10 <saml:Issuer><%= $issuer %></saml:Issuer>
11 % }
12 % if (my $policy = $self->nameid_policy) {
13 <%= $policy %>
14 % }
15 <samlp:RequestedAuthnContext Comparison="exact">
16 <saml:AuthnContextClassRef>urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport</saml:AuthnContextClassRef>
17 </samlp:RequestedAuthnContext>
18 % end
19 XML
20  
21 has id => sub { 'MOJOSAML_' . shift->get_guid };
22 has issue_instant => sub { shift->get_instant };
23 has [qw/
24 assertion_consumer_service_index assertion_consumer_service_url
25 protocol_binding provider_name destination
26 is_passive force_authn issuer nameid_policy
27 /];
28  
29 sub before_render {
30 my $self = shift;
31 my $idx = defined $self->assertion_consumer_service_index;
32 my $url = defined $self->assertion_consumer_service_url;
33 if ($idx && $url) {
34 Carp::croak 'Cannot specify both index and url for AssertionConsumerService';
35 } elsif (!($idx || $url)) {
36 $self->assertion_consumer_service_index(0);
37 }
38 }
39  
40 sub tag_attrs {
41 my $self = shift;
42 my @attrs = (
43 'xmlns:samlp' => 'urn:oasis:names:tc:SAML:2.0:protocol',
44 'xmlns:saml' => 'urn:oasis:names:tc:SAML:2.0:assertion',
45 Version => '2.0',
46 ID => $self->id,
47 IssueInstant => $self->issue_instant,
48 );
49  
50 if (defined(my $idx = $self->assertion_consumer_service_index)) {
51 push @attrs, AssertionConsumerServiceIndex => $idx;
52 }
53 if (defined(my $url = $self->assertion_consumer_service_url)) {
54 push @attrs, AssertionConsumerServiceURL => $url;
55 }
56 if (defined(my $binding = $self->protocol_binding)) {
57 push @attrs, ProtocolBinding => Mojo::SAML::Names::binding($binding);
58 }
59 if (defined(my $dest = $self->destination)) {
60 push @attrs, Destination => $dest;
61 }
62  
63 if (defined(my $force = $self->force_authn)) {
64 push @attrs, ForceAuthn => $force ? 'true' : 'false';
65 }
66 if (defined(my $passive = $self->is_passive)) {
67 push @attrs, IsPassive => $passive ? 'true' : 'false';
68 }
69  
70 return @attrs;
71 }
72  
73 1;
74  
75 =head1 NAME
76  
77 Mojo::SAML::Document::AuthnRequest
78  
79 =head1 DESCRIPTION
80  
81 Represents an AuthnRequest SAML protocol tag
82  
83 =head1 ATTRIBUTES
84  
85 L<Mojo::SAML::Document::AuthnRequest> inherits all attributes from L<Mojo::SAML::Document> and implements the following new ones.
86  
87 =head2 id
88  
89 The ID of the request XML document, defaults to C<MOJOSAML_> concatenated with a GUID (see L<Mojo::SAML::Document/get_guid>).
90  
91 =head2 issue_instant
92  
93 The issue instant of the request, defaults to L<Mojo::SAML::Document/get_instant>.
94  
95 =head2 assertion_consumer_service_index
96  
97 The index of the response service, see L<Mojo::SAML::Document::AssertionConsumerService/index>.
98 Exactly one of this or L</assertion_consumer_service_url> is required, however if neither is given, this value will be set to C<0>.
99  
100 =head2 assertion_consumer_service_url
101  
102 The url of the response service.
103 Exactly one of this or L</assertion_consumer_service_index> is required.
104  
105 =head2 destination
106  
107 A url specifying where this request is being sent.
108 Optional but recommended.
109  
110 =head2 force_authn
111  
112 A boolean indicating if authentication should be forced.
113 May be omitted, but assumed false if not given.
114  
115 =head2 protocol_binding
116  
117 If L</assertion_consumer_service_url> is given then this specifies the binding type.
118 Can use a shortened form expanded via L<Mojo::SAML::Names/binding>.
119  
120 =head2 provider_name
121  
122 Optional.
123 The human readable name of the requester service for possible use in display by other agents.
124  
125 =head2 is_passive
126  
127 A boolean indicating if this authentication request should be passive (ie, not disrupt workflow if not authenticatble).
128 May be omitted, but assumed false if not given.
129  
130 =head2 issuer
131  
132 The entity id of the service that generated the request.
133 See L<Mojo::SAML::Document::EntityDescriptor/entity_id>.
134 Optional but recommended.
135  
136 =head2 nameid_policy
137  
138 Optional.
139 An instance of L<Mojo::SAML::Document::NameIDPolicy> specifying the nameid policy to be returned.
140 This is essentially asking for a username vs email address, etc; read more at that document type.
141 If omitted, any identifier for the subject may be returned.
142  
143 =head2 template
144  
145 A template specific to the document type.
146  
147 =head1 METHODS
148  
149 L<Mojo::SAML::Document::AuthnRequest> inherits all methods from L<Mojo::SAML::Document> and implements the following new ones.
150  
151 =head2 tag_attrs
152  
153 Generates a list of attributes for the tag.
154