Skip to content

Commit 10b9ab0

Browse files
committed
Only use defaults/required attrs in net_saml2_sp() test method
Setup a bare minimum SP with just the defaults so it is easier to override these defaults. Currently, in order to test this minimal thing we need to setup the minimal thing while we can easily expand the caller to add their flavor. Signed-off-by: Wesley Schwengle <wesley@opndev.io>
1 parent 55d6e5e commit 10b9ab0

File tree

2 files changed

+83
-83
lines changed

2 files changed

+83
-83
lines changed

t/02-create-sp.t

Lines changed: 71 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -3,61 +3,71 @@ use warnings;
33
use Test::Lib;
44
use Test::Net::SAML2;
55

6-
my $sp = net_saml2_sp();
7-
8-
my $xpath = get_xpath(
9-
$sp->metadata,
10-
md => 'urn:oasis:names:tc:SAML:2.0:metadata',
11-
ds => 'http://www.w3.org/2000/09/xmldsig#'
12-
);
13-
14-
my $node
15-
= get_single_node_ok($xpath, '//md:EntityDescriptor/md:SPSSODescriptor');
16-
ok(!$node->getAttribute('WantAssertionsSigned'),
17-
'Wants assertions to be signed');
18-
ok(
19-
!$node->getAttribute('AuthnRequestsSigned'),
20-
'.. and also authn requests to be signed'
21-
);
22-
23-
my @ssos = $xpath->findnodes(
24-
'//md:EntityDescriptor/md:SPSSODescriptor/md:AssertionConsumerService');
25-
26-
if (is(@ssos, 2, "Got two assertionConsumerService(s)")) {
27-
is(
28-
$ssos[0]->getAttribute('Binding'),
29-
'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST',
30-
"Returns the correct binding: HTTP-POST"
31-
);
32-
is(
33-
$ssos[1]->getAttribute('Binding'),
34-
'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Artifact',
35-
"Returns the correct binding: HTTP-Artifact"
36-
);
37-
}
38-
396
{
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"
7+
my $sp = net_saml2_sp(
8+
authnreq_signed => 0,
9+
want_assertions_signed => 0,
10+
slo_url_post => '/sls-post-response',
11+
slo_url_soap => '/slo-soap',
4712
);
4813

49-
$node = get_single_node_ok($xpath,
50-
'//md:SingleLogoutService[@Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST"]'
14+
my $xpath = get_xpath(
15+
$sp->metadata,
16+
md => 'urn:oasis:names:tc:SAML:2.0:metadata',
17+
ds => 'http://www.w3.org/2000/09/xmldsig#'
5118
);
52-
is(
53-
$node->getAttribute('Location'),
54-
'http://localhost:3000/sls-post-response',
55-
".. with the correct location"
19+
20+
my $node
21+
= get_single_node_ok($xpath,
22+
'//md:EntityDescriptor/md:SPSSODescriptor');
23+
ok(!$node->getAttribute('WantAssertionsSigned'),
24+
'Wants assertions to be signed');
25+
ok(
26+
!$node->getAttribute('AuthnRequestsSigned'),
27+
'.. and also authn requests to be signed'
5628
);
57-
}
5829

30+
my @ssos
31+
= $xpath->findnodes(
32+
'//md:EntityDescriptor/md:SPSSODescriptor/md:AssertionConsumerService'
33+
);
5934

60-
get_single_node_ok($xpath, '//ds:Signature');
35+
if (is(@ssos, 2, "Got two assertionConsumerService(s)")) {
36+
is(
37+
$ssos[0]->getAttribute('Binding'),
38+
'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST',
39+
"Returns the correct binding: HTTP-POST"
40+
);
41+
is(
42+
$ssos[1]->getAttribute('Binding'),
43+
'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Artifact',
44+
"Returns the correct binding: HTTP-Artifact"
45+
);
46+
}
47+
48+
{
49+
my $node = get_single_node_ok($xpath,
50+
'//md:SingleLogoutService[@Binding="urn:oasis:names:tc:SAML:2.0:bindings:SOAP"]'
51+
);
52+
is(
53+
$node->getAttribute('Location'),
54+
'http://localhost:3000/slo-soap',
55+
".. with the correct location"
56+
);
57+
58+
$node = get_single_node_ok($xpath,
59+
'//md:SingleLogoutService[@Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST"]'
60+
);
61+
is(
62+
$node->getAttribute('Location'),
63+
'http://localhost:3000/sls-post-response',
64+
".. with the correct location"
65+
);
66+
}
67+
68+
69+
get_single_node_ok($xpath, '//ds:Signature');
70+
}
6171

6272
{
6373
my $sp = net_saml2_sp(sign_metadata => 0);
@@ -73,23 +83,7 @@ get_single_node_ok($xpath, '//ds:Signature');
7383
}
7484

7585
{
76-
my $sp = Net::SAML2::SP->new(
77-
id => 'Some entity ID',
78-
url => 'http://localhost:3000',
79-
cert => 't/sign-nopw-cert.pem',
80-
key => 't/sign-nopw-cert.pem',
81-
cacert => 't/cacert.pem',
82-
83-
org_name => 'Net::SAML2::SP',
84-
org_display_name => 'Net::SAML2::SP testsuite',
85-
org_contact => 'test@example.com',
86-
87-
org_url => 'http://www.example.com',
88-
slo_url_redirect => '/sls-redirect-response',
89-
acs_url_post => '/consumer-post',
90-
acs_url_artifact => '/consumer-artifact',
91-
error_url => '/error',
92-
);
86+
my $sp = net_saml2_sp();
9387

9488
my $xpath = get_xpath(
9589
$sp->metadata,
@@ -174,10 +168,18 @@ get_single_node_ok($xpath, '//ds:Signature');
174168
}
175169

176170
# 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");
171+
ok(
172+
!$xpath->findnodes(
173+
'//md:SingleLogoutService[@Binding="urn:oasis:names:tc:SAML:2.0:bindings:SOAP"]'
174+
),
175+
"No node found for slo_url_soap"
176+
);
177+
ok(
178+
!$xpath->findnodes(
179+
'//md:SingleLogoutService[@Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST"]'
180+
),
181+
"No node found for slo_url_post"
182+
);
181183

182184
{
183185
# Test Signature

t/lib/Test/Net/SAML2/Util.pm

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,26 +34,24 @@ use URI::URL;
3434

3535
sub net_saml2_sp {
3636
return Net::SAML2::SP->new(
37-
id => 'http://localhost:3000',
38-
url => 'http://localhost:3000',
39-
cert => 't/sign-nopw-cert.pem',
40-
key => 't/sign-nopw-cert.pem',
41-
cacert => 't/cacert.pem',
42-
org_name => 'Test',
43-
org_display_name => 'Test',
37+
38+
39+
id => 'Some entity ID',
40+
cert => 't/sign-nopw-cert.pem',
41+
key => 't/sign-nopw-cert.pem',
42+
cacert => 't/cacert.pem',
43+
44+
org_name => 'Net::SAML2::SP',
45+
org_display_name => 'Net::SAML2::SP testsuite',
4446
org_contact => 'test@example.com',
4547
org_url => 'http://www.example.com',
46-
slo_url_soap => '/slo-soap',
48+
49+
url => 'http://localhost:3000',
4750
slo_url_redirect => '/sls-redirect-response',
48-
slo_url_post => '/sls-post-response',
4951
acs_url_post => '/consumer-post',
5052
acs_url_artifact => '/consumer-artifact',
51-
org_name => 'Net::SAML2 Saml2Test',
52-
org_display_name => 'Saml2Test app for Net::SAML2',
53-
org_contact => 'saml2test@example.com',
5453
error_url => '/error',
55-
authnreq_signed => '0',
56-
want_assertions_signed => '0',
54+
5755
@_,
5856
);
5957
}

0 commit comments

Comments
 (0)