Skip to content

Commit 428c0dd

Browse files
committed
Remove Jasig fix; shouldn't be necessary anymore
1 parent 40ad585 commit 428c0dd

File tree

5 files changed

+31
-38
lines changed

5 files changed

+31
-38
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
"php": ">=7.4 || ^8.0",
2626

2727
"simplesamlphp/composer-module-installer": "~1.1",
28-
"simplesamlphp/simplesamlphp": "dev-master"
28+
"simplesamlphp/simplesamlphp": "dev-master",
29+
"simplesamlphp/xml-common": "^0.0.12"
2930
},
3031
"require-dev": {
3132
"simplesamlphp/simplesamlphp-test-framework": "~1.0.4"

lib/Cas/Protocol/Cas20.php

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
use DOMException;
3131
use SimpleSAML\Configuration;
3232
use SimpleSAML\Logger;
33+
use SimpleSAML\XML\DOMDocumentFactory;
3334

3435
class Cas20
3536
{
@@ -102,7 +103,8 @@ public function getProxyGrantingTicketIOU(): ?string
102103
*/
103104
public function getValidateSuccessResponse(string $username): string
104105
{
105-
$xmlDocument = new DOMDocument("1.0");
106+
$xmlDocument = DOMDocumentFactory::create();
107+
$xmlDocument->formatOutput = true;
106108

107109
$root = $xmlDocument->createElement("cas:serviceResponse");
108110
$root->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:cas', 'http://www.yale.edu/tp/cas');
@@ -154,7 +156,7 @@ public function getValidateSuccessResponse(string $username): string
154156
$root->appendChild($casSuccess);
155157
$xmlDocument->appendChild($root);
156158

157-
return $this->workAroundForBuggyJasigXmlParser($xmlDocument->saveXML());
159+
return $xmlDocument->saveXML();
158160
}
159161

160162

@@ -165,7 +167,7 @@ public function getValidateSuccessResponse(string $username): string
165167
*/
166168
public function getValidateFailureResponse(string $errorCode, string $explanation): string
167169
{
168-
$xmlDocument = new DOMDocument("1.0");
170+
$xmlDocument = DOMDocumentFactory::create();
169171

170172
$root = $xmlDocument->createElement("cas:serviceResponse");
171173
$root->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:cas', 'http://www.yale.edu/tp/cas');
@@ -182,7 +184,7 @@ public function getValidateFailureResponse(string $errorCode, string $explanatio
182184

183185
$xmlDocument->appendChild($root);
184186

185-
return $this->workAroundForBuggyJasigXmlParser($xmlDocument->saveXML());
187+
return $xmlDocument->saveXML();
186188
}
187189

188190

@@ -192,7 +194,7 @@ public function getValidateFailureResponse(string $errorCode, string $explanatio
192194
*/
193195
public function getProxySuccessResponse(string $proxyTicketId): string
194196
{
195-
$xmlDocument = new DOMDocument("1.0");
197+
$xmlDocument = DOMDocumentFactory::create();
196198

197199
$root = $xmlDocument->createElement("cas:serviceResponse");
198200
$root->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:cas', 'http://www.yale.edu/tp/cas');
@@ -207,7 +209,7 @@ public function getProxySuccessResponse(string $proxyTicketId): string
207209
$root->appendChild($casProxySuccess);
208210
$xmlDocument->appendChild($root);
209211

210-
return $this->workAroundForBuggyJasigXmlParser($xmlDocument->saveXML());
212+
return $xmlDocument->saveXML();
211213
}
212214

213215

@@ -218,7 +220,7 @@ public function getProxySuccessResponse(string $proxyTicketId): string
218220
*/
219221
public function getProxyFailureResponse(string $errorCode, string $explanation): string
220222
{
221-
$xmlDocument = new DOMDocument("1.0");
223+
$xmlDocument = DOMDocumentFactory::create();
222224

223225
$root = $xmlDocument->createElement("cas:serviceResponse");
224226
$root->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:cas', 'http://www.yale.edu/tp/cas');
@@ -235,18 +237,7 @@ public function getProxyFailureResponse(string $errorCode, string $explanation):
235237

236238
$xmlDocument->appendChild($root);
237239

238-
return $this->workAroundForBuggyJasigXmlParser($xmlDocument->saveXML());
239-
}
240-
241-
242-
/**
243-
* @param string $xmlString
244-
* @return string
245-
*/
246-
private function workAroundForBuggyJasigXmlParser(string $xmlString): string
247-
{
248-
// when will people stop hand coding xml handling....?
249-
return str_replace('><', '>' . PHP_EOL . '<', str_replace(PHP_EOL, '', $xmlString));
240+
return $xmlDocument->saveXML();
250241
}
251242

252243

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
<cas:serviceResponse xmlns:cas="http://www.yale.edu/tp/cas">
2-
<cas:authenticationSuccess>
3-
<cas:user>myUser</cas:user>
4-
<cas:attributes>
5-
<cas:lastName>lasty</cas:lastName>
6-
<cas:valuesAreEscaped>&gt;abc&lt;blah&gt;</cas:valuesAreEscaped>
7-
<cas:urn_oid_0.9.2342.19200300.100.1.1>someValue</cas:urn_oid_0.9.2342.19200300.100.1.1>
8-
<cas:urn_oid_1.3.6.1.4.1.34199.1.7.1.5.2>CN=Some-Service,OU=Non-Privileged,OU=Groups,DC=exmple,DC=com</cas:urn_oid_1.3.6.1.4.1.34199.1.7.1.5.2>
9-
<cas:urn_oid_1.3.6.1.4.1.34199.1.7.1.5.2>CN=Other Servics,OU=Non-Privileged,OU=Groups,DC=example,DC=com</cas:urn_oid_1.3.6.1.4.1.34199.1.7.1.5.2>
10-
</cas:attributes>
11-
</cas:authenticationSuccess>
2+
<cas:authenticationSuccess>
3+
<cas:user>myUser</cas:user>
4+
<cas:attributes>
5+
<cas:lastName>lasty</cas:lastName>
6+
<cas:valuesAreEscaped>&gt;abc&lt;blah&gt;</cas:valuesAreEscaped>
7+
<cas:urn_oid_0.9.2342.19200300.100.1.1>someValue</cas:urn_oid_0.9.2342.19200300.100.1.1>
8+
<cas:urn_oid_1.3.6.1.4.1.34199.1.7.1.5.2>CN=Some-Service,OU=Non-Privileged,OU=Groups,DC=exmple,DC=com</cas:urn_oid_1.3.6.1.4.1.34199.1.7.1.5.2>
9+
<cas:urn_oid_1.3.6.1.4.1.34199.1.7.1.5.2>CN=Other Servics,OU=Non-Privileged,OU=Groups,DC=example,DC=com</cas:urn_oid_1.3.6.1.4.1.34199.1.7.1.5.2>
10+
</cas:attributes>
11+
</cas:authenticationSuccess>
1212
</cas:serviceResponse>
13+
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<cas:serviceResponse xmlns:cas="http://www.yale.edu/tp/cas">
2-
<cas:authenticationSuccess>
3-
<cas:user>[email protected]</cas:user>
4-
<cas:attributes>
5-
<cas:eduPersonPrincipalName>[email protected]</cas:eduPersonPrincipalName>
6-
<cas:base64Attributes>false</cas:base64Attributes>
7-
</cas:attributes>
8-
</cas:authenticationSuccess>
2+
<cas:authenticationSuccess>
3+
<cas:user>[email protected]</cas:user>
4+
<cas:attributes>
5+
<cas:eduPersonPrincipalName>[email protected]</cas:eduPersonPrincipalName>
6+
<cas:base64Attributes>false</cas:base64Attributes>
7+
</cas:attributes>
8+
</cas:authenticationSuccess>
99
</cas:serviceResponse>

tests/www/LoginIntegrationTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ public function testValidServiceUrl(string $serviceParam, string $ticketParam)
207207
)->saveXML();
208208

209209
$this->assertEquals(200, $resp['code']);
210-
$this->assertEquals(rtrim($expectedResponse), $resp['body']);
210+
$this->assertEquals($expectedResponse, $resp['body']);
211211
}
212212

213213
public function validServiceUrlProvider(): array

0 commit comments

Comments
 (0)