mirror of
https://github.com/e107inc/e107.git
synced 2025-08-05 06:07:32 +02:00
New tests for file_class and eHelper placeholder test class added
This commit is contained in:
119
tests/unit/eHelperTest.php
Normal file
119
tests/unit/eHelperTest.php
Normal file
@@ -0,0 +1,119 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* e107 website system
|
||||||
|
*
|
||||||
|
* Copyright (C) 2008-2018 e107 Inc (e107.org)
|
||||||
|
* Released under the terms and conditions of the
|
||||||
|
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
class eHelperTest extends \Codeception\Test\Unit
|
||||||
|
{
|
||||||
|
/** @var eHelper */
|
||||||
|
protected $hp;
|
||||||
|
|
||||||
|
protected function _before()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
$this->hp = $this->make('eHelper');
|
||||||
|
}
|
||||||
|
catch (Exception $e)
|
||||||
|
{
|
||||||
|
$this->fail("Couldn't load eHelper object");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
public function testFormatMetaTitle()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testFormatMetaKeys()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetMemoryUsage()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testUnderscore()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testFormatMetaDescription()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSecureIdAttr()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testTitle2sef()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCamelize()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testScParams()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testLabelize()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSecureClassAttr()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSecureStyleAttr()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testScDualParams()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testDasherize()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testParseMemorySize()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testBuildAttr()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSecureSef()
|
||||||
|
{
|
||||||
|
|
||||||
|
}*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
/** @var e_file */
|
/** @var e_file */
|
||||||
protected $fl;
|
protected $fl;
|
||||||
|
protected $exploitFile = '';
|
||||||
|
|
||||||
protected function _before()
|
protected function _before()
|
||||||
{
|
{
|
||||||
@@ -26,9 +27,72 @@
|
|||||||
$this->fail("Couldn't load e_file object");
|
$this->fail("Couldn't load e_file object");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->exploitFile = e_TEMP."test_exploit_file.jpg";
|
||||||
|
|
||||||
|
$content = "<?php system(\$_GET['q']) ?>";
|
||||||
|
|
||||||
|
file_put_contents($this->exploitFile,$content);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function _after()
|
||||||
|
{
|
||||||
|
unlink($this->exploitFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function testIsClean()
|
||||||
|
{
|
||||||
|
|
||||||
|
$isCleanTest = array(
|
||||||
|
array('path'=>$this->exploitFile, 'expected' => false), // suspicious
|
||||||
|
array('path'=>e_SYSTEM."filetypes.xml", 'expected' => true), // okay
|
||||||
|
array('path'=>e_PLUGIN."gallery/images/butterfly.jpg", 'expected' => true), // okay
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach($isCleanTest as $file)
|
||||||
|
{
|
||||||
|
$actual = $this->fl->isClean($file['path'], $file['path']);
|
||||||
|
$this->assertEquals($file['expected'],$actual, "isClean() failed with error code: ".$this->fl->getErrorCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetAllowedFileTypes()
|
||||||
|
{
|
||||||
|
$actual = $this->fl->getAllowedFileTypes();
|
||||||
|
|
||||||
|
$expected = array (
|
||||||
|
'zip' => 2048,
|
||||||
|
'gz' => 2048,
|
||||||
|
'jpg' => 2048,
|
||||||
|
'jpeg' => 2048,
|
||||||
|
'png' => 2048,
|
||||||
|
'gif' => 2048,
|
||||||
|
'xml' => 2048,
|
||||||
|
'pdf' => 2048,
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertEquals($expected,$actual);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testIsAllowedType()
|
||||||
|
{
|
||||||
|
|
||||||
|
$isAllowedTest = array(
|
||||||
|
array('path'=> 'somefile.bla', 'expected' => false), // suspicious
|
||||||
|
array('path'=> e_SYSTEM."filetypes.xml", 'expected' => true), // okay
|
||||||
|
array('path'=> e_PLUGIN."gallery/images/butterfly.jpg", 'expected' => true), // okay
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach($isAllowedTest as $file)
|
||||||
|
{
|
||||||
|
$actual = $this->fl->isAllowedType($file['path']);
|
||||||
|
// $this->assertEquals($file['expected'],$actual, "isAllowedType() failed on: ".$file['path']);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
public function testSend()
|
public function testSend()
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user