SodiumChachaIetfTest.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. declare(strict_types=1);
  7. /**
  8. * Test case for \Magento\Framework\Encryption\Adapter\SodiumChachaIetf
  9. */
  10. namespace Magento\Framework\Encryption\Test\Unit\Adapter;
  11. class SodiumChachaIetfTest extends \PHPUnit\Framework\TestCase
  12. {
  13. public function getCryptData(): array
  14. {
  15. $fixturesFilename = __DIR__ . '/../Crypt/_files/_sodium_chachaieft_fixtures.php';
  16. $result = include $fixturesFilename;
  17. /* Restore encoded string back to binary */
  18. foreach ($result as &$cryptParams) {
  19. $cryptParams['encrypted'] = base64_decode($cryptParams['encrypted']);
  20. }
  21. unset($cryptParams);
  22. return $result;
  23. }
  24. /**
  25. * @dataProvider getCryptData
  26. */
  27. public function testEncrypt(string $key, string $encrypted, string $decrypted)
  28. {
  29. $crypt = new \Magento\Framework\Encryption\Adapter\SodiumChachaIetf($key);
  30. $result = $crypt->encrypt($decrypted);
  31. $this->assertNotEquals($encrypted, $result);
  32. }
  33. /**
  34. * @dataProvider getCryptData
  35. */
  36. public function testDecrypt(string $key, string $encrypted, string $decrypted)
  37. {
  38. $crypt = new \Magento\Framework\Encryption\Adapter\SodiumChachaIetf($key);
  39. $result = $crypt->decrypt($encrypted);
  40. $this->assertEquals($decrypted, $result);
  41. }
  42. }