1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace LightSaml\Tests\Functional\Model\Metadata; |
4
|
|
|
|
5
|
|
|
use LightSaml\Model\Context\DeserializationContext; |
6
|
|
|
use LightSaml\Model\Metadata\ContactPerson; |
7
|
|
|
use LightSaml\Model\Metadata\EntitiesDescriptor; |
8
|
|
|
use LightSaml\SamlConstants; |
9
|
|
|
use LightSaml\Tests\BaseTestCase; |
10
|
|
|
use LightSaml\Tests\Helper\ContactPersonChecker; |
11
|
|
|
use LightSaml\Tests\Helper\EndpointChecker; |
12
|
|
|
use LightSaml\Tests\Helper\IndexedEndpointChecker; |
13
|
|
|
use LightSaml\Tests\Helper\KeyDescriptorChecker; |
14
|
|
|
use LightSaml\Tests\Helper\NameIdFormatChecker; |
15
|
|
|
use LightSaml\Tests\Helper\OrganizationChecker; |
16
|
|
|
|
17
|
|
|
class EntitiesDescriptorFunctionalTest extends BaseTestCase |
18
|
|
|
{ |
19
|
|
|
public function test__deserialize_test_shib() |
20
|
|
|
{ |
21
|
|
|
$context = new DeserializationContext(); |
22
|
|
|
$context->getDocument()->load(__DIR__.'/../../../../../../resources/sample/EntitiesDescriptor/testshib-providers.xml'); |
23
|
|
|
|
24
|
|
|
$entitiesDescriptor = new EntitiesDescriptor(); |
25
|
|
|
$entitiesDescriptor->deserialize($context->getDocument(), $context); |
26
|
|
|
|
27
|
|
|
$this->assertEquals('urn:mace:shibboleth:testshib:two', $entitiesDescriptor->getName()); |
28
|
|
|
$this->assertCount(2, $entitiesDescriptor->getAllEntityDescriptors()); |
|
|
|
|
29
|
|
|
|
30
|
|
|
//region IDP |
31
|
|
|
$ed = $entitiesDescriptor->getByEntityId('https://idp.testshib.org/idp/shibboleth'); |
32
|
|
|
$this->assertNotNull($ed); |
33
|
|
|
$this->assertEquals('https://idp.testshib.org/idp/shibboleth', $ed->getEntityID()); |
34
|
|
|
$this->assertCount(1, $ed->getAllIdpSsoDescriptors()); |
35
|
|
|
|
36
|
|
|
$idp = $ed->getFirstIdpSsoDescriptor(); |
37
|
|
|
$this->assertNotNull($idp); |
38
|
|
|
$this->assertEquals( |
39
|
|
|
'urn:oasis:names:tc:SAML:1.1:protocol urn:mace:shibboleth:1.0 urn:oasis:names:tc:SAML:2.0:protocol', |
40
|
|
|
$idp->getProtocolSupportEnumeration() |
41
|
|
|
); |
42
|
|
|
|
43
|
|
|
$this->assertCount(1, $idp->getAllKeyDescriptors()); |
44
|
|
|
KeyDescriptorChecker::checkCertificateCN($this, null, 'idp.testshib.org', $idp->getFirstKeyDescriptor()); |
45
|
|
|
|
46
|
|
|
NameIdFormatChecker::check($this, $idp, array( |
47
|
|
|
SamlConstants::NAME_ID_FORMAT_TRANSIENT, |
48
|
|
|
SamlConstants::NAME_ID_FORMAT_SHIB_NAME_ID, |
49
|
|
|
)); |
50
|
|
|
|
51
|
|
|
$this->assertCount(4, $idp->getAllSingleSignOnServices()); |
52
|
|
|
EndpointChecker::check( |
53
|
|
|
$this, |
54
|
|
|
SamlConstants::BINDING_SHIB1_AUTHN_REQUEST, |
55
|
|
|
'https://idp.testshib.org/idp/profile/Shibboleth/SSO', |
56
|
|
|
$idp->getFirstSingleSignOnService(SamlConstants::BINDING_SHIB1_AUTHN_REQUEST) |
57
|
|
|
); |
58
|
|
|
EndpointChecker::check( |
59
|
|
|
$this, |
60
|
|
|
SamlConstants::BINDING_SAML2_HTTP_POST, |
61
|
|
|
'https://idp.testshib.org/idp/profile/SAML2/POST/SSO', |
62
|
|
|
$idp->getFirstSingleSignOnService(SamlConstants::BINDING_SAML2_HTTP_POST) |
63
|
|
|
); |
64
|
|
|
EndpointChecker::check( |
65
|
|
|
$this, |
66
|
|
|
SamlConstants::BINDING_SAML2_HTTP_REDIRECT, |
67
|
|
|
'https://idp.testshib.org/idp/profile/SAML2/Redirect/SSO', |
68
|
|
|
$idp->getFirstSingleSignOnService(SamlConstants::BINDING_SAML2_HTTP_REDIRECT) |
69
|
|
|
); |
70
|
|
|
EndpointChecker::check( |
71
|
|
|
$this, |
72
|
|
|
SamlConstants::BINDING_SAML2_SOAP, |
73
|
|
|
'https://idp.testshib.org/idp/profile/SAML2/SOAP/ECP', |
74
|
|
|
$idp->getFirstSingleSignOnService(SamlConstants::BINDING_SAML2_SOAP) |
75
|
|
|
); |
76
|
|
|
|
77
|
|
|
$this->assertEmpty($idp->getAllSingleLogoutServices()); |
78
|
|
|
$this->assertEmpty($idp->getAllAttributes()); |
79
|
|
|
$this->assertEmpty($idp->getAllOrganizations()); |
80
|
|
|
$this->assertEmpty($idp->getAllContactPersons()); |
81
|
|
|
|
82
|
|
|
$this->assertCount(1, $ed->getAllOrganizations()); |
83
|
|
|
OrganizationChecker::check( |
84
|
|
|
$this, |
85
|
|
|
'TestShib Two Identity Provider', |
86
|
|
|
'TestShib Two', |
87
|
|
|
'http://www.testshib.org/testshib-two/', |
88
|
|
|
$ed->getFirstOrganization() |
89
|
|
|
); |
90
|
|
|
|
91
|
|
|
$this->assertCount(1, $ed->getAllContactPersons()); |
92
|
|
|
ContactPersonChecker::check( |
93
|
|
|
$this, |
94
|
|
|
ContactPerson::TYPE_TECHNICAL, |
95
|
|
|
null, |
96
|
|
|
'Nate', |
97
|
|
|
'Klingenstein', |
98
|
|
|
'[email protected]', |
99
|
|
|
null, |
100
|
|
|
$ed->getFirstContactPerson() |
101
|
|
|
); |
102
|
|
|
unset($idp); |
103
|
|
|
//endregion |
104
|
|
|
|
105
|
|
|
|
106
|
|
|
//region SP |
107
|
|
|
$ed = $entitiesDescriptor->getByEntityId('https://sp.testshib.org/shibboleth-sp'); |
108
|
|
|
$this->assertNotNull($ed); |
109
|
|
|
$this->assertEquals('https://sp.testshib.org/shibboleth-sp', $ed->getEntityID()); |
110
|
|
|
$this->assertCount(1, $ed->getAllSpSsoDescriptors()); |
111
|
|
|
|
112
|
|
|
$sp = $ed->getFirstSpSsoDescriptor(); |
113
|
|
|
$this->assertNotNull($sp); |
114
|
|
|
$this->assertEquals( |
115
|
|
|
'urn:oasis:names:tc:SAML:2.0:protocol urn:oasis:names:tc:SAML:1.1:protocol http://schemas.xmlsoap.org/ws/2003/07/secext', |
116
|
|
|
$sp->getProtocolSupportEnumeration() |
117
|
|
|
); |
118
|
|
|
|
119
|
|
|
$this->assertCount(1, $sp->getAllKeyDescriptors()); |
120
|
|
|
KeyDescriptorChecker::checkCertificateCN($this, null, 'sp.testshib.org', $sp->getFirstKeyDescriptor()); |
121
|
|
|
|
122
|
|
|
$this->assertCount(4, $sp->getAllSingleLogoutServices()); |
123
|
|
|
EndpointChecker::check( |
124
|
|
|
$this, |
125
|
|
|
SamlConstants::BINDING_SAML2_SOAP, |
126
|
|
|
'https://sp.testshib.org/Shibboleth.sso/SLO/SOAP', |
127
|
|
|
$sp->getFirstSingleLogoutService(SamlConstants::BINDING_SAML2_SOAP) |
128
|
|
|
); |
129
|
|
|
EndpointChecker::check( |
130
|
|
|
$this, |
131
|
|
|
SamlConstants::BINDING_SAML2_HTTP_REDIRECT, |
132
|
|
|
'https://sp.testshib.org/Shibboleth.sso/SLO/Redirect', |
133
|
|
|
$sp->getFirstSingleLogoutService(SamlConstants::BINDING_SAML2_HTTP_REDIRECT) |
134
|
|
|
); |
135
|
|
|
EndpointChecker::check( |
136
|
|
|
$this, |
137
|
|
|
SamlConstants::BINDING_SAML2_HTTP_POST, |
138
|
|
|
'https://sp.testshib.org/Shibboleth.sso/SLO/POST', |
139
|
|
|
$sp->getFirstSingleLogoutService(SamlConstants::BINDING_SAML2_HTTP_POST) |
140
|
|
|
); |
141
|
|
|
EndpointChecker::check( |
142
|
|
|
$this, |
143
|
|
|
SamlConstants::BINDING_SAML2_HTTP_ARTIFACT, |
144
|
|
|
'https://sp.testshib.org/Shibboleth.sso/SLO/Artifact', |
145
|
|
|
$sp->getFirstSingleLogoutService(SamlConstants::BINDING_SAML2_HTTP_ARTIFACT) |
146
|
|
|
); |
147
|
|
|
|
148
|
|
|
NameIdFormatChecker::check($this, $sp, array( |
149
|
|
|
SamlConstants::NAME_ID_FORMAT_TRANSIENT, |
150
|
|
|
SamlConstants::NAME_ID_FORMAT_SHIB_NAME_ID, |
151
|
|
|
)); |
152
|
|
|
|
153
|
|
|
$this->assertCount(8, $sp->getAllAssertionConsumerServices()); |
154
|
|
|
IndexedEndpointChecker::check( |
155
|
|
|
$this, |
156
|
|
|
SamlConstants::BINDING_SAML2_HTTP_POST, |
157
|
|
|
'https://sp.testshib.org/Shibboleth.sso/SAML2/POST', |
158
|
|
|
1, |
159
|
|
|
true, |
160
|
|
|
$sp->getFirstAssertionConsumerService(SamlConstants::BINDING_SAML2_HTTP_POST) |
161
|
|
|
); |
162
|
|
|
IndexedEndpointChecker::check( |
163
|
|
|
$this, |
164
|
|
|
SamlConstants::BINDING_SAML2_HTTP_POST_SIMPLE_SIGN, |
165
|
|
|
'https://sp.testshib.org/Shibboleth.sso/SAML2/POST-SimpleSign', |
166
|
|
|
2, |
167
|
|
|
false, |
168
|
|
|
$sp->getFirstAssertionConsumerService(SamlConstants::BINDING_SAML2_HTTP_POST_SIMPLE_SIGN) |
169
|
|
|
); |
170
|
|
|
IndexedEndpointChecker::check( |
171
|
|
|
$this, |
172
|
|
|
SamlConstants::BINDING_SAML2_HTTP_ARTIFACT, |
173
|
|
|
'https://sp.testshib.org/Shibboleth.sso/SAML2/Artifact', |
174
|
|
|
3, |
175
|
|
|
false, |
176
|
|
|
$sp->getFirstAssertionConsumerService(SamlConstants::BINDING_SAML2_HTTP_ARTIFACT) |
177
|
|
|
); |
178
|
|
|
IndexedEndpointChecker::check( |
179
|
|
|
$this, |
180
|
|
|
SamlConstants::BINDING_SAML1_BROWSER_POST, |
181
|
|
|
'https://sp.testshib.org/Shibboleth.sso/SAML/POST', |
182
|
|
|
4, |
183
|
|
|
false, |
184
|
|
|
$sp->getFirstAssertionConsumerService(SamlConstants::BINDING_SAML1_BROWSER_POST) |
185
|
|
|
); |
186
|
|
|
IndexedEndpointChecker::check( |
187
|
|
|
$this, |
188
|
|
|
SamlConstants::BINDING_SAML1_ARTIFACT1, |
189
|
|
|
'https://sp.testshib.org/Shibboleth.sso/SAML/Artifact', |
190
|
|
|
5, |
191
|
|
|
false, |
192
|
|
|
$sp->getFirstAssertionConsumerService(SamlConstants::BINDING_SAML1_ARTIFACT1) |
193
|
|
|
); |
194
|
|
|
IndexedEndpointChecker::check( |
195
|
|
|
$this, |
196
|
|
|
SamlConstants::BINDING_WS_FED_WEB_SVC, |
197
|
|
|
'https://sp.testshib.org/Shibboleth.sso/ADFS', |
198
|
|
|
6, |
199
|
|
|
false, |
200
|
|
|
$sp->getFirstAssertionConsumerService(SamlConstants::BINDING_WS_FED_WEB_SVC) |
201
|
|
|
); |
202
|
|
|
|
203
|
|
|
$this->assertCount(1, $ed->getAllOrganizations()); |
204
|
|
|
OrganizationChecker::check($this, 'TestShib Two Service Provider', 'TestShib Two', 'http://www.testshib.org/testshib-two/', $ed->getFirstOrganization()); |
205
|
|
|
|
206
|
|
|
$this->assertCount(1, $ed->getAllContactPersons()); |
207
|
|
|
ContactPersonChecker::check($this, ContactPerson::TYPE_TECHNICAL, null, 'Nate', 'Klingenstein', '[email protected]', null, $ed->getFirstContactPerson()); |
208
|
|
|
|
209
|
|
|
unset($sp); |
210
|
|
|
//endregion |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
public function test_deserialize_ukfederation_metadata() |
214
|
|
|
{ |
215
|
|
|
$context = new DeserializationContext(); |
216
|
|
|
$context->getDocument()->load(__DIR__.'/../../../../../../resources/sample/EntitiesDescriptor/ukfederation-metadata.xml'); |
217
|
|
|
|
218
|
|
|
$entitiesDescriptor = new EntitiesDescriptor(); |
219
|
|
|
$entitiesDescriptor->deserialize($context->getDocument(), $context); |
220
|
|
|
$this->assertCount(2935, $entitiesDescriptor->getAllEntityDescriptors()); |
|
|
|
|
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
public function test_throws_on_entity_descriptor() |
224
|
|
|
{ |
225
|
|
|
$this->expectExceptionMessage("Expected 'EntitiesDescriptor' xml node and 'urn:oasis:names:tc:SAML:2.0:metadata' namespace but got node 'EntityDescriptor' and namespace 'urn:oasis:names:tc:SAML:2.0:metadata'"); |
226
|
|
|
$this->expectException(\LightSaml\Error\LightSamlXmlException::class); |
227
|
|
|
EntitiesDescriptor::load(__DIR__.'/../../../../../../resources/sample/EntityDescriptor/idp-ed.xml'); |
228
|
|
|
} |
229
|
|
|
} |
230
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: