SecurityTest.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. /**
  3. * Tests Kohana_Security
  4. *
  5. * @group kohana
  6. * @group kohana.core
  7. * @group kohana.core.security
  8. *
  9. * @package Kohana
  10. * @category Tests
  11. */
  12. class Kohana_SecurityTest extends Unittest_TestCase
  13. {
  14. /**
  15. * Provides test data for test_envode_php_tags()
  16. *
  17. * @return array Test data sets
  18. */
  19. public function provider_encode_php_tags()
  20. {
  21. return [
  22. ["&lt;?php echo 'helloo'; ?&gt;", "<?php echo 'helloo'; ?>"],
  23. ];
  24. }
  25. /**
  26. * Tests Security::encode_php_tags()
  27. *
  28. * @test
  29. * @dataProvider provider_encode_php_tags
  30. * @covers Security::encode_php_tags
  31. */
  32. public function test_encode_php_tags($expected, $input)
  33. {
  34. $this->assertSame($expected, Security::encode_php_tags($input));
  35. }
  36. /**
  37. * Provides test data for test_strip_image_tags()
  38. *
  39. * @return array Test data sets
  40. */
  41. public function provider_strip_image_tags()
  42. {
  43. return [
  44. ['foo', '<img src="foo" />'],
  45. ];
  46. }
  47. /**
  48. * Tests Security::strip_image_tags()
  49. *
  50. * @test
  51. * @dataProvider provider_strip_image_tags
  52. * @covers Security::strip_image_tags
  53. */
  54. public function test_strip_image_tags($expected, $input)
  55. {
  56. $this->assertSame($expected, Security::strip_image_tags($input));
  57. }
  58. /**
  59. * Provides test data for Security::token()
  60. *
  61. * @return array Test data sets
  62. */
  63. public function provider_csrf_token()
  64. {
  65. $array = [];
  66. for ($i = 0; $i <= 4; $i++)
  67. {
  68. Security::$token_name = 'token_'.$i;
  69. $array[] = [Security::token(TRUE), Security::check(Security::token(FALSE)), $i];
  70. }
  71. return $array;
  72. }
  73. /**
  74. * Tests Security::token()
  75. *
  76. * @test
  77. * @dataProvider provider_csrf_token
  78. * @covers Security::token
  79. */
  80. public function test_csrf_token($expected, $input, $iteration)
  81. {
  82. //@todo: the Security::token tests need to be reviewed to check how much of the logic they're actually covering
  83. Security::$token_name = 'token_'.$iteration;
  84. $this->assertSame(TRUE, $input);
  85. $this->assertSame($expected, Security::token(FALSE));
  86. Session::instance()->delete(Security::$token_name);
  87. }
  88. }