security.lib.test.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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() {
  39. $var ='';
  40. $type='string';
  41. $options=array();
  42. $res=Security::filter($var, $type, $options);
  43. $this->assertTrue(is_bool($res));
  44. //var_dump($res);
  45. }
  46. function testfilter_filename() {
  47. $filename = 'security/.htaccess';
  48. $res=Security::filter_filename($filename);
  49. $this->assertTrue(is_string($res));
  50. //var_dump($res);
  51. }
  52. function testget() {
  53. $varname='';
  54. $res=Security::get($varname);
  55. if(!empty($res)) {
  56. $this->assertTrue(is_string($res));
  57. } else {
  58. $this->assertTrue(is_null($res));
  59. }
  60. //var_dump($res);
  61. }
  62. function testget_HTML_token() {
  63. $res=Security::get_HTML_token();
  64. $this->assertTrue(is_string($res));
  65. //var_dump($res);
  66. }
  67. function testget_token() {
  68. $res=Security::get_token();
  69. $this->assertTrue(is_string($res));
  70. //var_dump($res);
  71. }
  72. function testget_ua() {
  73. $res=Security::get_ua();
  74. $this->assertTrue(is_null($res));
  75. //var_dump($res);
  76. }
  77. function testremove_XSS() {
  78. global $charset;
  79. $var ='';
  80. $user_status=ANONYMOUS;
  81. $res=Security::remove_XSS($var,$user_status=ANONYMOUS);
  82. if(!empty($res)) {
  83. $this->assertTrue(is_array($res));
  84. } else {
  85. $this->assertTrue(is_string($res));
  86. }
  87. //var_dump($res);
  88. }
  89. }
  90. ?>