AssertionTest.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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-2010 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 dirname(dirname(dirname(__FILE__))) . '/TestHelper.php';
  27. require_once "PHPUnit/Framework/TestCase.php";
  28. require_once "PHPUnit/Framework/TestSuite.php";
  29. require_once 'Zend/InfoCard.php';
  30. /**
  31. * @category Zend
  32. * @package Zend_InfoCard
  33. * @subpackage UnitTests
  34. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  35. * @license http://framework.zend.com/license/new-bsd New BSD License
  36. * @group Zend_InfoCard
  37. */
  38. class Zend_InfoCard_AssertionTest extends PHPUnit_Framework_TestCase
  39. {
  40. protected $_xmlDocument;
  41. /**
  42. * Runs the test methods of this class.
  43. *
  44. * @access public
  45. * @static
  46. */
  47. public static function main()
  48. {
  49. require_once "PHPUnit/TextUI/TestRunner.php";
  50. $suite = new PHPUnit_Framework_TestSuite("Zend_InfoCard_AssertionTest");
  51. $result = PHPUnit_TextUI_TestRunner::run($suite);
  52. }
  53. public function setUp()
  54. {
  55. $this->tokenDocument = dirname(__FILE__) . '/_files/signedToken.xml';
  56. $this->sslPubKey = dirname(__FILE__) . '/_files/ssl_pub.cert';
  57. $this->sslPrvKey = dirname(__FILE__) . '/_files/ssl_private.cert';
  58. $this->loadXmlDocument();
  59. }
  60. public function loadXmlDocument()
  61. {
  62. $this->_xmlDocument = file_get_contents($this->tokenDocument);
  63. }
  64. public function testAssertionProcess()
  65. {
  66. date_default_timezone_set("America/Los_Angeles");
  67. $assertions = Zend_InfoCard_Xml_Assertion::getInstance($this->_xmlDocument);
  68. $this->assertTrue($assertions instanceof Zend_InfoCard_Xml_Assertion_Saml);
  69. $this->assertSame($assertions->getMajorVersion(), 1);
  70. $this->assertSame($assertions->getMinorversion(), 1);
  71. $this->assertSame($assertions->getAssertionID(), "uuid:5cf2cd76-acf6-45ef-9059-a811801b80cc");
  72. $this->assertSame($assertions->getIssuer(), "http://schemas.xmlsoap.org/ws/2005/05/identity/issuer/self");
  73. $this->assertSame($assertions->getConfirmationMethod(), Zend_InfoCard_Xml_Assertion_Saml::CONFIRMATION_BEARER);
  74. $this->assertSame($assertions->getIssuedTimestamp(), 1190153823);
  75. }
  76. public function testAssertionErrors()
  77. {
  78. try {
  79. Zend_InfoCard_Xml_Assertion::getInstance(10);
  80. $this->fail("Exception Not Thrown as Expected");
  81. } catch(Exception $e) {
  82. /* yay */
  83. }
  84. $doc = file_get_contents(dirname(__FILE__) . '/_files/signedToken_bad_type.xml');
  85. try {
  86. $assertions = Zend_InfoCard_Xml_Assertion::getInstance($doc);
  87. $this->fail("Exception Not thrown as expected");
  88. } catch(Exception $e) {
  89. /* yay */
  90. }
  91. }
  92. }
  93. // Call Zend_InfoCard_AssertionTest::main() if this source file is executed directly.
  94. if (PHPUnit_MAIN_METHOD == "Zend_InfoCard_AssertionTest::main") {
  95. Zend_InfoCard_AssertionTest::main();
  96. }