동작하지 않던 Unit test 코드 복원

This commit is contained in:
bnu 2015-04-15 21:33:45 +09:00
parent 3e58d680d8
commit 0d24de74d3
7 changed files with 141 additions and 123 deletions

View file

@ -1,3 +1,26 @@
<?php
// This is global bootstrap for autoloading
if(!defined('__XE__')) define('__XE__', true);
if(!defined('_XE_PATH_')) define('_XE_PATH_', realpath(dirname(__FILE__).'/../').'/');
error_reporting(E_ALL ^ E_NOTICE ^ E_DEPRECATED ^ E_WARNING ^ E_STRICT);
function _debug() {
$args = func_get_args();
$bt = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS | DEBUG_BACKTRACE_PROVIDE_OBJECT, 2);
if(is_array($bt))
{
$bt_debug_print = array_shift($bt);
$bt_called_function = array_shift($bt);
}
$file_name = str_replace(_XE_PATH_, '', $bt_debug_print['file']);
$line_num = $bt_debug_print['line'];
if($bt_called_function) $function = $bt_called_function['class'] . $bt_called_function['type'] . $bt_called_function['function'];
$print = sprintf("%s() [%s:%d]", $function, $file_name, $line_num);
codecept_debug("\n" . $print);
foreach($args as $arg) {
codecept_debug('(' . gettype($arg) . ') ' . var_export($arg, true));
}
}

View file

@ -1,55 +1,53 @@
<?php
require _XE_PATH_.'/config/func.inc.php';
class FuncIncTest extends \Codeception\TestCase\Test
{
static public function xssProvider()
{
return array(
// remove iframe
array(
'<div class="frame"><iframe src="path/to/file.html"></iframe><p><a href="#iframe">IFrame</a></p></div>',
'<div class="frame">&lt;iframe src="path/to/file.html">&lt;/iframe><p><a href="#iframe">IFrame</a></p></div>'
),
// expression
array(
'<div class="dummy" style="xss:expr/*XSS*/ession(alert(\'XSS\'))">',
'<div class="dummy">'
),
// no quotes and no semicolon - http://ha.ckers.org/xss.html
array(
'<img src=javascript:alert(\'xss\')>',
'<img>'
),
// embedded encoded tab to break up XSS - http://ha.ckers.org/xss.html
array(
'<IMG SRC="jav&#x09;ascript:alert(\'XSS\');">',
'<img>'
),
// issue 178
array(
"<img src=\"invalid\"\nonerror=\"alert(1)\" />",
'<img src="invalid" />'
),
// issue 534
array(
'<img src=\'as"df dummy=\'"1234\'" 4321\' asdf/*/>*/" onerror="console.log(\'Yet another XSS\')">',
'<img src="as&quot;df dummy=" />*/" onerror="console.log(\'Yet another XSS\')">'
),
// issue 602
array(
'<img alt="test" src="(http://static.naver.com/www/u/2010/0611/nmms_215646753.gif" onload="eval(String.fromCharCode(105,61,49,48,48,59,119,104,105,108,101, 40,105,62,48,41,97,108,101,114,116,40,40,105,45,45,41,43,39,48264,47564,32, 45908,32,53364,47533,54616,49464,50836,39,41,59));">',
'<img alt="test" src="(http://static.naver.com/www/u/2010/0611/nmms_215646753.gif">'
)
);
}
static public function provider()
{
return array(
// remove iframe
array(
'<div class="frame"><iframe src="path/to/file.html"></iframe><p><a href="#iframe">IFrame</a></p></div>',
'<div class="frame">&lt;iframe src="path/to/file.html">&lt;/iframe><p><a href="#iframe">IFrame</a></p></div>'
),
// expression
array(
'<div class="dummy" style="xss:expr/*XSS*/ession(alert(\'XSS\'))">',
'<div class="dummy">'
),
// no quotes and no semicolon - http://ha.ckers.org/xss.html
array(
'<img src=javascript:alert(\'xss\')>',
'<img>'
),
// embedded encoded tab to break up XSS - http://ha.ckers.org/xss.html
array(
'<IMG SRC="jav&#x09;ascript:alert(\'XSS\');">',
'<img>'
),
// issue 178
array(
"<img src=\"invalid\"\nonerror=\"alert(1)\" />",
'<img src="invalid" />'
),
// issue 534
array(
'<img src=\'as"df dummy=\'"1234\'" 4321\' asdf/*/>*/" onerror="console.log(\'Yet another XSS\')">',
'<img src="as&quot;df dummy=" />*/" onerror="console.log(\'Yet another XSS\')">'
),
// issue 602
array(
'<img alt="test" src="(http://static.naver.com/www/u/2010/0611/nmms_215646753.gif" onload="eval(String.fromCharCode(105,61,49,48,48,59,119,104,105,108,101, 40,105,62,48,41,97,108,101,114,116,40,40,105,45,45,41,43,39,48264,47564,32, 45908,32,53364,47533,54616,49464,50836,39,41,59));">',
'<img alt="test" src="(http://static.naver.com/www/u/2010/0611/nmms_215646753.gif">'
)
);
}
/**
* @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);
}
}

View file

@ -0,0 +1,56 @@
<?php
require_once( _XE_PATH_.'config/func.inc.php');
class FuncIncTest extends \Codeception\TestCase\Test
{
static public function provider()
{
return array(
// remove iframe
array(
'<div class="frame"><iframe src="path/to/file.html"></iframe><p><a href="#iframe">IFrame</a></p></div>',
// '<div class="frame">&lt;iframe src="path/to/file.html">&lt;/iframe><p><a href="#iframe">IFrame</a></p></div>'
'<div class="frame"><iframe></iframe><p><a href="#iframe">IFrame</a></p></div>'
),
// expression
array(
'<div class="dummy" style="xss:expr/*XSS*/ession(alert(\'XSS\'))">',
'<div class="dummy"></div>'
),
// no quotes and no semicolon - http://ha.ckers.org/xss.html
array(
'<img src=javascript:alert(\'xss\')>',
''
),
// embedded encoded tab to break up XSS - http://ha.ckers.org/xss.html
array(
'<IMG SRC="jav&#x09;ascript:alert(\'XSS\');">',
''
),
// issue 178
array(
"<img src=\"invalid.jpg\"\nonerror=\"alert(1)\" />",
'<img src="invalid.jpg" alt="invalid.jpg" />'
),
// issue 534
array(
'<img src=\'as"df dummy=\'"1234\'" 4321\' asdf/*/>*/" onerror="console.log(\'Yet another XSS\')">',
'<img src="as" alt="as&quot;df dummy=" />*/" onerror="console.log(\'Yet another XSS\')"&gt;'
),
// issue 602
array(
'<img alt="test" src="(http://static.naver.com/www/u/2010/0611/nmms_215646753.gif" onload="eval(String.fromCharCode(105,61,49,48,48,59,119,104,105,108,101, 40,105,62,48,41,97,108,101,114,116,40,40,105,45,45,41,43,39,48264,47564,32, 45908,32,53364,47533,54616,49464,50836,39,41,59));">',
''
)
);
}
/**
* @dataProvider provider
*/
public function testXss($source, $expected)
{
$result = removeHackTag($source);
$this->assertEquals($result, $expected);
}
}

