Skip to content

Commit 22b9185

Browse files
committed
MQE-1600: unit and static test fixes
1 parent 6ec227f commit 22b9185

File tree

6 files changed

+25
-22
lines changed

6 files changed

+25
-22
lines changed

dev/tests/unit/Magento/FunctionalTestFramework/DataGenerator/Handlers/CredentialStoreTest.php renamed to dev/tests/unit/Magento/FunctionalTestFramework/DataGenerator/Handlers/SecretStorage/FileStorageTest.php

+9-8
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,34 @@
44
* See COPYING.txt for license details.
55
*/
66

7-
namespace tests\unit\Magento\FunctionalTestFramework\DataGenerator\Handlers;
7+
namespace tests\unit\Magento\FunctionalTestFramework\DataGenerator\Handlers\SecretStorage;
88

9-
use Magento\FunctionalTestingFramework\DataGenerator\Handlers\CredentialStore;
9+
use Magento\FunctionalTestingFramework\DataGenerator\Handlers\SecretStorage\FileStorage;
1010
use Magento\FunctionalTestingFramework\Util\MagentoTestCase;
1111
use AspectMock\Test as AspectMock;
1212

13-
class CredentialStoreTest extends MagentoTestCase
13+
class FileStorageTest extends MagentoTestCase
1414
{
1515

1616
/**
17-
* Test basic encryption/decryption functionality in CredentialStore class.
17+
* Test basic encryption/decryption functionality in FileStorage class.
1818
*/
1919
public function testBasicEncryptDecrypt()
2020
{
21-
$testKey = 'myKey';
21+
$testKey = 'magento/myKey';
2222
$testValue = 'myValue';
2323

24-
AspectMock::double(CredentialStore::class, [
24+
AspectMock::double(FileStorage::class, [
2525
'readInCredentialsFile' => ["$testKey=$testValue"]
2626
]);
2727

28-
$encryptedCred = CredentialStore::getInstance()->getSecret($testKey);
28+
$fileStorage = new FileStorage();
29+
$encryptedCred = $fileStorage->getEncryptedValue($testKey);
2930

3031
// assert the value we've gotten is in fact not identical to our test value
3132
$this->assertNotEquals($testValue, $encryptedCred);
3233

33-
$actualValue = CredentialStore::getInstance()->decryptSecretValue($encryptedCred);
34+
$actualValue = $fileStorage->getDecryptedValue($encryptedCred);
3435

3536
// assert that we are able to successfully decrypt our secret value
3637
$this->assertEquals($testValue, $actualValue);

etc/config/.env.example

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ BROWSER=chrome
3030
#MAGENTO_RESTAPI_SERVER_PORT=8080
3131
#MAGENTO_RESTAPI_SERVER_PROTOCOL=https
3232

33-
*** Uncomment and set vault base url and access token if you want to use vault to manage _CREDS secrets ***#
33+
#*** Uncomment and set vault base url and access token if you want to use vault to manage _CREDS secrets ***#
3434
#CREDENTIAL_VAULT_BASE_URL=
3535
#CREDENTIAL_VAULT_TOKEN=
3636

src/Magento/FunctionalTestingFramework/DataGenerator/Handlers/CredentialStore.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,15 @@ private function __construct()
7979
public function getSecret($key)
8080
{
8181
// Get secret data from vault storage first
82-
if (!is_null($this->credVault)) {
82+
if (null !== $this->credVault) {
8383
$value = $this->credVault->getEncryptedValue($key);
8484
if (!empty($value)) {
8585
return $value;
8686
}
8787
}
8888

8989
// Get secret data from file when not found in vault
90-
if (!is_null($this->credFile)) {
90+
if (null !== $this->credFile) {
9191
$value = $this->credFile->getEncryptedValue($key);
9292
if (!empty($value)) {
9393
return $value;
@@ -107,11 +107,11 @@ public function getSecret($key)
107107
*/
108108
public function decryptSecretValue($value)
109109
{
110-
if (!is_null($this->credVault)) {
110+
if (null !== $this->credVault) {
111111
return $this->credVault->getDecryptedValue($value);
112112
}
113113

114-
if (!is_null($this->credFile)) {
114+
if (null !== $this->credFile) {
115115
return $this->credFile->getDecryptedValue($value);
116116
}
117117
}
@@ -124,11 +124,11 @@ public function decryptSecretValue($value)
124124
*/
125125
public function decryptAllSecretsInString($string)
126126
{
127-
if (!is_null($this->credVault)) {
127+
if (null !== $this->credVault) {
128128
return $this->credVault->getAllDecryptedValues($string);
129129
}
130130

131-
if (!is_null($this->credFile)) {
131+
if (null !== $this->credFile) {
132132
return $this->credFile->getAllDecryptedValues($string);
133133
}
134134
}

src/Magento/FunctionalTestingFramework/DataGenerator/Handlers/SecretStorage/BaseStorage.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,12 @@ abstract class BaseStorage
3131
*/
3232
protected static $cachedSecretData = [];
3333

34+
/**
35+
* BaseStorage constructor
36+
*/
3437
public function __construct()
3538
{
36-
if (is_null(self::$encodedKey)) {
39+
if (null === self::$encodedKey) {
3740
self::$encodedKey = base64_encode(openssl_random_pseudo_bytes(16));
3841
self::$iv = substr(hash('sha256', self::$encodedKey), 0, 16);
3942
}

src/Magento/FunctionalTestingFramework/DataGenerator/Handlers/SecretStorage/FileStorage.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function __construct()
4141
public function getEncryptedValue($key)
4242
{
4343
// Check if secret is in cached array
44-
if (!is_null($value = parent::getEncryptedValue($key))) {
44+
if (null !== ($value = parent::getEncryptedValue($key))) {
4545
return $value;
4646
}
4747

@@ -52,7 +52,6 @@ public function getEncryptedValue($key)
5252
"retrieving secret for key name {$key} from file"
5353
);
5454
}
55-
5655
} catch (\Exception $e) {
5756
}
5857

src/Magento/FunctionalTestingFramework/DataGenerator/Handlers/SecretStorage/VaultStorage.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ class VaultStorage extends BaseStorage
5151
public function __construct($baseUrl, $token)
5252
{
5353
parent::__construct();
54-
if (is_null(self::$client)) {
54+
if (null === self::$client) {
5555
// Creating the client using Guzzle6 Transport and passing a custom url
56-
self::$client = new Client(new Guzzle6Transport(['base_url' => $baseUrl . self::BASE_PATH]));
56+
self::$client = new Client(new Guzzle6Transport(['base_url' => $baseUrl]));
5757
}
5858
$this->token = $token;
5959
if (!$this->authenticated()) {
@@ -70,7 +70,7 @@ public function __construct($baseUrl, $token)
7070
public function getEncryptedValue($key)
7171
{
7272
// Check if secret is in cached array
73-
if (!is_null($value = parent::getEncryptedValue($key))) {
73+
if (null !== ($value = parent::getEncryptedValue($key))) {
7474
return $value;
7575
}
7676

@@ -124,7 +124,7 @@ private function authenticated()
124124
if ($authenticated) {
125125
return true;
126126
}
127-
} catch (\Psr\Cache\InvalidArgumentException $e) {
127+
} catch (\Exception $e) {
128128
}
129129
return false;
130130
}

0 commit comments

Comments
 (0)