Skip to content

Commit c4dc1fb

Browse files
author
James Grant
committed
updated tests for custom signing algorithms
1 parent 1a10d65 commit c4dc1fb

File tree

2 files changed

+66
-4
lines changed

2 files changed

+66
-4
lines changed

tests/src/OneLogin/Saml2/MetadataTest.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,58 @@ public function testSignMetadata()
159159
}
160160
}
161161

162+
/**
163+
* Tests the signMetadata method of the OneLogin_Saml2_Metadata
164+
*
165+
* @covers OneLogin_Saml2_Metadata::signMetadata
166+
*/
167+
public function testSignMetadataDefaultAlgorithms()
168+
{
169+
$settingsDir = TEST_ROOT .'/settings/';
170+
include $settingsDir.'settings1.php';
171+
172+
$settings = new OneLogin_Saml2_Settings($settingsInfo);
173+
$spData = $settings->getSPData();
174+
$security = $settings->getSecurityData();
175+
176+
$metadata = OneLogin_Saml2_Metadata::builder($spData, $security['authnRequestsSigned'], $security['wantAssertionsSigned']);
177+
178+
$certPath = $settings->getCertPath();
179+
$key = file_get_contents($certPath.'sp.key');
180+
$cert = file_get_contents($certPath.'sp.crt');
181+
182+
$signedMetadata = OneLogin_Saml2_Metadata::signMetadata($metadata, $key, $cert);
183+
184+
$this->assertContains('<ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>', $signedMetadata);
185+
$this->assertContains('<ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>', $signedMetadata);
186+
}
187+
188+
/**
189+
* Tests the signMetadata method of the OneLogin_Saml2_Metadata
190+
*
191+
* @covers OneLogin_Saml2_Metadata::signMetadata
192+
*/
193+
public function testSignMetadataCustomAlgorithms()
194+
{
195+
$settingsDir = TEST_ROOT .'/settings/';
196+
include $settingsDir.'settings1.php';
197+
198+
$settings = new OneLogin_Saml2_Settings($settingsInfo);
199+
$spData = $settings->getSPData();
200+
$security = $settings->getSecurityData();
201+
202+
$metadata = OneLogin_Saml2_Metadata::builder($spData, $security['authnRequestsSigned'], $security['wantAssertionsSigned']);
203+
204+
$certPath = $settings->getCertPath();
205+
$key = file_get_contents($certPath.'sp.key');
206+
$cert = file_get_contents($certPath.'sp.crt');
207+
208+
$signedMetadata = OneLogin_Saml2_Metadata::signMetadata($metadata, $key, $cert, XMLSecurityKey::RSA_SHA256, XMLSecurityDSig::SHA512);
209+
210+
$this->assertContains('<ds:SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"/>', $signedMetadata);
211+
$this->assertContains('<ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha512"/>', $signedMetadata);
212+
}
213+
162214
/**
163215
* Tests the addX509KeyDescriptors method of the OneLogin_Saml2_Metadata
164216
*

tests/src/OneLogin/Saml2/UtilsTest.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,39 +1056,49 @@ public function testAddSign()
10561056
$xmlAuthn = base64_decode(file_get_contents(TEST_ROOT . '/data/requests/authn_request.xml.base64'));
10571057
$xmlAuthnSigned = OneLogin_Saml2_Utils::addSign($xmlAuthn, $key, $cert);
10581058
$this->assertContains('<ds:SignatureValue>', $xmlAuthnSigned);
1059+
$this->assertContains('<ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>', $xmlAuthnSigned);
1060+
$this->assertContains('<ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>', $xmlAuthnSigned);
10591061
$res = new DOMDocument();
10601062
$res->loadXML($xmlAuthnSigned);
10611063
$dsSignature = $res->firstChild->firstChild->nextSibling->nextSibling;
10621064
$this->assertContains('ds:Signature', $dsSignature->tagName);
10631065

10641066
$dom = new DOMDocument();
10651067
$dom->loadXML($xmlAuthn);
1066-
$xmlAuthnSigned2 = OneLogin_Saml2_Utils::addSign($dom, $key, $cert);
1068+
$xmlAuthnSigned2 = OneLogin_Saml2_Utils::addSign($dom, $key, $cert, XMLSecurityKey::RSA_SHA256, XMLSecurityDSig::SHA512);
10671069
$this->assertContains('<ds:SignatureValue>', $xmlAuthnSigned2);
1070+
$this->assertContains('<ds:SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"/>', $xmlAuthnSigned2);
1071+
$this->assertContains('<ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha512"/>', $xmlAuthnSigned2);
10681072
$res2 = new DOMDocument();
10691073
$res2->loadXML($xmlAuthnSigned2);
10701074
$dsSignature2 = $res2->firstChild->firstChild->nextSibling->nextSibling;
10711075
$this->assertContains('ds:Signature', $dsSignature2->tagName);
10721076

10731077
$xmlLogoutReq = base64_decode(file_get_contents(TEST_ROOT . '/data/logout_requests/logout_request.xml.base64'));
1074-
$xmlLogoutReqSigned = OneLogin_Saml2_Utils::addSign($xmlLogoutReq, $key, $cert);
1078+
$xmlLogoutReqSigned = OneLogin_Saml2_Utils::addSign($xmlLogoutReq, $key, $cert, XMLSecurityKey::RSA_SHA256, XMLSecurityDSig::SHA512);
10751079
$this->assertContains('<ds:SignatureValue>', $xmlLogoutReqSigned);
1080+
$this->assertContains('<ds:SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"/>', $xmlLogoutReqSigned);
1081+
$this->assertContains('<ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha512"/>', $xmlLogoutReqSigned);
10761082
$res3 = new DOMDocument();
10771083
$res3->loadXML($xmlLogoutReqSigned);
10781084
$dsSignature3 = $res3->firstChild->firstChild->nextSibling->nextSibling;
10791085
$this->assertContains('ds:Signature', $dsSignature3->tagName);
10801086

10811087
$xmlLogoutRes = base64_decode(file_get_contents(TEST_ROOT . '/data/logout_responses/logout_response.xml.base64'));
1082-
$xmlLogoutResSigned = OneLogin_Saml2_Utils::addSign($xmlLogoutRes, $key, $cert);
1088+
$xmlLogoutResSigned = OneLogin_Saml2_Utils::addSign($xmlLogoutRes, $key, $cert, XMLSecurityKey::RSA_SHA256, XMLSecurityDSig::SHA512);
10831089
$this->assertContains('<ds:SignatureValue>', $xmlLogoutResSigned);
1090+
$this->assertContains('<ds:SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"/>', $xmlLogoutResSigned);
1091+
$this->assertContains('<ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha512"/>', $xmlLogoutResSigned);
10841092
$res4 = new DOMDocument();
10851093
$res4->loadXML($xmlLogoutResSigned);
10861094
$dsSignature4 = $res4->firstChild->firstChild->nextSibling->nextSibling;
10871095
$this->assertContains('ds:Signature', $dsSignature4->tagName);
10881096

10891097
$xmlMetadata = file_get_contents(TEST_ROOT . '/data/metadata/metadata_settings1.xml');
1090-
$xmlMetadataSigned = OneLogin_Saml2_Utils::addSign($xmlMetadata, $key, $cert);
1098+
$xmlMetadataSigned = OneLogin_Saml2_Utils::addSign($xmlMetadata, $key, $cert, XMLSecurityKey::RSA_SHA256, XMLSecurityDSig::SHA512);
10911099
$this->assertContains('<ds:SignatureValue>', $xmlMetadataSigned);
1100+
$this->assertContains('<ds:SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"/>', $xmlMetadataSigned);
1101+
$this->assertContains('<ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha512"/>', $xmlMetadataSigned);
10921102
$res5 = new DOMDocument();
10931103
$res5->loadXML($xmlMetadataSigned);
10941104
$dsSignature5 = $res5->firstChild->firstChild;

0 commit comments

Comments
 (0)