Skip to content

Commit

Permalink
Add unicode character to the tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
defuse committed Feb 10, 2016
1 parent 60fd5a8 commit 82095a0
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 8 deletions.
16 changes: 14 additions & 2 deletions tests/CSharpAndPHPCompatibility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,13 @@ private static void testPHPHashes()
// Good password.
CommandExecResult goodHashExecution = RunCommand("php", "tests/phpHashMaker.php");
testData = goodHashExecution.stdOut.Split(useDelimiter);
if (PasswordStorage.VerifyPassword(testData[0], testData[1]))

if (testData[1].Length != Int32.Parse(testData[0])) {
Console.WriteLine("Unicode test is invalid.");
System.Environment.Exit(1);
}

if (PasswordStorage.VerifyPassword(testData[1], testData[2]))
{
Console.WriteLine("PHP hash validating in C#: pass");
}
Expand All @@ -70,7 +76,13 @@ private static void testPHPHashes()
// Bad password.
CommandExecResult badHashExecution = RunCommand("php", "tests/phpHashMaker.php");
testData = badHashExecution.stdOut.Split(useDelimiter);
if (PasswordStorage.VerifyPassword("wrongPassword", testData[1]))

if (testData[1].Length != Int32.Parse(testData[0])) {
Console.WriteLine("Unicode test is invalid.");
System.Environment.Exit(1);
}

if (PasswordStorage.VerifyPassword("wrongPassword", testData[2]))
{
Console.WriteLine("The C# implementation accepts BAD PHP hashes: FAIL");
System.Environment.Exit(1);
Expand Down
10 changes: 8 additions & 2 deletions tests/JavaAndPHPCompatibility.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,14 @@ private static PasswordHashPair getPHPHash()

String[] testData = s.split(" ");
PasswordHashPair pair = new PasswordHashPair();
pair.password = testData[0];
pair.hash = testData[1];
pair.password = testData[1];
pair.hash = testData[2];

if (testData[1].length() != Integer.parseInt(testData[0])) {
System.out.println("Unicode test is invalid.");
System.exit(1);
}

return pair;
}
}
7 changes: 5 additions & 2 deletions tests/phpHashMaker.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
*/
require_once 'PasswordStorage.php';

$testPassword = "this_is_a_test_password";
echo $testPassword . " " . PasswordStorage::create_hash($testPassword) . "\n";
// At the end is "WHITE SMILING FACE", in UTF-8, which fits into a single UTF-16
// character, allowing implementations to compare against the length.
$testPassword = "password\xE2\x98\xBA";
$length = mb_strlen($testPassword, 'UTF-8');
echo $length . " ". $testPassword . " " . PasswordStorage::create_hash($testPassword) . "\n";

9 changes: 7 additions & 2 deletions tests/testRubyPhpCompatibility.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,13 @@ def self.testPHPHash()
testData = `php ./tests/phpHashMaker.php`
testData = testData.split(' ')

testPw = testData[0]
testHash = testData[1]
testPw = testData[1]
testHash = testData[2]

if testPw.length != testData[0].to_i
puts "Unicode test is invalid"
exit(1)
end

if PasswordStorage.verifyPassword(testPw, testHash)
puts "PHP hash validating in Ruby: pass"
Expand Down

0 comments on commit 82095a0

Please sign in to comment.