View file

@ -1,4 +1,4 @@
<?php //[STAMP] 82bc9161e8772dbad0b5d616567eaa2d
<?php //[STAMP] cb6a361b59627f91b689bd53cd926484
// This class was automatically generated by build task
// You should not change it manually as it will be overwritten on next build
@ -19,9 +19,7 @@ use Codeception\Module\UnitHelper;
* @method void am($role)
* @method void lookForwardTo($achieveValue)
* @method void comment($description)
* @method void haveFriend($name, $actorClass = null)
*
* @SuppressWarnings(PHPMD)
* @method void haveFriend($name)
*/
class UnitTester extends \Codeception\Actor
{
@ -58,38 +56,6 @@ class UnitTester extends \Codeception\Actor
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that two variables are same
*
* @param $expected
* @param $actual
* @param string $message
*
* @return mixed
* @see \Codeception\Module\Asserts::assertSame()
*/
public function assertSame($expected, $actual, $message = null) {
return $this->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.
*

View file

@ -1,30 +1,4 @@
<?php
use Codeception\Util\Debug;
if(!defined('__XE__')) define('__XE__', TRUE);
if(!defined('_XE_PATH_')) define('_XE_PATH_', realpath(dirname(__FILE__).'/../').'/');
$_SERVER['SCRIPT_NAME'] = '/xe/index.php';
error_reporting(E_ALL ^ E_NOTICE ^ E_DEPRECATED ^ E_WARNING ^ E_STRICT);
function _log() {
$args = func_get_args();
$bt = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS | DEBUG_BACKTRACE_PROVIDE_OBJECT, 2);
if(is_array($bt))
{
$bt_debug_print = array_shift($bt);
$bt_called_function = array_shift($bt);
}
$file_name = str_replace(_XE_PATH_, '', $bt_debug_print['file']);
$line_num = $bt_debug_print['line'];
$function = $bt_called_function['class'] . $bt_called_function['type'] . $bt_called_function['function'];
$print = sprintf("%s() [%s:%d]", $function, $file_name, $line_num);
Debug::debug("\n" . $print);
foreach($args as $arg) {
Debug::debug('(' . gettype($arg) . ') ' . var_export($arg, true));
}
}

View file

@ -1,9 +1,9 @@
<?php
require_once _XE_PATH_.'/classes/security/Security.class.php';
require_once _XE_PATH_.'classes/security/Security.class.php';
class SecurityTest extends \Codeception\TestCase\Test
{
protected function setUp()
public function _before()
{
/**
* Setup mock data
@ -35,18 +35,19 @@ class SecurityTest extends \Codeception\TestCase\Test
Context::set('array2', $aarr);
}
public function testEncodeHTML_DefaultContext()
public function testEncodeHtmlDefaultContext()
{
$security = new Security();
$this->assertTrue(true);
// normal string - one
$this->setUp();
$this->_before();
$this->assertEquals('<strong>Hello, world</strong>', Context::get('content1'));
$security->encodeHTML('content1');
$this->assertEquals('&lt;strong&gt;Hello, world&lt;/strong&gt;', Context::get('content1'));
// normal string - two
$this->setUp();
$this->_before();
$this->assertEquals('<strong>Hello, world</strong>', 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('&lt;span class=&quot;first&quot;&gt;F&lt;/span&gt;irst','<u>S</u>econd','<b>T</b>hird'));
$security->encodeHTML('array1.2'); // affects only third element
$this->assertEquals(Context::get('array1'), array('&lt;span class=&quot;first&quot;&gt;F&lt;/span&gt;irst','<u>S</u>econd','&lt;b&gt;T&lt;/b&gt;hird'));
$this->setUp(); // reset;
$this->_before(); // reset;
$this->assertEquals(Context::get('array1'), array('<span class="first">F</span>irst','<u>S</u>econd','<b>T</b>hird'));
$security->encodeHTML('array1.'); // affects all items
$this->assertEquals(Context::get('array1'), array('&lt;span class=&quot;first&quot;&gt;F&lt;/span&gt;irst','&lt;u&gt;S&lt;/u&gt;econd','&lt;b&gt;T&lt;/b&gt;hird'));
@ -74,7 +75,7 @@ class SecurityTest extends \Codeception\TestCase\Test
$this->assertEquals(Context::get('array2'), array('elem1'=>'One <ins>1</ins>','elem2'=>'Two <del>2</del>','elem3'=>'Three <addr>3</addr>'));
$security->encodeHTML('array2.elem2'); // affects only 'elem2'
$this->assertEquals(Context::get('array2'), array('elem1'=>'One <ins>1</ins>','elem2'=>'Two &lt;del&gt;2&lt;/del&gt;','elem3'=>'Three <addr>3</addr>'));
$this->setUp(); // reset;
$this->_before(); // reset;
$this->assertEquals(Context::get('array2'), array('elem1'=>'One <ins>1</ins>','elem2'=>'Two <del>2</del>','elem3'=>'Three <addr>3</addr>'));
$security->encodeHTML('array2.'); // affects all items
$this->assertEquals(Context::get('array2'), array('elem1'=>'One &lt;ins&gt;1&lt;/ins&gt;','elem2'=>'Two &lt;del&gt;2&lt;/del&gt;','elem3'=>'Three &lt;addr&gt;3&lt;/addr&gt;'));
@ -94,7 +95,7 @@ class SecurityTest extends \Codeception\TestCase\Test
$security->encodeHTML('object1.prop3'); // affects only 'prop3' property
$obj->prop3 = '&lt;strong&gt;Strong&lt;/strong&gt; Baby';
$this->assertEquals(Context::get('object1'), $obj);
$this->setUp(); // reset
$this->_before(); // reset
$obj->prop3 = '<strong>Strong</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', '<b>Bold</b> is not bald');

View file

@ -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';