KeyValidatorTest.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. declare(strict_types=1);
  7. namespace Magento\Framework\Encryption\Test\Unit;
  8. use Magento\Framework\Encryption\KeyValidator;
  9. use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
  10. class KeyValidatorTest extends \PHPUnit\Framework\TestCase
  11. {
  12. /**
  13. * @var KeyValidator
  14. */
  15. private $keyValidator;
  16. protected function setUp()
  17. {
  18. $this->keyValidator = (new ObjectManager($this))->getObject(KeyValidator::class);
  19. }
  20. /**
  21. * @param $key
  22. * @param bool $expected
  23. * @dataProvider isValidDataProvider
  24. */
  25. public function testIsValid($key, $expected = true)
  26. {
  27. $this->assertEquals($expected, $this->keyValidator->isValid($key));
  28. }
  29. public function isValidDataProvider() : array
  30. {
  31. return [
  32. '32 numbers' => ['12345678901234567890123456789012'],
  33. '32 characters' => ['aBcdeFghIJKLMNOPQRSTUvwxYzabcdef'],
  34. '32 special characters' => ['!@#$%^&*()_+~`:;"<>,.?/|*&^%$#@!'],
  35. '32 combination' =>['1234eFghI1234567^&*(890123456789'],
  36. 'empty string' => ['', false],
  37. 'leading space' => [' 1234567890123456789012345678901', false],
  38. 'tailing space' => ['1234567890123456789012345678901 ', false],
  39. 'space in the middle' => ['12345678901 23456789012345678901', false],
  40. 'tab in the middle' => ['12345678901 23456789012345678', false],
  41. 'return in the middle' => ['12345678901
  42. 23456789012345678901', false],
  43. '31 characters' => ['1234567890123456789012345678901', false],
  44. '33 characters' => ['123456789012345678901234567890123', false],
  45. ];
  46. }
  47. }