hash_pbkdf2_error.phpt 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. --TEST--
  2. Test hash_pbkdf2() function : error functionality
  3. --SKIPIF--
  4. <?php extension_loaded('hash') or die('skip: hash extension not loaded.'); ?>
  5. --FILE--
  6. <?php
  7. /* {{{ proto string hash_pbkdf2(string algo, string password, string salt, int iterations [, int length = 0, bool raw_output = false])
  8. Generate a PBKDF2 hash of the given password and salt
  9. Returns lowercase hexbits by default */
  10. echo "*** Testing hash_pbkdf2() : error conditions ***\n";
  11. $password = 'password';
  12. $salt = 'salt';
  13. echo "\n-- Testing hash_pbkdf2() function with less than expected no. of arguments --\n";
  14. var_dump(@hash_pbkdf2());
  15. echo $php_errormsg . "\n";
  16. var_dump(@hash_pbkdf2('crc32'));
  17. echo $php_errormsg . "\n";
  18. var_dump(@hash_pbkdf2('crc32', $password));
  19. echo $php_errormsg . "\n";
  20. var_dump(@hash_pbkdf2('crc32', $password, $salt));
  21. echo $php_errormsg . "\n";
  22. echo "\n-- Testing hash_pbkdf2() function with more than expected no. of arguments --\n";
  23. var_dump(@hash_pbkdf2('crc32', $password, $salt, 10, 10, true, 'extra arg'));
  24. echo $php_errormsg . "\n";
  25. echo "\n-- Testing hash_pbkdf2() function with invalid hash algorithm --\n";
  26. var_dump(@hash_pbkdf2('foo', $password, $salt, 1));
  27. echo $php_errormsg . "\n";
  28. echo "\n-- Testing hash_pbkdf2() function with invalid iterations --\n";
  29. var_dump(@hash_pbkdf2('md5', $password, $salt, 0));
  30. echo $php_errormsg . "\n";
  31. var_dump(@hash_pbkdf2('md5', $password, $salt, -1));
  32. echo $php_errormsg . "\n";
  33. echo "\n-- Testing hash_pbkdf2() function with invalid length --\n";
  34. var_dump(@hash_pbkdf2('md5', $password, $salt, 1, -1));
  35. echo $php_errormsg . "\n\n";
  36. ?>
  37. ===Done===
  38. --EXPECT--
  39. *** Testing hash_pbkdf2() : error conditions ***
  40. -- Testing hash_pbkdf2() function with less than expected no. of arguments --
  41. NULL
  42. hash_pbkdf2() expects at least 4 parameters, 0 given
  43. NULL
  44. hash_pbkdf2() expects at least 4 parameters, 1 given
  45. NULL
  46. hash_pbkdf2() expects at least 4 parameters, 2 given
  47. NULL
  48. hash_pbkdf2() expects at least 4 parameters, 3 given
  49. -- Testing hash_pbkdf2() function with more than expected no. of arguments --
  50. NULL
  51. hash_pbkdf2() expects at most 6 parameters, 7 given
  52. -- Testing hash_pbkdf2() function with invalid hash algorithm --
  53. bool(false)
  54. hash_pbkdf2(): Unknown hashing algorithm: foo
  55. -- Testing hash_pbkdf2() function with invalid iterations --
  56. bool(false)
  57. hash_pbkdf2(): Iterations must be a positive integer: 0
  58. bool(false)
  59. hash_pbkdf2(): Iterations must be a positive integer: -1
  60. -- Testing hash_pbkdf2() function with invalid length --
  61. bool(false)
  62. hash_pbkdf2(): Length must be greater than or equal to 0: -1
  63. ===Done===