@@ -11,9 +11,8 @@ my $xpath = get_xpath(
1111 ds => ' http://www.w3.org/2000/09/xmldsig#'
1212);
1313
14- my $nodes = $xpath -> findnodes(' //md:EntityDescriptor/md:SPSSODescriptor' );
15- is($nodes -> size, 1, " We have one PSSODescriptor" );
16- my $node = $nodes -> get_node(1);
14+ my $node
15+ = get_single_node_ok($xpath , ' //md:EntityDescriptor/md:SPSSODescriptor' );
1716ok(!$node -> getAttribute(' WantAssertionsSigned' ),
1817 ' Wants assertions to be signed' );
1918ok(
@@ -37,54 +36,120 @@ if (is(@ssos, 2, "Got two assertionConsumerService(s)")) {
3736 );
3837}
3938
39+ get_single_node_ok($xpath , ' //ds:Signature' );
40+
41+ {
42+ my $sp = net_saml2_sp(sign_metadata => 0);
43+ my $xpath = get_xpath(
44+ $sp -> metadata,
45+ md => ' urn:oasis:names:tc:SAML:2.0:metadata' ,
46+ ds => ' http://www.w3.org/2000/09/xmldsig#'
47+ );
48+
49+ my $nodes = $xpath -> findnodes(' //ds:Signature' );
50+ is($nodes -> size(), 0, " We don't have any ds:Signature present" );
51+
52+ }
53+
4054{
4155 my $sp = Net::SAML2::SP-> new(
42- id => ' http://localhost:3000' ,
43- url => ' http://localhost:3000' ,
44- cert => ' t/sign-nopw-cert.pem' ,
45- key => ' t/sign-nopw-cert.pem' ,
46- cacert => ' t/cacert.pem' ,
47- org_name => ' Test' ,
48- org_display_name => ' Test' ,
56+ id => ' Some entity ID' ,
57+ url => ' http://localhost:3000' ,
58+ cert => ' t/sign-nopw-cert.pem' ,
59+ key => ' t/sign-nopw-cert.pem' ,
60+ cacert => ' t/cacert.pem' ,
61+
62+ org_name => ' Net::SAML2::SP' ,
63+ org_display_name => ' Net::SAML2::SP testsuite' ,
4964 org_contact => ' test@example.com' ,
65+
5066 org_url => ' http://www.example.com' ,
5167 slo_url_soap => ' /slo-soap' ,
5268 slo_url_redirect => ' /sls-redirect-response' ,
5369 slo_url_post => ' /sls-post-response' ,
5470 acs_url_post => ' /consumer-post' ,
5571 acs_url_artifact => ' /consumer-artifact' ,
56- org_name => ' Net::SAML2 Saml2Test' ,
57- org_display_name => ' Saml2Test app for Net::SAML2' ,
58- org_contact => ' saml2test@example.com' ,
5972 error_url => ' /error' ,
6073 );
6174
62- my $xpath = get_xpath($sp -> metadata,
63- md => ' urn:oasis:names:tc:SAML:2.0:metadata' );
64- my $nodes = $xpath -> findnodes(' //md:EntityDescriptor/md:SPSSODescriptor' );
65- is($nodes -> size, 1, " We have one PSSODescriptor" );
66- my $node = $nodes -> get_node(1);
67- ok($node -> getAttribute(' WantAssertionsSigned' ),
68- ' Wants assertions to be signed' );
69- ok(
70- $node -> getAttribute(' AuthnRequestsSigned' ),
71- ' .. and also authn requests to be signed'
72- );
73- }
74-
75- $nodes = $xpath -> findnodes(' //ds:Signature' );
76- is($nodes -> size(), 1, " We have a signed metadata document ds:Signature present" );
77-
78- {
79- my $sp = net_saml2_sp(sign_metadata => 0);
80- my $xpath = get_xpath(
75+ my $xpc = get_xpath(
8176 $sp -> metadata,
8277 md => ' urn:oasis:names:tc:SAML:2.0:metadata' ,
8378 ds => ' http://www.w3.org/2000/09/xmldsig#'
8479 );
8580
86- my $nodes = $xpath -> findnodes(' //ds:Signature' );
87- is($nodes -> size(), 0, " We don't have any ds:Signature present" );
81+ my $node = get_single_node_ok($xpc , ' /md:EntityDescriptor' );
82+ is(
83+ $node -> getAttribute(' entityID' ),
84+ ' Some entity ID' ,
85+ ' .. has the correct entity ID'
86+ );
87+
88+ ok($node -> getAttribute(' ID' ), ' .. has an ID' );
89+
90+ {
91+ # Test ContactPerson
92+ my $node = get_single_node_ok($xpc , ' /node()/md:ContactPerson' );
93+ my $p = $node -> nodePath();
94+
95+ my $company = get_single_node_ok($xpc , " $p /md:Company" );
96+ is(
97+ $company -> textContent,
98+ ' Net::SAML2::SP testsuite' ,
99+ " Got the correct company name for the contact person"
100+ );
101+
102+ my $email = get_single_node_ok($xpc , " $p /md:EmailAddress" );
103+ is($email -> textContent, ' test@example.com' ,
104+ " .. and the correct email" );
105+ }
106+
107+ {
108+ # Test Organisation
109+ my $node = get_single_node_ok($xpc , ' /node()/md:Organization' );
110+ my $p = $node -> nodePath();
111+
112+ my $name = get_single_node_ok($xpc , " $p /md:OrganizationName" );
113+ is(
114+ $name -> textContent,
115+ ' Net::SAML2::SP' ,
116+ " Got the correct company name"
117+ );
118+
119+ my $display_name
120+ = get_single_node_ok($xpc , " $p /md:OrganizationDisplayName" );
121+ is(
122+ $display_name -> textContent,
123+ ' Net::SAML2::SP testsuite' ,
124+ " .. and the correct display name"
125+ );
126+
127+ my $url = get_single_node_ok($xpc , " $p /md:OrganizationURL" );
128+ is($url -> textContent, ' http://www.example.com' ,
129+ " .. and the correct URI" );
130+ }
131+
132+ {
133+ # Test SPSSODescriptor
134+ my $node = get_single_node_ok($xpc , ' /node()/md:SPSSODescriptor' );
135+ is($node -> getAttribute(' AuthnRequestsSigned' ),
136+ ' 1' , ' .. and authn request needs signing' );
137+ is($node -> getAttribute(' WantAssertionsSigned' ),
138+ ' 1' , ' .. as does assertions' );
139+ is(
140+ $node -> getAttribute(' errorURL' ),
141+ ' http://localhost:3000/error' ,
142+ ' Got the correct error URI'
143+ );
144+
145+ # TODO: Add more tests for other metadata parts
146+
147+ }
148+
149+ {
150+ # Test Signature
151+ my $node = get_single_node_ok($xpc , ' /node()/ds:Signature' );
152+ }
88153
89154}
90155
0 commit comments