AssertionTest.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. $this->tokenDocument = dirname(__FILE__) . '/_files/signedToken.xml';
  52. $this->sslPubKey = dirname(__FILE__) . '/_files/ssl_pub.cert';
  53. $this->sslPrvKey = dirname(__FILE__) . '/_files/ssl_private.cert';
  54. $this->loadXmlDocument();
  55. }
  56. public function loadXmlDocument()
  57. {
  58. $this->_xmlDocument = file_get_contents($this->tokenDocument);
  59. }
  60. public function testAssertionProcess()
  61. {
  62. date_default_timezone_set("America/Los_Angeles");
  63. $assertions = Zend_InfoCard_Xml_Assertion::getInstance($this->_xmlDocument);
  64. $this->assertTrue($assertions instanceof Zend_InfoCard_Xml_Assertion_Saml);
  65. $this->assertSame($assertions->getMajorVersion(), 1);
  66. $this->assertSame($assertions->getMinorversion(), 1);
  67. $this->assertSame($assertions->getAssertionID(), "uuid:5cf2cd76-acf6-45ef-9059-a811801b80cc");
  68. $this->assertSame($assertions->getIssuer(), "http://schemas.xmlsoap.org/ws/2005/05/identity/issuer/self");
  69. $this->assertSame($assertions->getConfirmationMethod(), Zend_InfoCard_Xml_Assertion_Saml::CONFIRMATION_BEARER);
  70. $this->assertSame($assertions->getIssuedTimestamp(), 1190153823);
  71. }
  72. public function testAssertionErrors()
  73. {
  74. try {
  75. Zend_InfoCard_Xml_Assertion::getInstance(10);
  76. $this->fail("Exception Not Thrown as Expected");
  77. } catch(Exception $e) {
  78. /* yay */
  79. }
  80. $doc = file_get_contents(dirname(__FILE__) . '/_files/signedToken_bad_type.xml');
  81. try {
  82. $assertions = Zend_InfoCard_Xml_Assertion::getInstance($doc);
  83. $this->fail("Exception Not thrown as expected");
  84. } catch(Exception $e) {
  85. /* yay */
  86. }
  87. }
  88. }
  89. // Call Zend_InfoCard_AssertionTest::main() if this source file is executed directly.
  90. if (PHPUnit_MAIN_METHOD == "Zend_InfoCard_AssertionTest::main") {
  91. Zend_InfoCard_AssertionTest::main();
  92. }