Skip to content

Commit b25642f

Browse files
committed
Make some URI's optional in the constructor
Not all URI's are mandatory for metadata creation * slo_url_post * slo_url_soap These can now be omitted in the constructor and we are able to build the correct metadata. Signed-off-by: Wesley Schwengle <wesley@opndev.io>
1 parent 57142a1 commit b25642f

File tree

2 files changed

+51
-18
lines changed

2 files changed

+51
-18
lines changed

lib/Net/SAML2/SP.pm

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ has 'key' => (isa => 'Str', is => 'ro', required => 1);
104104
has 'cacert' => (isa => 'Maybe[Str]', is => 'ro', required => 1);
105105

106106
has 'error_url' => (isa => 'Str', is => 'ro', required => 1);
107-
has 'slo_url_soap' => (isa => 'Str', is => 'ro', required => 1);
107+
has 'slo_url_soap' => (isa => 'Str', is => 'ro', required => 0, predicate => 'has_slo_url_soap');
108+
has 'slo_url_post' => (isa => 'Str', is => 'ro', required => 0, predicate => 'has_slo_url_post');
108109
has 'slo_url_redirect' => (isa => 'Str', is => 'ro', required => 1);
109-
has 'slo_url_post' => (isa => 'Str', is => 'ro', required => 1);
110110
has 'acs_url_post' => (isa => 'Str', is => 'ro', required => 1);
111111
has 'acs_url_artifact' => (isa => 'Str', is => 'ro', required => 1);
112112

@@ -359,21 +359,29 @@ sub generate_metadata {
359359

360360
)
361361
),
362-
$x->SingleLogoutService(
363-
$md,
364-
{ Binding => 'urn:oasis:names:tc:SAML:2.0:bindings:SOAP',
365-
Location => $self->url . $self->slo_url_soap },
366-
),
362+
$self->has_slo_url_soap ?
363+
$x->SingleLogoutService(
364+
$md,
365+
{ Binding => 'urn:oasis:names:tc:SAML:2.0:bindings:SOAP',
366+
Location => $self->url . $self->slo_url_soap },
367+
) : (),
368+
367369
$x->SingleLogoutService(
368370
$md,
369371
{ Binding => 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect',
370372
Location => $self->url . $self->slo_url_redirect },
371373
),
372-
$x->SingleLogoutService(
373-
$md,
374-
{ Binding => 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST',
375-
Location => $self->url . $self->slo_url_post },
376-
),
374+
375+
$self->has_slo_url_post ?
376+
$x->SingleLogoutService(
377+
$md,
378+
{
379+
Binding =>
380+
'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST',
381+
Location => $self->url . $self->slo_url_post
382+
},
383+
) : (),
384+
377385
$x->AssertionConsumerService(
378386
$md,
379387
{ Binding => 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST',

t/02-create-sp.t

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,27 @@ if (is(@ssos, 2, "Got two assertionConsumerService(s)")) {
3636
);
3737
}
3838

39+
{
40+
my $node = get_single_node_ok($xpath,
41+
'//md:SingleLogoutService[@Binding="urn:oasis:names:tc:SAML:2.0:bindings:SOAP"]'
42+
);
43+
is(
44+
$node->getAttribute('Location'),
45+
'http://localhost:3000/slo-soap',
46+
".. with the correct location"
47+
);
48+
49+
$node = get_single_node_ok($xpath,
50+
'//md:SingleLogoutService[@Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST"]'
51+
);
52+
is(
53+
$node->getAttribute('Location'),
54+
'http://localhost:3000/sls-post-response',
55+
".. with the correct location"
56+
);
57+
}
58+
59+
3960
get_single_node_ok($xpath, '//ds:Signature');
4061

4162
{
@@ -64,9 +85,7 @@ get_single_node_ok($xpath, '//ds:Signature');
6485
org_contact => 'test@example.com',
6586

6687
org_url => 'http://www.example.com',
67-
slo_url_soap => '/slo-soap',
6888
slo_url_redirect => '/sls-redirect-response',
69-
slo_url_post => '/sls-post-response',
7089
acs_url_post => '/consumer-post',
7190
acs_url_artifact => '/consumer-artifact',
7291
error_url => '/error',
@@ -154,11 +173,17 @@ get_single_node_ok($xpath, '//ds:Signature');
154173
ok($keyname->textContent, "... and we have a key name");
155174
}
156175

157-
}
176+
# These nodes are missing
177+
ok(!$xpath->findnodes('//md:SingleLogoutService[@Binding="urn:oasis:names:tc:SAML:2.0:bindings:SOAP"]'),
178+
"No node found for slo_url_soap");
179+
ok(!$xpath->findnodes('//md:SingleLogoutService[@Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST"]'),
180+
"No node found for slo_url_post");
158181

159-
{
160-
# Test Signature
161-
my $node = get_single_node_ok($xpath, '/node()/ds:Signature');
182+
{
183+
# Test Signature
184+
my $node = get_single_node_ok($xpath, '/node()/ds:Signature');
185+
186+
}
162187

163188
}
164189

0 commit comments

Comments
 (0)