249 lines
13 KiB
PHP
249 lines
13 KiB
PHP
|
<?php
|
||
|
/**
|
||
|
* Zend Framework
|
||
|
*
|
||
|
* LICENSE
|
||
|
*
|
||
|
* This source file is subject to the new BSD license that is bundled
|
||
|
* with this package in the file LICENSE.txt.
|
||
|
* It is also available through the world-wide-web at this URL:
|
||
|
* http://framework.zend.com/license/new-bsd
|
||
|
* If you did not receive a copy of the license and are unable to
|
||
|
* obtain it through the world-wide-web, please send an email
|
||
|
* to license@zend.com so we can send you a copy immediately.
|
||
|
*
|
||
|
* @category Zend
|
||
|
* @package Zend_InfoCard
|
||
|
* @subpackage UnitTests
|
||
|
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||
|
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||
|
* @version $Id: XmlParsingTest.php 17363 2009-08-03 07:40:18Z bkarwin $
|
||
|
*/
|
||
|
|
||
|
// Call Zend_InfoCard_XmlParsingTest::main() if this source file is executed directly.
|
||
|
if (!defined("PHPUnit_MAIN_METHOD")) {
|
||
|
define("PHPUnit_MAIN_METHOD", "Zend_InfoCard_XmlParsingTest::main");
|
||
|
}
|
||
|
|
||
|
require_once dirname(dirname(dirname(__FILE__))) . '/TestHelper.php';
|
||
|
require_once "PHPUnit/Framework/TestCase.php";
|
||
|
require_once "PHPUnit/Framework/TestSuite.php";
|
||
|
|
||
|
require_once 'Zend/InfoCard/Xml/EncryptedData.php';
|
||
|
require_once 'Zend/InfoCard/Xml/SecurityTokenReference.php';
|
||
|
|
||
|
/**
|
||
|
* @category Zend
|
||
|
* @package Zend_InfoCard
|
||
|
* @subpackage UnitTests
|
||
|
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||
|
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||
|
* @group Zend_InfoCard
|
||
|
*/
|
||
|
class Zend_InfoCard_XmlParsingTest extends PHPUnit_Framework_TestCase
|
||
|
{
|
||
|
protected $_xmlDocument;
|
||
|
|
||
|
/**
|
||
|
* Runs the test methods of this class.
|
||
|
*
|
||
|
* @access public
|
||
|
* @static
|
||
|
*/
|
||
|
public static function main()
|
||
|
{
|
||
|
require_once "PHPUnit/TextUI/TestRunner.php";
|
||
|
|
||
|
$suite = new PHPUnit_Framework_TestSuite("Zend_InfoCard_XmlParsingTest");
|
||
|
$result = PHPUnit_TextUI_TestRunner::run($suite);
|
||
|
}
|
||
|
|
||
|
public function setUp()
|
||
|
{
|
||
|
$this->tokenDocument = dirname(__FILE__) . '/_files/encryptedtoken.xml';
|
||
|
$this->loadXmlDocument();
|
||
|
}
|
||
|
|
||
|
public function loadXmlDocument()
|
||
|
{
|
||
|
$this->_xmlDocument = file_get_contents($this->tokenDocument);
|
||
|
}
|
||
|
|
||
|
public function testEncryptedDataType()
|
||
|
{
|
||
|
$doc = file_get_contents(dirname(__FILE__) . '/_files/encryptedtoken_bad_type.xml');
|
||
|
|
||
|
try {
|
||
|
$encryptedData = Zend_InfoCard_Xml_EncryptedData::getInstance($doc);
|
||
|
$this->fail("Exception not thrown as expected");
|
||
|
} catch(Exception $e) {
|
||
|
/* yay */
|
||
|
}
|
||
|
|
||
|
try {
|
||
|
$encryptedData = Zend_InfoCard_Xml_EncryptedData::getInstance(10);
|
||
|
$this->fail("Exception not thrown as expected");
|
||
|
} catch(Exception $e) {
|
||
|
/* yay */
|
||
|
}
|
||
|
|
||
|
}
|
||
|
public function testEncryptedData()
|
||
|
{
|
||
|
$encryptedData = Zend_InfoCard_Xml_EncryptedData::getInstance($this->_xmlDocument);
|
||
|
|
||
|
$this->assertTrue($encryptedData instanceof Zend_InfoCard_Xml_EncryptedData_XmlEnc);
|
||
|
$this->assertSame($encryptedData->getCipherValue(), '+5yXODn6COtlq4VWFl84Ue/nyf92UCqHc9LmFzDVJr+HDoLwOl1FV9VcIYs/KhmVHiHiv3nGHMvc8RBCJbQbpC8WaQRm9lGyO+4Hmj2w9D+c+O3gOr5sfxKIOK99Wmhj+0Z+7aqm+J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XAZCaTb9Ds/XZl/bel7uBMTPyDrppvL90fAq48rW7sPCNaw6CBbSu7R9tmx3d81UI7X39H5afWphydUfPIJMgPIiPT91RHPq0+30uL7jQzTr6i9MK5fymgrk+nKiZanKA/Lck9TdfpMlgOZ/AuFS7CzzvA6XL3n1GCCk8/TD1HRIaCZxnT53bpKcKGa8VT64RO1yt4hYOyar0sj/KSbx62//FxeZJ7eILudcbLmKGu+cF0E7uLk9+GMThnTwpDFIvsGqZF8298MHGs958bEEMqcG/0RNwjJriMo4UpcKnGF1eb5kgKoU2pvYENDHyBdfxIUiJ+N58P0ut1e94nn263A4h9fHH4k71NbcnJcch+mkwFzgWDhU1Tpi0dKJJ9rQilNXdC3+Fhkvs0ZRV0+cKzcn8NFPVlSuLOpIJDP+E61tmAixSPRGn+aRvW9H1rmmmqUfLD1m671Q2LLnIPM4GucS2UbT+ocb/r0yZpnPHHs2uZEHEf+qbDX3J/q7uzY8HRe289i/aXTAcKF8FkWOKCp4N3gIR8PsQ9D6Q4i/PWNKHyTLszGYRcK+fZWpWjjdXOyrzr2axoEmsS8b0DdoelHa9rsyowynKYe1t7iccmnfSaZDgRT3t8UCPXmx4aGSCa5yej
|
||
|
|
||
|
$this->assertSame($encryptedData->getEncryptionMethod(), 'http://www.w3.org/2001/04/xmlenc#aes256-cbc');
|
||
|
$this->assertTrue($encryptedData->getKeyInfo() instanceof Zend_InfoCard_Xml_KeyInfo_XmlDSig);
|
||
|
}
|
||
|
|
||
|
public function testTostring()
|
||
|
{
|
||
|
$encryptedData = Zend_InfoCard_Xml_EncryptedData::getInstance($this->_xmlDocument);
|
||
|
$key = $encryptedData->getKeyInfo();
|
||
|
|
||
|
$this->assertTrue(is_string($key->__toString()));
|
||
|
}
|
||
|
|
||
|
public function testConversion()
|
||
|
{
|
||
|
$encryptedData = Zend_InfoCard_Xml_EncryptedData::getInstance($this->_xmlDocument);
|
||
|
|
||
|
$keyInfo = $encryptedData->getKeyInfo();
|
||
|
|
||
|
$this->assertTrue($keyInfo instanceof SimpleXMLElement);
|
||
|
|
||
|
$dom = Zend_InfoCard_Xml_KeyInfo_XmlDSig::convertToDOM($keyInfo);
|
||
|
$this->assertTrue($dom instanceof DOMNode);
|
||
|
$sxe = Zend_InfoCard_Xml_KeyInfo_XmlDSig::convertToObject($dom, 'Zend_InfoCard_Xml_KeyInfo_XmlDSig');
|
||
|
|
||
|
$this->assertTrue($sxe instanceof Zend_InfoCard_Xml_KeyInfo_XmlDSig);
|
||
|
}
|
||
|
|
||
|
public function testEncryptedDataKeyInfo()
|
||
|
{
|
||
|
$keyinfo = Zend_InfoCard_Xml_EncryptedData::getInstance($this->_xmlDocument)->getKeyInfo();
|
||
|
|
||
|
$this->assertTrue($keyinfo instanceof Zend_InfoCard_Xml_KeyInfo_XmlDSig);
|
||
|
$this->assertTrue($keyinfo->getEncryptedKey() instanceof Zend_InfoCard_Xml_EncryptedKey);
|
||
|
}
|
||
|
|
||
|
public function testEncryptedKey()
|
||
|
{
|
||
|
$enckey = Zend_InfoCard_Xml_EncryptedData::getInstance($this->_xmlDocument)->getKeyInfo()->getEncryptedKey();
|
||
|
|
||
|
$this->assertTrue($enckey instanceof Zend_InfoCard_Xml_EncryptedKey);
|
||
|
|
||
|
$this->assertSame($enckey->getEncryptionMethod(), 'http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p');
|
||
|
$this->assertSame($enckey->getDigestMethod(), 'http://www.w3.org/2000/09/xmldsig#sha1');
|
||
|
$this->assertSame($enckey->getCipherValue(), 'AIgtBEv9lGMikyHjV/b5mQ5LbLyupNtRH8hl5I6tJsZI5CYP32BLo9FgxAY5ZReEv+XZbqcs5KORBvTbMkP6l7MY32WJGPBDDMSB7k6DshryoZqlmGMbjt2g1nM7xOuwwfru1jC7t+qCBXL4PPBpHDhHzAW7u8tB8LQCU6GklIFa1+GoZbQ00BY/OoPbE3rxhxgGPAHXfYPLjGALIkYo9czeTO/zfcydHl5Xcyp/PsskSOUhNFcftxG+fQELb/oqc50ldBWlxBM/qU7fLI4KRfUag3J5sanCUsgiYdF0iQNfiYnUKLa9ThDHjHUQnB5EEt77cM2/DKQkyExMBBgYcRo9GzqyLXiDCYWVatCQU6rAD8NkBBpFs8W/0QXIV1J/S3DuZS3Eo4x27gRlT5YfUeO7jAZvwqy51WHNXwq13QTV2AOGfvpK3054sZm+10jdfAq6tgYdShQgO2kHRGP1q9vAC3SfD49mP9q+AemJrAkiR2HZTxkEQ+AttdfPhc2dzdLXp+ukQdqpL/xlywIp+KIim+YVjhO+Bi92rRn5Kl0h7q6MkpoTGI1F+akmNhD6VmB1Nd0G6e4AGTisuyd+vygEH7fsZhZuiMSknajfgPgazKiLUihwRvfk4FJm18Ju97tXcl6LhIJpkOcq7sI25GhWz0mHX1ErOf/949pcozo=');
|
||
|
|
||
|
$this->assertTrue($enckey->getKeyInfo() instanceof Zend_InfoCard_Xml_KeyInfo_Default);
|
||
|
}
|
||
|
|
||
|
public function testEncryptedKeyKeyInfo()
|
||
|
{
|
||
|
$keyinfo = Zend_InfoCard_Xml_EncryptedData::getInstance($this->_xmlDocument)->getKeyInfo()->getEncryptedKey()->getKeyInfo();
|
||
|
|
||
|
$this->assertTrue($keyinfo instanceof Zend_InfoCard_Xml_KeyInfo_Default);
|
||
|
$this->assertTrue($keyinfo->getSecurityTokenReference() instanceof Zend_InfoCard_Xml_SecurityTokenReference);
|
||
|
}
|
||
|
|
||
|
public function testSecurityTokenReference()
|
||
|
{
|
||
|
$sectoken = Zend_InfoCard_Xml_EncryptedData::getInstance($this->_xmlDocument)->getKeyInfo()
|
||
|
->getEncryptedKey()
|
||
|
->getKeyInfo()
|
||
|
->getSecurityTokenReference();
|
||
|
$this->assertTrue($sectoken instanceof Zend_InfoCard_Xml_SecurityTokenReference);
|
||
|
|
||
|
$this->assertSame($sectoken->getKeyThumbprintType(), 'http://docs.oasis-open.org/wss/oasis-wss-soap-message-security-1.1#ThumbprintSHA1');
|
||
|
$this->assertSame($sectoken->getKeyThumbprintEncodingType(), 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary');
|
||
|
$this->assertSame($sectoken->getKeyReference(false), '/OCqQ7Np25sOiA+4OsFh1R6qIeY=');
|
||
|
}
|
||
|
|
||
|
public function testEncryptedKeyErrors()
|
||
|
{
|
||
|
try {
|
||
|
Zend_InfoCard_Xml_EncryptedKey::getInstance(10);
|
||
|
$this->fail("Expected Exception Not thrown");
|
||
|
} catch(Exception $e) {
|
||
|
/* yay */
|
||
|
}
|
||
|
|
||
|
$doc = file_get_contents(dirname(__FILE__) . "/_files/encryptedkey_bad_block.xml");
|
||
|
|
||
|
try {
|
||
|
Zend_InfoCard_Xml_EncryptedKey::getInstance($doc);
|
||
|
$this->fail("Expected Exception not thrown");
|
||
|
} catch(Exception $e) {
|
||
|
/* yay */
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
$doc = file_get_contents(dirname(__FILE__) . "/_files/encryptedkey_missing_enc_algo.xml");
|
||
|
$ek = Zend_InfoCard_Xml_EncryptedKey::getInstance($doc);
|
||
|
|
||
|
try {
|
||
|
$ek->getEncryptionMethod();
|
||
|
$this->fail("Expected Exception not thrown");
|
||
|
} catch(Exception $e) {
|
||
|
/* yay */
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
public function testKeyInfo()
|
||
|
{
|
||
|
try {
|
||
|
Zend_InfoCard_Xml_KeyInfo::getInstance("<foo/>");
|
||
|
$this->fail("Expected Exception Not thrown");
|
||
|
} catch(Exception $e) {
|
||
|
/* yay */
|
||
|
}
|
||
|
|
||
|
try {
|
||
|
Zend_InfoCard_Xml_KeyInfo::getInstance(10);
|
||
|
$this->fail("Expected Exception Not thrown");
|
||
|
} catch(Exception $e) {
|
||
|
/* yay */
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public function testSecurityTokenReferenceErrors()
|
||
|
{
|
||
|
try {
|
||
|
Zend_InfoCard_Xml_SecurityTokenReference::getInstance("<foo/>");
|
||
|
$this->fail("Expected Exception Not thrown");
|
||
|
} catch(Exception $e) {
|
||
|
/* yay */
|
||
|
}
|
||
|
|
||
|
try {
|
||
|
Zend_InfoCard_Xml_SecurityTokenReference::getInstance(10);
|
||
|
$this->fail("Expected Exception Not thrown");
|
||
|
} catch(Exception $e) {
|
||
|
/* yay */
|
||
|
}
|
||
|
|
||
|
$doc = file_get_contents(dirname(__FILE__) . "/_files/security_token_bad_keyref.xml");
|
||
|
|
||
|
try {
|
||
|
$si = Zend_InfoCard_Xml_SecurityTokenReference::getInstance($doc);
|
||
|
$si->getKeyReference();
|
||
|
$this->fail("Expected Exception Not thrown");
|
||
|
} catch(Exception $e) {
|
||
|
/* yay */
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
// Call Zend_InfoCard_XmlParsingTest::main() if this source file is executed directly.
|
||
|
if (PHPUnit_MAIN_METHOD == "Zend_InfoCard_XmlParsingTest::main") {
|
||
|
Zend_InfoCard_XmlParsingTest::main();
|
||
|
}
|