SecurityTest.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. * Tests KO7_Security
  4. *
  5. * @group ko7
  6. * @group ko7.core
  7. * @group ko7.core.security
  8. *
  9. * @package KO7
  10. * @category Tests
  11. */
  12. class KO7_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 Security::token()
  38. *
  39. * @return array Test data sets
  40. */
  41. public function provider_csrf_token()
  42. {
  43. $array = [];
  44. for ($i = 0; $i <= 4; $i++)
  45. {
  46. $id = uniqid('', FALSE);
  47. Security::$token_name = 'token_'.$id;
  48. $array[] = [Security::token(TRUE), Security::check(Security::token()), $id];
  49. }
  50. return $array;
  51. }
  52. /**
  53. * Tests Security::token()
  54. *
  55. * @dataProvider provider_csrf_token
  56. * @covers Security::token
  57. */
  58. public function test_csrf_token($expected, $input, $iteration)
  59. {
  60. //@todo: the Security::token tests need to be reviewed to check how much of the logic they're actually covering
  61. Security::$token_name = 'token_'.$iteration;
  62. self::assertTrue($input);
  63. self::assertSame($expected, Security::token());
  64. Session::instance()->delete(Security::$token_name);
  65. }
  66. }