Skip to content

Commit 6d5d312

Browse files
authored
Merge pull request #142 from magento-gl/MQE-3092
MQE-3092 throw error message if key value pair is not mapped properly in .credentials file
2 parents 49670c1 + b67a169 commit 6d5d312

File tree

2 files changed

+39
-3
lines changed
  • dev/tests/unit/Magento/FunctionalTestFramework/DataGenerator/Handlers/SecretStorage
  • src/Magento/FunctionalTestingFramework/DataGenerator/Handlers/SecretStorage

2 files changed

+39
-3
lines changed

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

+33-2
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,30 @@
88
namespace tests\unit\Magento\FunctionalTestFramework\DataGenerator\Handlers\SecretStorage;
99

1010
use Magento\FunctionalTestingFramework\DataGenerator\Handlers\SecretStorage\FileStorage;
11+
use Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException;
1112
use ReflectionClass;
13+
use ReflectionException;
1214
use tests\unit\Util\MagentoTestCase;
1315

1416
class FileStorageTest extends MagentoTestCase
1517
{
1618
/**
1719
* Test basic encryption/decryption functionality in FileStorage class.
20+
* @throws TestFrameworkException|ReflectionException
1821
*/
1922
public function testBasicEncryptDecrypt(): void
2023
{
2124
$testKey = 'magento/myKey';
2225
$testValue = 'myValue';
23-
$creds = ["$testKey=$testValue"];
26+
$cred = ["$testKey=$testValue"];
2427

2528
$fileStorage = new FileStorage();
2629
$reflection = new ReflectionClass(FileStorage::class);
2730

2831
// Emulate initialize() function result with the test credentials
2932
$reflectionMethod = $reflection->getMethod('encryptCredFileContents');
3033
$reflectionMethod->setAccessible(true);
31-
$secretData = $reflectionMethod->invokeArgs($fileStorage, [$creds]);
34+
$secretData = $reflectionMethod->invokeArgs($fileStorage, [$cred]);
3235

3336
// Set encrypted test credentials to the private 'secretData' property
3437
$reflectionProperty = $reflection->getProperty('secretData');
@@ -45,4 +48,32 @@ public function testBasicEncryptDecrypt(): void
4548
// assert that we are able to successfully decrypt our secret value
4649
$this->assertEquals($testValue, $actualValue);
4750
}
51+
52+
/**
53+
* Test empty value encryption/decryption functionality in FileStorage class.
54+
* @return void
55+
* @throws TestFrameworkException|ReflectionException
56+
*/
57+
public function testEmptyValueEncryptDecrypt(): void
58+
{
59+
$this->expectException(TestFrameworkException::class);
60+
61+
$testKey = 'magento/myKey';
62+
$cred = ["$testKey"];
63+
64+
$fileStorage = new FileStorage();
65+
$reflection = new ReflectionClass(FileStorage::class);
66+
67+
// Emulate initialize() function result with the test credentials
68+
$reflectionMethod = $reflection->getMethod('encryptCredFileContents');
69+
$reflectionMethod->setAccessible(true);
70+
$secretData = $reflectionMethod->invokeArgs($fileStorage, [$cred]);
71+
72+
// Set encrypted test credentials to the private 'secretData' property
73+
$reflectionProperty = $reflection->getProperty('secretData');
74+
$reflectionProperty->setAccessible(true);
75+
$reflectionProperty->setValue($fileStorage, $secretData);
76+
77+
$fileStorage->getEncryptedValue($testKey);
78+
}
4879
}

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

+6-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
namespace Magento\FunctionalTestingFramework\DataGenerator\Handlers\SecretStorage;
88

9-
use Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException;
109
use Magento\FunctionalTestingFramework\Config\MftfApplicationConfig;
10+
use Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException;
1111
use Magento\FunctionalTestingFramework\Util\Logger\LoggingUtil;
1212
use Magento\FunctionalTestingFramework\Util\Path\FilePathFormatter;
1313

@@ -93,13 +93,18 @@ private function readInCredentialsFile()
9393
*
9494
* @param array $credContents
9595
* @return array
96+
* @throws TestFrameworkException
9697
*/
9798
private function encryptCredFileContents($credContents)
9899
{
99100
$encryptedCreds = [];
100101
foreach ($credContents as $credValue) {
101102
if (substr($credValue, 0, 1) === '#' || empty($credValue)) {
102103
continue;
104+
} elseif (strpos($credValue, "=") === false) {
105+
throw new TestFrameworkException(
106+
$credValue . " not configured correctly in .credentials file"
107+
);
103108
}
104109

105110
list($key, $value) = explode("=", $credValue, 2);

0 commit comments

Comments
 (0)