Skip to content

Commit

Permalink
Merge pull request #3736 from magento-chaika/chaika_february
Browse files Browse the repository at this point in the history
chaika_february
  • Loading branch information
Lysenko Olexandr authored Feb 13, 2019
2 parents f211371 + 5b3afb5 commit 2f77c8f
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 58 deletions.
6 changes: 5 additions & 1 deletion app/code/Magento/Catalog/Block/Product/View/Attributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
use Magento\Framework\Pricing\PriceCurrencyInterface;

/**
* Attributes attributes block
*
* @api
* @since 100.0.2
*/
Expand Down Expand Up @@ -56,6 +58,8 @@ public function __construct(
}

/**
* Returns a Product
*
* @return Product
*/
public function getProduct()
Expand Down Expand Up @@ -88,7 +92,7 @@ public function getAdditionalData(array $excludeAttr = [])
$value = $this->priceCurrency->convertAndFormat($value);
}

if (is_string($value) && strlen($value)) {
if (is_string($value) && strlen(trim($value))) {
$data[$attribute->getAttributeCode()] = [
'label' => __($attribute->getStoreLabel()),
'value' => $value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function render(\Magento\Framework\Data\Form\Element\AbstractElement $ele

$regionId = $element->getForm()->getElement('region_id')->getValue();

$html = '<div class="field field-state required admin__field _required">';
$html = '<div class="field field-state admin__field">';
$element->setClass('input-text admin__control-text');
$element->setRequired(true);
$html .= $element->getLabelHtml() . '<div class="control admin__field-control">';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public function __construct(
*
* @param string $data
* @return string string
* @throws \SodiumException
*/
public function encrypt(string $data): string
{
Expand All @@ -58,13 +59,17 @@ public function decrypt(string $data): string
$nonce = mb_substr($data, 0, SODIUM_CRYPTO_AEAD_CHACHA20POLY1305_IETF_NPUBBYTES, '8bit');
$payload = mb_substr($data, SODIUM_CRYPTO_AEAD_CHACHA20POLY1305_IETF_NPUBBYTES, null, '8bit');

$plainText = sodium_crypto_aead_chacha20poly1305_ietf_decrypt(
$payload,
$nonce,
$nonce,
$this->key
);
try {
$plainText = sodium_crypto_aead_chacha20poly1305_ietf_decrypt(
$payload,
$nonce,
$nonce,
$this->key
);
} catch (\SodiumException $e) {
$plainText = '';
}

return $plainText;
return $plainText !== false ? $plainText : '';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@
*/
namespace Magento\Framework\Encryption\Test\Unit\Adapter;

class SodiumChachaIetfTest extends \PHPUnit\Framework\TestCase
use Magento\Framework\Encryption\Adapter\SodiumChachaIetf;
use PHPUnit\Framework\TestCase;

class SodiumChachaIetfTest extends TestCase
{
/**
* @return array
*/
public function getCryptData(): array
{
$fixturesFilename = __DIR__ . '/../Crypt/_files/_sodium_chachaieft_fixtures.php';

$result = include $fixturesFilename;
$result = include __DIR__ . '/../Crypt/_files/_sodium_chachaieft_fixtures.php';
/* Restore encoded string back to binary */
foreach ($result as &$cryptParams) {
$cryptParams['encrypted'] = base64_decode($cryptParams['encrypted']);
Expand All @@ -29,21 +33,30 @@ public function getCryptData(): array

/**
* @dataProvider getCryptData
*
* @param string $key
* @param string $encrypted
* @param string $decrypted
* @throws \SodiumException
*/
public function testEncrypt(string $key, string $encrypted, string $decrypted)
public function testEncrypt(string $key, string $encrypted, string $decrypted): void
{
$crypt = new \Magento\Framework\Encryption\Adapter\SodiumChachaIetf($key);
$crypt = new SodiumChachaIetf($key);
$result = $crypt->encrypt($decrypted);

$this->assertNotEquals($encrypted, $result);
}

/**
* @dataProvider getCryptData
*
* @param string $key
* @param string $encrypted
* @param string $decrypted
*/
public function testDecrypt(string $key, string $encrypted, string $decrypted)
public function testDecrypt(string $key, string $encrypted, string $decrypted): void
{
$crypt = new \Magento\Framework\Encryption\Adapter\SodiumChachaIetf($key);
$crypt = new SodiumChachaIetf($key);
$result = $crypt->decrypt($encrypted);

$this->assertEquals($decrypted, $result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,14 @@
'encrypted' => 'UglO9dEgslFpwPwejJmrK89PmBicv+I1pfdaXaEI69IrETD8LpdzOLF7',
'decrypted' => 'Hello World!!!',
],
5 => [
'key' => '6wRADHwwCBGgdxbcHhovGB0upmg0mbsN',
'encrypted' => '',
'decrypted' => '',
],
6 => [
'key' => '6wRADHwwCBGgdxbcHhovGB0upmg0mbsN',
'encrypted' => 'bWFsZm9ybWVkLWlucHV0',
'decrypted' => '',
],
];
Loading

0 comments on commit 2f77c8f

Please sign in to comment.