Skip to content

Commit

Permalink
Default v1 and UTF-8
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdijen committed Mar 8, 2023
1 parent 96950c0 commit b7db8d5
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 27 deletions.
5 changes: 1 addition & 4 deletions src/SAML2/HTTPPost.php
Expand Up @@ -90,10 +90,7 @@ public function receive(ServerRequestInterface $request): AbstractMessage
}

$msgStr = base64_decode($msgStr);

$xml = new DOMDocument();
$xml->loadXML($msgStr);
$msgStr = $xml->saveXML();
$msgStr = DOMDocumentFactory::fromString($msgStr)->saveXML();

$document = DOMDocumentFactory::fromString($msgStr);
Utils::getContainer()->debugMessage($document->documentElement, 'in');
Expand Down
2 changes: 1 addition & 1 deletion src/SAML2/XML/md/ContactPerson.php
Expand Up @@ -266,7 +266,7 @@ public static function fromArray(array $data): static
$name = array_key_first($attribute);
$value = $attribute[$name];

$doc = new DOMDocument();
$doc = new DOMDocument('1.0', 'UTF-8');
$elt = $doc->createElement("placeholder");
$elt->setAttributeNS($ns, $name, $value);

Expand Down
21 changes: 12 additions & 9 deletions tests/SAML2/Response/SignatureValidationTest.php
Expand Up @@ -4,7 +4,6 @@

namespace SimpleSAML\Test\SAML2\Response;

