2
0

AssertionTest.php 3.5 KB

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