Skip to content

Commit 1206d4a

Browse files
authored
Merge pull request #89 from waterkip/GH-saml-request_requiredness
Make params optional in Binding::Redirect for SAMLResponse
2 parents 1841b8f + 8b83b3e commit 1206d4a

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

lib/Net/SAML2/Binding/Redirect.pm

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package Net::SAML2::Binding::Redirect;
66
use Moose;
77
use MooseX::Types::URI qw/ Uri /;
88
use Net::SAML2::Types qw(signingAlgorithm SAMLRequestType);
9+
use Carp qw(croak);
910

1011
# ABSTRACT: Net::SAML2::Binding::Redirect - HTTP Redirect binding for SAML
1112

@@ -96,9 +97,9 @@ The double encoding requires it to be decoded prior to processing.
9697
9798
=cut
9899

99-
has 'key' => (isa => 'Str', is => 'ro', required => 1);
100100
has 'cert' => (isa => 'Str', is => 'ro', required => 1);
101-
has 'url' => (isa => Uri, is => 'ro', required => 1, coerce => 1);
101+
has 'url' => (isa => Uri, is => 'ro', required => 0, coerce => 1, predicate => 'has_url');
102+
has 'key' => (isa => 'Str', is => 'ro', required => 0, predicate => 'has_key');
102103

103104
has 'param' => (
104105
isa => SAMLRequestType,
@@ -128,6 +129,16 @@ has 'sls_double_encoded_response' => (
128129
default => 0
129130
);
130131

132+
sub BUILD {
133+
my $self = shift;
134+
135+
if ($self->param eq 'SAMLRequest') {
136+
croak("Need to have an URL specified") unless $self->has_url;
137+
croak("Need to have a key specified") unless $self->has_key;
138+
}
139+
# other params don't need to have these per-se
140+
}
141+
131142
=head2 sign( $request, $relaystate )
132143
133144
Signs the given request, and returns the URL to which the user's

t/06-redirect-binding.t

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use Test::Lib;
44
use Test::Net::SAML2;
55

66
use Net::SAML2::IdP;
7+
use Net::SAML2::Binding::Redirect;
78

89
my $sp = net_saml2_sp();
910

@@ -51,4 +52,37 @@ test_xml_attribute_ok($xp, '/saml2p:AuthnRequest/@ID', qr/^NETSAML2_/,
5152

5253
is($relaystate, 'http://return/url', "Relay state shows correct uri");
5354

55+
lives_ok(
56+
sub {
57+
my $binding = Net::SAML2::Binding::Redirect->new(
58+
cert => $sp->cert,
59+
param => 'SAMLResponse',
60+
);
61+
isa_ok($binding, "Net::SAML2::Binding::Redirect");
62+
},
63+
"We can create a binding redirect without key/url for verification purposes"
64+
);
65+
66+
throws_ok(
67+
sub {
68+
Net::SAML2::Binding::Redirect->new(
69+
cert => $sp->cert,
70+
key => $sp->key,
71+
);
72+
},
73+
qr/Need to have an URL specified/,
74+
"Need an URL for SAMLRequest"
75+
);
76+
77+
throws_ok(
78+
sub {
79+
Net::SAML2::Binding::Redirect->new(
80+
cert => $sp->cert,
81+
url => 'https://foo.example.com',
82+
);
83+
},
84+
qr/Need to have a key specified/,
85+
"Need a key for SAMLRequest"
86+
);
87+
5488
done_testing;

0 commit comments

Comments
 (0)