Dropped other classes we don't need any longer
This commit is contained in:
parent
e299d268c8
commit
1381fd82a0
5 changed files with 0 additions and 723 deletions
|
@ -1,153 +0,0 @@
|
|||
<?php
|
||||
|
||||
class MockUserModel extends Model
|
||||
{
|
||||
public $table = 'users';
|
||||
}
|
||||
|
||||
class SecurityTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testGenerateHashWithDefaultSalts()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'4940e793006aa897db22751bba80dff4cb6a3e08',
|
||||
Security::generateHash('source')
|
||||
);
|
||||
}
|
||||
|
||||
public function testGenerateHashWithCustomSalts()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$config->data['security']['salt'] = 'salt';
|
||||
|
||||
$this->assertEquals(
|
||||
'4eac88c934c33cfa9a80c0b2eb322f23ac3b13c5',
|
||||
Security::generateHash('source')
|
||||
);
|
||||
}
|
||||
|
||||
public function testGenerateSHA256Hash()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'3d04f805aff4838ecaf98c7260a813fffd2b7a8a7f957add8018908a1bbdad04',
|
||||
Security::generateSHA256Hash('source', 'salt')
|
||||
);
|
||||
}
|
||||
|
||||
public function testLogin()
|
||||
{
|
||||
$this->assertTrue(Security::login(1, 10, 'USER'));
|
||||
$this->assertTrue(isset($_SESSION['__pickles']['security']));
|
||||
}
|
||||
|
||||
public function testLoginNoSession()
|
||||
{
|
||||
session_destroy();
|
||||
$this->assertFalse(Security::login(1, 10, 'USER'));
|
||||
}
|
||||
|
||||
public function testLogout()
|
||||
{
|
||||
session_start();
|
||||
Security::login(1, 10, 'USER');
|
||||
|
||||
$this->assertTrue(Security::logout());
|
||||
$this->assertFalse(isset($_SESSION['__pickles']['security']));
|
||||
}
|
||||
|
||||
public function testIsLevel()
|
||||
{
|
||||
Security::login(1, 10, 'USER');
|
||||
|
||||
$this->assertTrue(Security::isLevel(SECURITY_LEVEL_USER));
|
||||
}
|
||||
|
||||
public function testIsLevelArray()
|
||||
{
|
||||
Security::login(1, 10, 'USER');
|
||||
|
||||
$this->assertTrue(Security::isLevel([SECURITY_LEVEL_USER, SECURITY_LEVEL_ADMIN]));
|
||||
}
|
||||
|
||||
public function testHasLevel()
|
||||
{
|
||||
Security::login(1, 10, 'USER');
|
||||
|
||||
$this->assertTrue(Security::hasLevel(SECURITY_LEVEL_USER));
|
||||
}
|
||||
|
||||
public function testHasLevelArray()
|
||||
{
|
||||
Security::login(1, 10, 'USER');
|
||||
|
||||
$this->assertTrue(Security::hasLevel([SECURITY_LEVEL_USER, SECURITY_LEVEL_ADMIN]));
|
||||
}
|
||||
|
||||
public function testBetweenLevel()
|
||||
{
|
||||
Security::login(1, 10, 'USER');
|
||||
|
||||
$this->assertTrue(Security::betweenLevel(SECURITY_LEVEL_USER, SECURITY_LEVEL_ADMIN));
|
||||
}
|
||||
|
||||
public function testTokenMismatch()
|
||||
{
|
||||
Security::login(1, 10, 'USER');
|
||||
|
||||
$_SESSION['__pickles']['security']['token'] = 'foo';
|
||||
$_COOKIE['pickles_security_token'] = 'bar';
|
||||
|
||||
$this->assertFalse(Security::isLevel(SECURITY_LEVEL_USER));
|
||||
}
|
||||
|
||||
public function testIsLevelDB()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
|
||||
$config->data = [
|
||||
'pickles' => [
|
||||
'datasource' => 'mysql',
|
||||
'cache' => 'memcache',
|
||||
],
|
||||
'datasources' => [
|
||||
'mysql' => [
|
||||
'type' => 'mysql',
|
||||
'driver' => 'pdo_mysql',
|
||||
'hostname' => 'localhost',
|
||||
'username' => '',
|
||||
'password' => '',
|
||||
'database' => 'test',
|
||||
'cache' => true,
|
||||
],
|
||||
'memcache' => [
|
||||
'type' => 'memcache',
|
||||
'hostname' => 'localhost',
|
||||
'port' => 11211,
|
||||
'namespace' => '',
|
||||
],
|
||||
],
|
||||
'security' => ['model' => 'MockUserModel'],
|
||||
];
|
||||
|
||||
$model = new MockUserModel();
|
||||
$model->record['username'] = 'pickles';
|
||||
$model->commit();
|
||||
|
||||
setUpConfig([
|
||||
|
||||
]);
|
||||
|
||||
new Config();
|
||||
|
||||
Security::login(1, 10, 'USER');
|
||||
|
||||
unset(
|
||||
$_SESSION['__pickles']['security']['token'],
|
||||
$_COOKIE['pickles_security_token'],
|
||||
$_SESSION['__pickles']['security']['level']
|
||||
);
|
||||
|
||||
$this->assertFalse(Security::isLevel([SECURITY_LEVEL_USER, SECURITY_LEVEL_ADMIN]));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,98 +0,0 @@
|
|||
<?php
|
||||
|
||||
class SessionTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
if (session_id())
|
||||
{
|
||||
session_destroy();
|
||||
}
|
||||
|
||||
$_SERVER['HTTP_USER_AGENT'] = 'yes';
|
||||
$_SERVER['REQUEST_METHOD'] = 'GET';
|
||||
}
|
||||
|
||||
public function testFiles()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$config->data['pickles']['sessions'] = 'files';
|
||||
|
||||
new Session();
|
||||
|
||||
$_SESSION['test'] = 'files';
|
||||
$this->assertEquals('files', $_SESSION['test']);
|
||||
}
|
||||
|
||||
public function testMemcache()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$config->data['pickles']['sessions'] = 'memcache';
|
||||
$config->data['datasources']['memcache'] = [
|
||||
'type' => 'memcache',
|
||||
'hostname' => 'localhost',
|
||||
'port' => '11211',
|
||||
];
|
||||
|
||||
new Session();
|
||||
|
||||
$_SESSION['test'] = 'memcache';
|
||||
$this->assertEquals('memcache', $_SESSION['test']);
|
||||
}
|
||||
|
||||
public function testMemcached()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$config->data['pickles']['sessions'] = 'memcached';
|
||||
$config->data['datasources']['memcached'] = [
|
||||
'type' => 'memcached',
|
||||
'hostname' => 'localhost',
|
||||
'port' => '11211',
|
||||
];
|
||||
|
||||
new Session();
|
||||
|
||||
$_SESSION['test'] = 'memcached';
|
||||
$this->assertEquals('memcached', $_SESSION['test']);
|
||||
}
|
||||
|
||||
public function testRedis()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$config->data['pickles']['sessions'] = 'redis';
|
||||
$config->data['datasources']['redis'] = [
|
||||
'type' => 'redis',
|
||||
'hostname' => 'localhost',
|
||||
'port' => '6379',
|
||||
'database' => '1',
|
||||
'prefix' => 'p:',
|
||||
];
|
||||
|
||||
new Session();
|
||||
|
||||
$_SESSION['test'] = 'redis';
|
||||
$this->assertEquals('redis', $_SESSION['test']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage You must provide both the hostname and port for the datasource.
|
||||
*/
|
||||
public function testMissingHostname()
|
||||
{
|
||||
$_SERVER['REQUEST_METHOD'] = 'GET';
|
||||
|
||||
$config = Config::getInstance();
|
||||
$config->data['pickles']['sessions'] = 'redis';
|
||||
$config->data['datasources']['redis'] = [
|
||||
'type' => 'redis',
|
||||
'port' => '6379',
|
||||
];
|
||||
|
||||
new Session();
|
||||
|
||||
$_SESSION['test'] = 'redis';
|
||||
$this->assertEquals('redis', $_SESSION['test']);
|
||||
}
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue