pushing to start core rebuild
This commit is contained in:
parent
7393f21d01
commit
f21f05e874
@ -36,6 +36,18 @@ class Token_Type Extends Base {
|
|||||||
return $result->fetch_all(MYSQLI_ASSOC);
|
return $result->fetch_all(MYSQLI_ASSOC);
|
||||||
return $this->sqlError();
|
return $this->sqlError();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch all tokens - used for unit tests
|
||||||
|
* @param none
|
||||||
|
* @return array All tokentypes
|
||||||
|
**/
|
||||||
|
public function getAll() {
|
||||||
|
$stmt = $this->mysqli->prepare("SELECT * FROM $this->table");
|
||||||
|
if ($this->checkStmt($stmt) && $stmt->execute() && $result = $stmt->get_result())
|
||||||
|
return $result->fetch_all(MYSQLI_ASSOC);
|
||||||
|
return $this->sqlError();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$tokentype = new Token_Type();
|
$tokentype = new Token_Type();
|
||||||
|
|||||||
@ -20,4 +20,19 @@ require_once(BASEPATH . 'include/autoloader.inc.php');
|
|||||||
|
|
||||||
require_once("PHPUnit/Autoload.php");
|
require_once("PHPUnit/Autoload.php");
|
||||||
|
|
||||||
|
/*
|
||||||
|
* apache2* libapache2-mod-php5* mysql-server* php-codecoverage*
|
||||||
|
php-codesniffer* php-file-iterator* php-gettext* php-pear* php-symfony-yaml*
|
||||||
|
php-text-template* php-timer* php-token-stream* php5* php5-cli*
|
||||||
|
php5-mysqlnd* phpmyadmin* phppgadmin* phpunit* phpunit-mock-object*
|
||||||
|
sudo apt-get install mysql-server apache2 memcached php5-memcached php5-mysqlnd php5-curl php5-json php5-cli libapache2-mod-php5 phpmyadmin phpunit phpunit-mock-object
|
||||||
|
*/
|
||||||
|
|
||||||
|
// your db connection setup
|
||||||
|
class DBConnection {
|
||||||
|
public function __construct($config) {
|
||||||
|
return new mysqli($config['db']['host'], $config['db']['user'], $config['db']['pass'], $config['db']['name'], $config['db']['port']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
@ -7,4 +7,7 @@ define('BASEPATH', '/var/www/php-mpos-allbranches/php-mpos/public/');
|
|||||||
// 0 = dist, 1 = real
|
// 0 = dist, 1 = real
|
||||||
define('DIST_OR_REAL_CONFIG', 1);
|
define('DIST_OR_REAL_CONFIG', 1);
|
||||||
|
|
||||||
|
// because php cli defaults are shit, the socket might be wrong
|
||||||
|
ini_set('mysqli.default_socket', '/var/run/mysqld/mysqld.sock');
|
||||||
|
|
||||||
?>
|
?>
|
||||||
@ -9,5 +9,8 @@
|
|||||||
<testsuite name="Security_Sessions">
|
<testsuite name="Security_Sessions">
|
||||||
<directory>unit/securityregress/Security_Sessions.php</directory>
|
<directory>unit/securityregress/Security_Sessions.php</directory>
|
||||||
</testsuite>
|
</testsuite>
|
||||||
|
<testsuite name="Security_Tokens">
|
||||||
|
<directory>unit/securityregress/Security_Tokens.php</directory>
|
||||||
|
</testsuite>
|
||||||
</testsuites>
|
</testsuites>
|
||||||
</phpunit>
|
</phpunit>
|
||||||
@ -14,7 +14,6 @@ class Security_CSRFToken extends PHPUnit_Framework_Testcase {
|
|||||||
$created_token = $csrftoken->getBasic($user->getCurrentIP(), 'test-token');
|
$created_token = $csrftoken->getBasic($user->getCurrentIP(), 'test-token');
|
||||||
$test_token = $csrftoken->checkBasic($user->getCurrentIP(), 'test-token', $created_token);
|
$test_token = $csrftoken->checkBasic($user->getCurrentIP(), 'test-token', $created_token);
|
||||||
$this->assertTrue($test_token);
|
$this->assertTrue($test_token);
|
||||||
$this->assertAttributeEquals($csrftoken->valid, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
25
tests/unit/securityregress/Security_Tokens.php
Normal file
25
tests/unit/securityregress/Security_Tokens.php
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class Security_Tokens extends PHPUnit_Framework_Testcase {
|
||||||
|
/**
|
||||||
|
* Tests tokens CRUD
|
||||||
|
*/
|
||||||
|
function testTokens_CRUD() {
|
||||||
|
global $config;
|
||||||
|
global $mysqli;
|
||||||
|
$mysqli = new DBConnection($config);
|
||||||
|
global $tokentype;
|
||||||
|
global $oToken;
|
||||||
|
// grab token types first so we can test them all
|
||||||
|
$token_types = $tokentype->getAll();
|
||||||
|
|
||||||
|
foreach ($token_types as $tt) {
|
||||||
|
// create
|
||||||
|
$create_token = $oToken->createToken($tt['name'], 1);
|
||||||
|
$this->assertStringMatchesFormat('%x', $create_token);
|
||||||
|
$this->assertGreaterThan(16, strlen($create_token));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
Loading…
Reference in New Issue
Block a user