Skip to content

Commit

Permalink
Remove Jasig fix; shouldn't be necessary anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdijen committed Jan 24, 2021
1 parent 40ad585 commit 0143712
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 38 deletions.
3 changes: 2 additions & 1 deletion composer.json
Expand Up @@ -25,7 +25,8 @@
"php": ">=7.4 || ^8.0",

"simplesamlphp/composer-module-installer": "~1.1",
"simplesamlphp/simplesamlphp": "dev-master"
"simplesamlphp/simplesamlphp": "dev-master",
"simplesamlphp/xml-common": "^0.0.12"
},
"require-dev": {
"simplesamlphp/simplesamlphp-test-framework": "~1.0.4"
Expand Down
29 changes: 10 additions & 19 deletions lib/Cas/Protocol/Cas20.php
Expand Up @@ -30,6 +30,7 @@
use DOMException;
use SimpleSAML\Configuration;
use SimpleSAML\Logger;
use SimpleSAML\XML\DOMDocumentFactory;

class Cas20
{
Expand Down Expand Up @@ -102,7 +103,8 @@ public function getProxyGrantingTicketIOU(): ?string
*/
public function getValidateSuccessResponse(string $username): string
{
$xmlDocument = new DOMDocument("1.0");
$xmlDocument = DOMDocumentFactory::create();
$xmlDocument->formatOutput = true;

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

return $this->workAroundForBuggyJasigXmlParser($xmlDocument->saveXML());
return $xmlDocument->saveXML();
}


Expand All @@ -165,7 +167,7 @@ public function getValidateSuccessResponse(string $username): string
*/
public function getValidateFailureResponse(string $errorCode, string $explanation): string
{
$xmlDocument = new DOMDocument("1.0");
$xmlDocument = DOMDocumentFactory::create();

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

$xmlDocument->appendChild($root);

return $this->workAroundForBuggyJasigXmlParser($xmlDocument->saveXML());
return $xmlDocument->saveXML();
}


Expand All @@ -192,7 +194,7 @@ public function getValidateFailureResponse(string $errorCode, string $explanatio
*/
public function getProxySuccessResponse(string $proxyTicketId): string
{
$xmlDocument = new DOMDocument("1.0");
$xmlDocument = DOMDocumentFactory::create();

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

return $this->workAroundForBuggyJasigXmlParser($xmlDocument->saveXML());
return $xmlDocument->saveXML();
}


Expand All @@ -218,7 +220,7 @@ public function getProxySuccessResponse(string $proxyTicketId): string
*/
public function getProxyFailureResponse(string $errorCode, string $explanation): string
{
$xmlDocument = new DOMDocument("1.0");
$xmlDocument = DOMDocumentFactory::create();

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

$xmlDocument->appendChild($root);

return $this->workAroundForBuggyJasigXmlParser($xmlDocument->saveXML());
}


/**
* @param string $xmlString
* @return string
*/
private function workAroundForBuggyJasigXmlParser(string $xmlString): string
{
// when will people stop hand coding xml handling....?
return str_replace('><', '>' . PHP_EOL . '<', str_replace(PHP_EOL, '', $xmlString));
return $xmlDocument->saveXML();
}


Expand Down
20 changes: 10 additions & 10 deletions tests/resources/xml/testAttributeToXmlConversion.xml
@@ -1,12 +1,12 @@
<cas:serviceResponse xmlns:cas="http://www.yale.edu/tp/cas">
<cas:authenticationSuccess>
<cas:user>myUser</cas:user>
<cas:attributes>
<cas:lastName>lasty</cas:lastName>
<cas:valuesAreEscaped>&gt;abc&lt;blah&gt;</cas:valuesAreEscaped>
<cas:urn_oid_0.9.2342.19200300.100.1.1>someValue</cas:urn_oid_0.9.2342.19200300.100.1.1>
<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>
<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>
</cas:attributes>
</cas:authenticationSuccess>
<cas:authenticationSuccess>
<cas:user>myUser</cas:user>
<cas:attributes>
<cas:lastName>lasty</cas:lastName>
<cas:valuesAreEscaped>&gt;abc&lt;blah&gt;</cas:valuesAreEscaped>
<cas:urn_oid_0.9.2342.19200300.100.1.1>someValue</cas:urn_oid_0.9.2342.19200300.100.1.1>
<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>
<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>
</cas:attributes>
</cas:authenticationSuccess>
</cas:serviceResponse>
14 changes: 7 additions & 7 deletions tests/resources/xml/testValidServiceUrl.xml
@@ -1,9 +1,9 @@
<cas:serviceResponse xmlns:cas="http://www.yale.edu/tp/cas">
<cas:authenticationSuccess>
<cas:user>testuser@example.com</cas:user>
<cas:attributes>
<cas:eduPersonPrincipalName>testuser@example.com</cas:eduPersonPrincipalName>
<cas:base64Attributes>false</cas:base64Attributes>
</cas:attributes>
</cas:authenticationSuccess>
<cas:authenticationSuccess>
<cas:user>testuser@example.com</cas:user>
<cas:attributes>
<cas:eduPersonPrincipalName>testuser@example.com</cas:eduPersonPrincipalName>
<cas:base64Attributes>false</cas:base64Attributes>
</cas:attributes>
</cas:authenticationSuccess>
</cas:serviceResponse>
2 changes: 1 addition & 1 deletion tests/www/LoginIntegrationTest.php
Expand Up @@ -207,7 +207,7 @@ public function testValidServiceUrl(string $serviceParam, string $ticketParam)
)->saveXML();

$this->assertEquals(200, $resp['code']);
$this->assertEquals(rtrim($expectedResponse), $resp['body']);
$this->assertEquals($expectedResponse, $resp['body']);
}

public function validServiceUrlProvider(): array
Expand Down

0 comments on commit 0143712

Please sign in to comment.