From 0d24de74d38bb28b79ee033bba33cbe998f47647 Mon Sep 17 00:00:00 2001 From: bnu Date: Wed, 15 Apr 2015 21:33:45 +0900 Subject: [PATCH] =?UTF-8?q?=EB=8F=99=EC=9E=91=ED=95=98=EC=A7=80=20?= =?UTF-8?q?=EC=95=8A=EB=8D=98=20Unit=20test=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EB=B3=B5=EC=9B=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/_bootstrap.php | 23 +++++ tests/unit/FuncIncTest.class.php | 98 +++++++++---------- tests/unit/FuncIncTest.php | 56 +++++++++++ tests/unit/UnitTester.php | 38 +------ tests/unit/_bootstrap.php | 26 ----- tests/unit/classes/security/SecurityTest.php | 19 ++-- .../unit/classes/validator/ValidatorTest.php | 4 +- 7 files changed, 141 insertions(+), 123 deletions(-) create mode 100644 tests/unit/FuncIncTest.php diff --git a/tests/_bootstrap.php b/tests/_bootstrap.php index e0d603d32..a778b4088 100644 --- a/tests/_bootstrap.php +++ b/tests/_bootstrap.php @@ -1,3 +1,26 @@

IFrame

', - '
<iframe src="path/to/file.html"></iframe>

IFrame

' - ), - // expression - array( - '
', - '
' - ), - // no quotes and no semicolon - http://ha.ckers.org/xss.html - array( - '', - '' - ), - // embedded encoded tab to break up XSS - http://ha.ckers.org/xss.html - array( - '', - '' - ), - // issue 178 - array( - "", - '' - ), - // issue 534 - array( - '*/" onerror="console.log(\'Yet another XSS\')">', - '*/" onerror="console.log(\'Yet another XSS\')">' - ), - // issue 602 - array( - 'test', - 'test' - ) - ); - } + static public function provider() + { + return array( + // remove iframe + array( + '', + '
<iframe src="path/to/file.html"></iframe>

IFrame

' + ), + // expression + array( + '
', + '
' + ), + // no quotes and no semicolon - http://ha.ckers.org/xss.html + array( + '', + '' + ), + // embedded encoded tab to break up XSS - http://ha.ckers.org/xss.html + array( + '', + '' + ), + // issue 178 + array( + "", + '' + ), + // issue 534 + array( + '*/" onerror="console.log(\'Yet another XSS\')">', + '*/" onerror="console.log(\'Yet another XSS\')">' + ), + // issue 602 + array( + 'test', + 'test' + ) + ); + } - /** - * @dataProvider xssProvider - */ - public function testXSS($source, $expected) - { - $result = removeHackTag($source); - $this->assertEquals($result, $expected); - } + /** + * @dataProvider provider + */ + public function testXss($source, $expected) + { + $result = removeHackTag($source); + $this->assertEquals($result, $expected); + } } diff --git a/tests/unit/FuncIncTest.php b/tests/unit/FuncIncTest.php new file mode 100644 index 000000000..bb7e86fa7 --- /dev/null +++ b/tests/unit/FuncIncTest.php @@ -0,0 +1,56 @@ +

IFrame

', + // '
<iframe src="path/to/file.html"></iframe>

IFrame

