security.lib.test.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. require_once(api_get_path(LIBRARY_PATH).'security.lib.php');
  3. require_once(api_get_path(LIBRARY_PATH).'fileUpload.lib.php');
  4. class TestSecurity extends UnitTestCase {
  5. public $clean = array();
  6. public function __construct() {
  7. $this->UnitTestCase('Security library - main/inc/lib/security.lib.test.php');
  8. }
  9. function testcheck_abs_path() {
  10. $abs_path='';
  11. $checker_path='';
  12. $res=Security::check_abs_path($abs_path,$checker_path);
  13. $this->assertTrue(is_bool($res));
  14. //var_dump($res);
  15. }
  16. function testcheck_rel_path() {
  17. $rel_path='';
  18. $checker_path='';
  19. $res=Security::check_rel_path($rel_path,$checker_path);
  20. $this->assertTrue(is_bool($res));
  21. //var_dump($res);
  22. }
  23. function testcheck_token() {
  24. $res=Security::check_token();
  25. $this->assertTrue(is_bool($res));
  26. //var_dump($res);
  27. }
  28. function testcheck_ua() {
  29. $res=Security::check_ua();
  30. $this->assertTrue(is_bool($res));
  31. //var_dump($res);
  32. }
  33. function testclear_token() {
  34. $res=Security::clear_token();
  35. $this->assertTrue(is_null($res));
  36. //var_dump($res);
  37. }
  38. function testfilter_filename() {
  39. $filename = 'security/.htaccess';
  40. $res=Security::filter_filename($filename);
  41. $this->assertTrue(is_string($res));
  42. //var_dump($res);
  43. }
  44. function testget() {
  45. $varname='';
  46. $res=Security::get($varname);
  47. if(!empty($res)) {
  48. $this->assertTrue(is_string($res));
  49. } else {
  50. $this->assertTrue(is_null($res));
  51. }
  52. //var_dump($res);
  53. }
  54. function testget_HTML_token() {
  55. $res=Security::get_HTML_token();
  56. $this->assertTrue(is_string($res));
  57. //var_dump($res);
  58. }
  59. function testget_token() {
  60. $res=Security::get_token();
  61. $this->assertTrue(is_string($res));
  62. //var_dump($res);
  63. }
  64. function testget_ua() {
  65. $res=Security::get_ua();
  66. $this->assertTrue(is_null($res));
  67. //var_dump($res);
  68. }
  69. function testremove_XSS() {
  70. global $charset;
  71. $var ='';
  72. $user_status=ANONYMOUS;
  73. $res=Security::remove_XSS($var,$user_status=ANONYMOUS);
  74. if(!empty($res)) {
  75. $this->assertTrue(is_array($res));
  76. } else {
  77. $this->assertTrue(is_string($res));
  78. }
  79. //var_dump($res);
  80. }
  81. }
  82. ?>