use DOMDocument;
use Mockery;
use Mockery\MockInterface;
use Mockery\Adapter\Phpunit\MockeryTestCase;
Expand Down Expand Up @@ -185,8 +184,9 @@ public function testThatAnUnsignedResponseWithNoSignedAssertionsThrowsAnExceptio
*/
private function getSignedResponseWithUnsignedAssertion(): Response
{
$doc = new DOMDocument();
$doc->load(__DIR__ . '../../../resources/xml/response/signedresponse_with_unsignedassertion.xml');
$doc = DOMDocumentFactory::fromFile(
dirname(__DIR__, 2) . '/resources/xml/response/signedresponse_with_unsignedassertion.xml',
);

return Response::fromXML($doc->documentElement);
}
Expand All @@ -197,8 +197,9 @@ private function getSignedResponseWithUnsignedAssertion(): Response
*/
private function getUnsignedResponseWithSignedAssertion(): Response
{
$doc = new DOMDocument();
$doc->load(__DIR__ . '../../../resources/xml/response/unsignedresponse_with_signedassertion.xml');
$doc = DOMDocumentFactory::fromFile(
dirname(__DIR__, 2) . '/resources/xml/response/unsignedresponse_with_signedassertion.xml',
);

return Response::fromXML($doc->documentElement);
}
Expand All @@ -209,8 +210,9 @@ private function getUnsignedResponseWithSignedAssertion(): Response
*/
private function getSignedResponseWithSignedAssertion(): Response
{
$doc = new DOMDocument();
$doc->load(__DIR__ . '../../../resources/xml/response/signedresponse_with_signedassertion.xml');
$doc = DOMDocumentFactory::fromFile(
dirname(__DIR__, 2) . '/resources/xml/response/signedresponse_with_signedassertion.xml',
);

return Response::fromXML($doc->documentElement);
}
Expand All @@ -221,8 +223,9 @@ private function getSignedResponseWithSignedAssertion(): Response
*/
private function getUnsignedResponseWithUnsignedAssertion(): Response
{
$doc = new DOMDocument();
$doc->load(__DIR__ . '../../../resources/xml/samlp_Response.xml');
$doc = DOMDocumentFactory::fromFile(
dirname(__DIR__, 2) . '/resources/xml/samlp_Response.xml',
);

return Response::fromXML($doc->documentElement);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/SAML2/XML/ecp/ResponseTest.php
Expand Up @@ -62,7 +62,7 @@ public function testMarshalling(): void
*/
public function testToXMLResponseAppended(): void
{
$doc = new DOMDocument();
$doc = new DOMDocument('1.0', 'UTF-8');
$element = $doc->createElement('Foobar');

$response = new Response('https://example.com/ACS');
Expand Down
17 changes: 8 additions & 9 deletions tests/SAML2/XML/samlp/AbstractMessageTest.php
Expand Up @@ -4,7 +4,6 @@

namespace SimpleSAML\Test\SAML2\XML\samlp;

use DOMDocument;
use DOMElement;
use Exception;
use Mockery\Adapter\Phpunit\MockeryTestCase;
Expand All @@ -29,6 +28,8 @@
use SimpleSAML\XMLSecurity\XML\ds\Signature;
use SimpleSAML\XMLSecurity\XMLSecurityKey;

use function dirname;

/**
* @covers \SimpleSAML\SAML2\XML\samlp\AbstractMessage
* @covers \SimpleSAML\SAML2\XML\samlp\AbstractSamlpElement
Expand All @@ -41,8 +42,7 @@ final class AbstractMessageTest extends MockeryTestCase
*/
public function testCorrectSignatureMethodCanBeExtractedFromAuthnRequest(): void
{
$authnRequest = new DOMDocument();
$authnRequest->loadXML(<<<'AUTHNREQUEST'
$authnRequest = DOMDocumentFactory::fromString(<<<AUTHNREQUEST
<samlp:AuthnRequest
xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol"
xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion"
Expand Down Expand Up @@ -85,8 +85,7 @@ public function testCorrectSignatureMethodCanBeExtractedFromAuthnRequest(): void
*/
public function testIssuerParsedAsNameID(): void
{
$authnRequest = new DOMDocument();
$authnRequest->loadXML(<<<AUTHNREQUEST
$authnRequest = DOMDocumentFactory::fromString(<<<AUTHNREQUEST
<samlp:AuthnRequest
xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol"
xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion"
Expand Down Expand Up @@ -172,8 +171,9 @@ public function testConvertIssuerToXML(): void
*/
public function testCorrectSignatureMethodCanBeExtractedFromResponse(): void
{
$response = new DOMDocument();
$response->load(__DIR__ . '../../../../resources/xml/samlp_Response.xml');
$response = DOMDocumentFactory::fromFile(
dirname(__DIR__, 3) . '/resources/xml/samlp_Response.xml',
);

$signer = (new SignatureAlgorithmFactory())->getAlgorithm(
C::SIG_RSA_SHA256,
Expand All @@ -199,8 +199,7 @@ public function testCorrectSignatureMethodCanBeExtractedFromResponse(): void
*/
public function testGetExtensions(): void
{
$authnRequest = new DOMDocument();
$authnRequest->loadXML(<<<'AUTHNREQUEST'
$authnRequest = DOMDocumentFactory::fromString(<<<AUTHNREQUEST
<samlp:AuthnRequest
xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol"
xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion"
Expand Down
4 changes: 1 addition & 3 deletions tests/SAML2/XML/samlp/AbstractStatusResponseTest.php
Expand Up @@ -4,7 +4,6 @@

namespace SimpleSAML\Test\SAML2\XML\samlp;

use DOMDocument;
use PHPUnit\Framework\TestCase;
use SimpleSAML\SAML2\Constants as C;
use SimpleSAML\SAML2\Utils\XPath;
Expand Down Expand Up @@ -243,8 +242,7 @@ public function testResponseTo(): void

$responseElement = $response->toXML();

$expectedStructureDocument = new DOMDocument();
$expectedStructureDocument->loadXML(<<<STATUSXML
$expectedStructureDocument = DOMDocumentFactory::fromString(<<<STATUSXML
<samlp:Response xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol"
xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion"
ID="123"
Expand Down

0 comments on commit b7db8d5

Please sign in to comment.