AssertionTest.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_InfoCard
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. // Call Zend_InfoCard_AssertionTest::main() if this source file is executed directly.
  23. if (!defined("PHPUnit_MAIN_METHOD")) {
  24. define("PHPUnit_MAIN_METHOD", "Zend_InfoCard_AssertionTest::main");
  25. }
  26. require_once 'Zend/InfoCard.php';
  27. /**
  28. * @category Zend
  29. * @package Zend_InfoCard
  30. * @subpackage UnitTests
  31. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  32. * @license http://framework.zend.com/license/new-bsd New BSD License
  33. * @group Zend_InfoCard
  34. */
  35. class Zend_InfoCard_AssertionTest extends PHPUnit_Framework_TestCase
  36. {
  37. protected $_xmlDocument;
  38. /**
  39. * Runs the test methods of this class.
  40. *
  41. * @access public
  42. * @static
  43. */
  44. public static function main()
  45. {
  46. $suite = new PHPUnit_Framework_TestSuite("Zend_InfoCard_AssertionTest");
  47. $result = PHPUnit_TextUI_TestRunner::run($suite);
  48. }
  49. public function setUp()
  50. {
  51. if (version_compare(PHP_VERSION, '5.4', '>=')) {
  52. $this->markTestSkipped('SimpleXML implementation changed and CardSpace technology is discontinued');
  53. }
  54. $this->tokenDocument = dirname(__FILE__) . '/_files/signedToken.xml';
  55. $this->sslPubKey = dirname(__FILE__) . '/_files/ssl_pub.cert';
  56. $this->sslPrvKey = dirname(__FILE__) . '/_files/ssl_private.cert';
  57. $this->loadXmlDocument();
  58. }
  59. public function loadXmlDocument()
  60. {
  61. $this->_xmlDocument = file_get_contents($this->tokenDocument);
  62. }
  63. public function testAssertionProcess()
  64. {
  65. date_default_timezone_set("America/Los_Angeles");
  66. $assertions = Zend_InfoCard_Xml_Assertion::getInstance($this->_xmlDocument);
  67. $this->assertTrue($assertions instanceof Zend_InfoCard_Xml_Assertion_Saml);
  68. $this->assertSame(1, $assertions->getMajorVersion());
  69. $this->assertSame(1, $assertions->getMinorVersion());
  70. $this->assertSame("uuid:5cf2cd76-acf6-45ef-9059-a811801b80cc", $assertions->getAssertionID());
  71. $this->assertSame("http://schemas.xmlsoap.org/ws/2005/05/identity/issuer/self", $assertions->getIssuer());
  72. $this->assertSame(Zend_InfoCard_Xml_Assertion_Saml::CONFIRMATION_BEARER, $assertions->getConfirmationMethod());
  73. $this->assertSame(1190153823, $assertions->getIssuedTimestamp());
  74. }
  75. public function testAssertionErrors()
  76. {
  77. try {
  78. Zend_InfoCard_Xml_Assertion::getInstance(10);
  79. $this->fail("Exception Not Thrown as Expected");
  80. } catch(Exception $e) {
  81. /* yay */
  82. }
  83. $doc = file_get_contents(dirname(__FILE__) . '/_files/signedToken_bad_type.xml');
  84. try {
  85. $assertions = Zend_InfoCard_Xml_Assertion::getInstance($doc);
  86. $this->fail("Exception Not thrown as expected");
  87. } catch(Exception $e) {
  88. /* yay */
  89. }
  90. }
  91. }
  92. // Call Zend_InfoCard_AssertionTest::main() if this source file is executed directly.
  93. if (PHPUnit_MAIN_METHOD == "Zend_InfoCard_AssertionTest::main") {
  94. Zend_InfoCard_AssertionTest::main();
  95. }