Browse files

Added Unit Tests

  • Loading branch information...
1 parent 08290ff commit 4655262aa30d89daaa77f06f2d021a76c9c0e4c0 @baldurrensch baldurrensch committed Aug 31, 2012
Showing with 106 additions and 6 deletions.
  1. +2 −0 .gitignore
  2. +2 −2 README.md
  3. +52 −0 Tests/BasicTest.php
  4. +14 −0 Tests/bootstrap.php
  5. +32 −0 Tests/phpunit.xml
  6. +3 −3 composer.json
  7. +1 −1 src/{Openwall → Hautelook}/Phpass/PasswordHash.php
View
2 .gitignore
@@ -0,0 +1,2 @@
+composer.lock
+vendor
View
4 README.md
@@ -15,7 +15,7 @@ Add this requirement to your `composer.json` file and run `composer.phar install
{
"require": {
- "openwall/phpass": "dev-master"
+ "hautelook/phpass": "dev-master"
}
}
@@ -28,7 +28,7 @@ The following example shows how to hash a password (to then store the hash in th
namespace Your\Namespace;
-use Openwall\Phpass\PasswordHash;
+use Hautelook\Phpass\PasswordHash;
require_once(__DIR__ . "/vendor/autoload.php");
View
52 Tests/BasicTest.php
@@ -0,0 +1,52 @@
+<?php
+
+// namespace Hautelook\Phpass\Tests;
+
+use Hautelook\Phpass\PasswordHash;
+
+/**
+ *
+ */
+class BasicTest extends \PHPUnit_Framework_TestCase
+{
+ const PORTABLE_HASH = '$P$9IQRaTwmfeRo7ud9Fh4E2PdI0S3r.L0';
+ public function testCorrectHash()
+ {
+ $hasher = new PasswordHash(8,false);
+ $correct = 'test12345';
+ $hash = $hasher->HashPassword($correct);
+
+ $this->assertTrue($hasher->CheckPassword($correct, $hash));
+ }
+
+ public function testIncorrectHash()
+ {
+ $hasher = new PasswordHash(8,false);
+ $correct = 'test12345';
+ $hash = $hasher->HashPassword($correct);
+ $wrong = 'test12346';
+
+ $this->assertFalse($hasher->CheckPassword($wrong, $hash));
+ }
+
+ public function testWeakHashes()
+ {
+ $hasher = new PasswordHash(8, true);
+ $correct = 'test12345';
+ $hash = $hasher->HashPassword($correct);
+ $wrong = 'test12346';
+
+ $this->assertTrue($hasher->CheckPassword($correct, $hash));
+ $this->assertFalse($hasher->CheckPassword($wrong, $hash));
+ }
+
+ public function testPortableHashes()
+ {
+ $hasher = new PasswordHash(8, true);
+ $correct = 'test12345';
+ $wrong = 'test12346';
+
+ $this->assertTrue($hasher->CheckPassword($correct, self::PORTABLE_HASH));
+ $this->assertFalse($hasher->CheckPassword($wrong, self::PORTABLE_HASH));
+ }
+}
View
14 Tests/bootstrap.php
@@ -0,0 +1,14 @@
+<?php
+
+function includeIfExists($file)
+{
+ if (file_exists($file)) {
+ return include $file;
+ }
+}
+
+if ((!$loader = includeIfExists(__DIR__.'/../vendor/autoload.php'))) {
+ die('You must set up the project dependencies, run the following commands:'.PHP_EOL.
+ 'curl -s http://getcomposer.org/installer | php'.PHP_EOL.
+ 'php composer.phar install'.PHP_EOL);
+}
View
32 Tests/phpunit.xml
@@ -0,0 +1,32 @@
+<phpunit bootstrap="./bootstrap.php"
+ colors="true"
+ convertErrorsToExceptions="true"
+ convertNoticesToExceptions="true"
+ convertWarningsToExceptions="true"
+ stopOnFailure="false"
+ syntaxCheck="true" >
+
+ <logging>
+ <!-- <log type="coverage-text" target="php://stdout"/> -->
+ <!--showUncoveredFiles="true"/>-->
+ <!--<log type="coverage-html" target="/tmp/report" charset="UTF-8"-->
+ <!--yui="true" highlight="false"-->
+ <!--lowUpperBound="35" highLowerBound="70"/>-->
+ <!--<log type="testdox-html" target="/tmp/testdox.html"/>-->
+ </logging>
+ <testsuite name="Phpass Test Suite">
+ <directory>.</directory>
+ </testsuite>
+ <filter>
+ <blacklist>
+ <directory suffix=".php">../</directory>
+ </blacklist>
+ <whitelist>
+ <directory suffix=".php">../src/Hautelook</directory>
+ <exclude>
+ <directory suffix=".phtml">../</directory>
+ <file>./bootstrap.php</file>
+ </exclude>
+ </whitelist>
+ </filter>
+</phpunit>
View
6 composer.json
@@ -1,9 +1,9 @@
{
- "name": "openwall/phpass",
+ "name": "hautelook/phpass",
"type": "library",
"version": "0.3.0",
"time" : "2012-08-31",
- "license" : "Apache2",
+ "license" : "Public Domain",
"description": "Portable PHP password hashing framework",
"keywords": ["Blowfish", "crypt", "password", "security"],
"homepage": "https://github.com/zircote/Hal/",
@@ -18,6 +18,6 @@
"php": ">=5.3.3"
},
"autoload": {
- "psr-0": {"Openwall": "src/"}
+ "psr-0": {"Hautelook": "src/"}
}
}
View
2 src/Openwall/Phpass/PasswordHash.php → src/Hautelook/Phpass/PasswordHash.php
@@ -1,6 +1,6 @@
<?php
-namespace Openwall\Phpass;
+namespace Hautelook\Phpass;
/**
*

0 comments on commit 4655262

Please sign in to comment.