' + '' + ), + // expression + array( + '
', + '
' + ), + // no quotes and no semicolon - http://ha.ckers.org/xss.html + array( + '', + '' + ), + // embedded encoded tab to break up XSS - http://ha.ckers.org/xss.html + array( + '', + '' + ), + // issue 178 + array( + "", + 'invalid.jpg' + ), + // issue 534 + array( + '*/" onerror="console.log(\'Yet another XSS\')">', + 'as"df dummy=*/" onerror="console.log(\'Yet another XSS\')">' + ), + // issue 602 + array( + 'test', + '' + ) + ); + } + + /** + * @dataProvider provider + */ + public function testXss($source, $expected) + { + $result = removeHackTag($source); + $this->assertEquals($result, $expected); + } +} diff --git a/tests/unit/UnitTester.php b/tests/unit/UnitTester.php index 1cec72fc3..86effba76 100644 --- a/tests/unit/UnitTester.php +++ b/tests/unit/UnitTester.php @@ -1,4 +1,4 @@ -scenario->runStep(new \Codeception\Step\Action('assertSame', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that two variables are not same - * - * @param $expected - * @param $actual - * @param string $message - * @see \Codeception\Module\Asserts::assertNotSame() - */ - public function assertNotSame($expected, $actual, $message = null) { - return $this->scenario->runStep(new \Codeception\Step\Action('assertNotSame', func_get_args())); - } - - /** * [!] Method is generated. Documentation taken from corresponding module. * diff --git a/tests/unit/_bootstrap.php b/tests/unit/_bootstrap.php index 31b359e8a..8ef4ccfd6 100644 --- a/tests/unit/_bootstrap.php +++ b/tests/unit/_bootstrap.php @@ -1,30 +1,4 @@ assertTrue(true); // normal string - one - $this->setUp(); + $this->_before(); $this->assertEquals('Hello, world', Context::get('content1')); $security->encodeHTML('content1'); $this->assertEquals('<strong>Hello, world</strong>', Context::get('content1')); // normal string - two - $this->setUp(); + $this->_before(); $this->assertEquals('Hello, world', Context::get('content1')); $this->assertEquals('Wow, >_< !', Context::get('content2')); $security->encodeHTML('content1','content2'); @@ -61,7 +62,7 @@ class SecurityTest extends \Codeception\TestCase\Test $this->assertEquals(Context::get('array1'), array('<span class="first">F</span>irst','Second','Third')); $security->encodeHTML('array1.2'); // affects only third element $this->assertEquals(Context::get('array1'), array('<span class="first">F</span>irst','Second','<b>T</b>hird')); - $this->setUp(); // reset; + $this->_before(); // reset; $this->assertEquals(Context::get('array1'), array('First','Second','Third')); $security->encodeHTML('array1.'); // affects all items $this->assertEquals(Context::get('array1'), array('<span class="first">F</span>irst','<u>S</u>econd','<b>T</b>hird')); @@ -74,7 +75,7 @@ class SecurityTest extends \Codeception\TestCase\Test $this->assertEquals(Context::get('array2'), array('elem1'=>'One 1','elem2'=>'Two 2','elem3'=>'Three 3')); $security->encodeHTML('array2.elem2'); // affects only 'elem2' $this->assertEquals(Context::get('array2'), array('elem1'=>'One 1','elem2'=>'Two <del>2</del>','elem3'=>'Three 3')); - $this->setUp(); // reset; + $this->_before(); // reset; $this->assertEquals(Context::get('array2'), array('elem1'=>'One 1','elem2'=>'Two 2','elem3'=>'Three 3')); $security->encodeHTML('array2.'); // affects all items $this->assertEquals(Context::get('array2'), array('elem1'=>'One <ins>1</ins>','elem2'=>'Two <del>2</del>','elem3'=>'Three <addr>3</addr>')); @@ -94,7 +95,7 @@ class SecurityTest extends \Codeception\TestCase\Test $security->encodeHTML('object1.prop3'); // affects only 'prop3' property $obj->prop3 = '<strong>Strong</strong> Baby'; $this->assertEquals(Context::get('object1'), $obj); - $this->setUp(); // reset + $this->_before(); // reset $obj->prop3 = 'Strong Baby'; $this->assertEquals(Context::get('object1'), $obj); $security->encodeHTML('object1.'); // affects all properties @@ -103,7 +104,7 @@ class SecurityTest extends \Codeception\TestCase\Test $this->assertEquals(Context::get('object1'), $obj); } - public function testEncodeHTML_CustomContext() + public function testEncodeHtmlCustomContext() { $array = array('Hello', 'World', 'Bold is not bald'); diff --git a/tests/unit/classes/validator/ValidatorTest.php b/tests/unit/classes/validator/ValidatorTest.php index c3045f814..2b2e45f46 100644 --- a/tests/unit/classes/validator/ValidatorTest.php +++ b/tests/unit/classes/validator/ValidatorTest.php @@ -7,11 +7,11 @@ require_once _XE_PATH_.'classes/validator/Validator.class.php'; class ValidatorTest extends \Codeception\TestCase\Test { - protected function setUp() + public function _before() { global $lang; - $lang->filter = new stdClass; + $lang->filter = new stdClass(); $lang->filter->isnull = 'isnull'; $lang->filter->outofrange = 'outofrange'; $lang->filter->equalto = 'equalto';