diff --git a/public/include/classes/tokentype.class.php b/public/include/classes/tokentype.class.php index 8befe7f0..c35dd84a 100644 --- a/public/include/classes/tokentype.class.php +++ b/public/include/classes/tokentype.class.php @@ -36,6 +36,18 @@ class Token_Type Extends Base { return $result->fetch_all(MYSQLI_ASSOC); 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(); diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 3aa4c274..b11e7c48 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -20,4 +20,19 @@ require_once(BASEPATH . 'include/autoloader.inc.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']); + } +} + ?> \ No newline at end of file diff --git a/tests/config.php b/tests/config.php index cbcdb1af..82f2ef67 100644 --- a/tests/config.php +++ b/tests/config.php @@ -7,4 +7,7 @@ define('BASEPATH', '/var/www/php-mpos-allbranches/php-mpos/public/'); // 0 = dist, 1 = real 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'); + ?> \ No newline at end of file diff --git a/tests/phpunit.xml b/tests/phpunit.xml index 513c0d17..5a0c3765 100644 --- a/tests/phpunit.xml +++ b/tests/phpunit.xml @@ -9,5 +9,8 @@ unit/securityregress/Security_Sessions.php + + unit/securityregress/Security_Tokens.php + \ No newline at end of file diff --git a/tests/unit/securityregress/Security_CSRFToken.php b/tests/unit/securityregress/Security_CSRFToken.php index beb01644..a3a0d7f5 100644 --- a/tests/unit/securityregress/Security_CSRFToken.php +++ b/tests/unit/securityregress/Security_CSRFToken.php @@ -14,7 +14,6 @@ class Security_CSRFToken extends PHPUnit_Framework_Testcase { $created_token = $csrftoken->getBasic($user->getCurrentIP(), 'test-token'); $test_token = $csrftoken->checkBasic($user->getCurrentIP(), 'test-token', $created_token); $this->assertTrue($test_token); - $this->assertAttributeEquals($csrftoken->valid, true); } /** diff --git a/tests/unit/securityregress/Security_Tokens.php b/tests/unit/securityregress/Security_Tokens.php new file mode 100644 index 00000000..4ff8d967 --- /dev/null +++ b/tests/unit/securityregress/Security_Tokens.php @@ -0,0 +1,25 @@ +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)); + } + } +} + +?> \ No newline at end of file