summaryrefslogtreecommitdiffstats
path: root/tests/codeigniter/helpers/security_helper_test.php
diff options
context:
space:
mode:
authordchill42 <dchill42@gmail.com>2012-10-21 01:39:40 +0200
committerdchill42 <dchill42@gmail.com>2012-10-21 01:39:40 +0200
commit9e4ebf1af81b0e5216a026fe4a99a19f2be6a831 (patch)
tree97ddddc6b7a65130672a168f522d7a69e515ec54 /tests/codeigniter/helpers/security_helper_test.php
parente3621cc79fa4b4658768fea0694cc0ae52835d85 (diff)
parent8df1ae2d7e0fd441f7a1fc481c76c5c1edfadf23 (diff)
Merge branch 'develop' of git://github.com/EllisLab/CodeIgniter into load_config_units
Diffstat (limited to 'tests/codeigniter/helpers/security_helper_test.php')
-rw-r--r--tests/codeigniter/helpers/security_helper_test.php64
1 files changed, 64 insertions, 0 deletions
diff --git a/tests/codeigniter/helpers/security_helper_test.php b/tests/codeigniter/helpers/security_helper_test.php
new file mode 100644
index 000000000..effd3ec02
--- /dev/null
+++ b/tests/codeigniter/helpers/security_helper_test.php
@@ -0,0 +1,64 @@
+<?php
+
+class Security_helper_tests extends CI_TestCase {
+
+ function setUp()
+ {
+ $this->helper('security');
+ $obj = new stdClass;
+ $obj->security = new Mock_Core_Security();
+ $this->ci_instance($obj);
+ }
+
+ function test_xss_clean()
+ {
+ $this->assertEquals('foo', xss_clean('foo'));
+
+ $this->assertEquals("Hello, i try to [removed]alert&#40;'Hack'&#41;;[removed] your site", xss_clean("Hello, i try to <script>alert('Hack');</script> your site"));
+ }
+
+ function test_sanitize_filename()
+ {
+ $this->assertEquals('hello.doc', sanitize_filename('hello.doc'));
+
+ $filename = './<!--foo-->';
+ $this->assertEquals('foo', sanitize_filename($filename));
+ }
+
+ function test_do_hash()
+ {
+ $md5 = md5('foo');
+ $sha1 = sha1('foo');
+
+ $algos = hash_algos();
+ $algo_results = array();
+ foreach ($algos as $k => $v)
+ {
+ $algo_results[$v] = hash($v, 'foo');
+ }
+
+ $this->assertEquals($sha1, do_hash('foo'));
+ $this->assertEquals($sha1, do_hash('foo', 'sha1'));
+ $this->assertEquals($md5, do_hash('foo', 'md5'));
+ $this->assertEquals($md5, do_hash('foo', 'foobar'));
+
+ // Test each algorithm available to PHP
+ foreach ($algo_results as $algo => $result)
+ {
+ $this->assertEquals($result, do_hash('foo', $algo));
+ }
+ }
+
+ function test_strip_image_tags()
+ {
+ $this->assertEquals('http://example.com/spacer.gif', strip_image_tags('http://example.com/spacer.gif'));
+
+ $this->assertEquals('http://example.com/spacer.gif', strip_image_tags('<img src="http://example.com/spacer.gif" alt="Who needs CSS when you have a spacer.gif?" />'));
+ }
+
+ function test_encode_php_tags()
+ {
+ $this->assertEquals('&lt;? echo $foo; ?&gt;', encode_php_tags('<? echo $foo; ?>'));
+ }
+
+} \ No newline at end of file