PageRenderTime 40ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/core/src/test/php/net/xp_framework/unittest/security/MD5UnixCryptTest.class.php

http://github.com/xp-framework/xp-framework
PHP | 56 lines | 30 code | 8 blank | 18 comment | 0 complexity | b8179552d1ca120d8a92a87d3f6918d6 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php namespace net\xp_framework\unittest\security;
  2. /**
  3. * TestCase
  4. *
  5. * @see xp://security.crypto.UnixCrypt
  6. * @see https://bugs.php.net/bug.php?id=55439
  7. * @see http://stackoverflow.com/questions/5258860/php-crypt-returning-wrong-answer
  8. */
  9. class MD5UnixCryptTest extends UnixCryptTest {
  10. /**
  11. * Returns fixture
  12. *
  13. * @return security.crypto.CryptImpl
  14. */
  15. protected function fixture() {
  16. return \security\crypto\UnixCrypt::$MD5;
  17. }
  18. #[@test]
  19. public function md5PhpNetExample() {
  20. $this->assertCryptedMatches('$1$rasmusle$', '$1$rasmusle$rISCgZzpwk3UhDidwXvin0', 'rasmuslerdorf');
  21. }
  22. #[@test]
  23. public function md5SaltTooLong() {
  24. $this->assertCryptedMatches('$1$0123456789AB', '$1$01234567$CEE8q9mw43U6PHo8uPcOW/');
  25. }
  26. #[@test]
  27. public function md5SaltTooShort() {
  28. $this->assertCryptedMatches('$1$_', '$1$_$.m3t.Z4nwsU9NHyuqbRAC1');
  29. }
  30. #[@test]
  31. public function md5SaltDoesNotEndWithDollar() {
  32. $this->assertCryptedMatches('$1$01234567_', '$1$01234567$CEE8q9mw43U6PHo8uPcOW/');
  33. }
  34. #[@test]
  35. public function phpBug55439() {
  36. $this->assertEquals(
  37. '$1$U7AjYB.O$L1N7ux7twaMIMw0En8UUR1',
  38. $this->fixture()->crypt('password', '$1$U7AjYB.O$')
  39. );
  40. }
  41. #[@test]
  42. public function incorrectBehaviourInWindowsPHP() {
  43. $this->assertEquals(
  44. '$1$ad000000$8tTFeywywdEQrAl9QzV.M1',
  45. $this->fixture()->crypt('hello world', '$1$ad0000000')
  46. );
  47. }
  48. }