Skip to content

Commit 32a4c56

Browse files
committed
MQE-1070: Hide Sensitive Creds in Allure Report
- CR/QA review feedback - Fix merge conflicts
1 parent fa2dd3f commit 32a4c56

File tree

7 files changed

+85
-17
lines changed

7 files changed

+85
-17
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace tests\unit\Magento\FunctionalTestFramework\DataGenerator\Handlers;
8+
9+
use Magento\FunctionalTestingFramework\DataGenerator\Handlers\CredentialStore;
10+
use Magento\FunctionalTestingFramework\Util\MagentoTestCase;
11+
use AspectMock\Test as AspectMock;
12+
13+
class CredentialStoreTest extends MagentoTestCase
14+
{
15+
16+
/**
17+
* Test basic encryption/decryption functionality in CredentialStore class.
18+
*/
19+
public function testBasicEncryptDecrypt()
20+
{
21+
$testKey = 'myKey';
22+
$testValue = 'myValue';
23+
24+
AspectMock::double(CredentialStore::class, [
25+
'readInCredentialsFile' => ["$testKey=$testValue"]
26+
]);
27+
28+
$encryptedCred = CredentialStore::getInstance()->getSecret($testKey);
29+
30+
// assert the value we've gotten is in fact not identical to our test value
31+
$this->assertNotEquals($testValue, $encryptedCred);
32+
33+
$actualValue = CredentialStore::getInstance()->decryptSecretValue($encryptedCred);
34+
35+
// assert that we are able to successfully decrypt our secret value
36+
$this->assertEquals($testValue, $actualValue);
37+
}
38+
}

src/Magento/FunctionalTestingFramework/Config/Reader/MftfFilesystem.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ public function readFiles($fileList)
4848
}
4949
}
5050
$exceptionCollector->throwException();
51-
$this->validateSchema($configMerger, $fileList->getFilename());
51+
if ($fileList->valid()) {
52+
$this->validateSchema($configMerger, $fileList->getFilename());
53+
}
5254

5355
$output = [];
5456
if ($configMerger) {

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

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
class CredentialStore
1515
{
16+
const ENCRYPTION_ALGO = "AES-256-CBC";
17+
1618
/**
1719
* Singleton instance
1820
*
@@ -27,6 +29,13 @@ class CredentialStore
2729
*/
2830
private $iv = null;
2931

32+
/**
33+
* Key for open_ssl encryption/decryption
34+
*
35+
* @var string
36+
*/
37+
private $encodedKey = null;
38+
3039
/**
3140
* Key/Value paris of credential names and their corresponding values
3241
*
@@ -53,8 +62,10 @@ public static function getInstance()
5362
*/
5463
private function __construct()
5564
{
56-
$this->readInCredentialsFile();
57-
$this->encryptionKey = openssl_random_pseudo_bytes(16);
65+
$this->encodedKey = base64_encode(openssl_random_pseudo_bytes(16));
66+
$this->iv = substr(hash('sha256', $this->encodedKey), 0, 16);
67+
$creds = $this->readInCredentialsFile();
68+
$this->credentials = $this->encryptCredFileContents($creds);
5869
}
5970

6071
/**
@@ -85,7 +96,7 @@ public function getSecret($key)
8596
/**
8697
* Private function which reads in secret key/values from .credentials file and stores in memory as key/value pair.
8798
*
88-
* @return void
99+
* @return array
89100
* @throws TestFrameworkException
90101
*/
91102
private function readInCredentialsFile()
@@ -103,17 +114,36 @@ private function readInCredentialsFile()
103114
);
104115
}
105116

106-
$credContents = file($credsFilePath, FILE_IGNORE_NEW_LINES);
117+
return file($credsFilePath, FILE_IGNORE_NEW_LINES);
118+
}
119+
120+
/**
121+
* Function which takes the contents of the credentials file and encrypts the entries.
122+
*
123+
* @param array $credContents
124+
* @return array
125+
*/
126+
private function encryptCredFileContents($credContents)
127+
{
128+
$encryptedCreds = [];
107129
foreach ($credContents as $credValue) {
108130
if (substr($credValue, 0, 1) === '#' || empty($credValue)) {
109131
continue;
110132
}
111133

112134
list($key, $value) = explode("=", $credValue);
113135
if (!empty($value)) {
114-
$this->credentials[$key] = openssl_encrypt($value, "AES-128-ECB", 0, $this->iv);
136+
$encryptedCreds[$key] = openssl_encrypt(
137+
$value,
138+
self::ENCRYPTION_ALGO,
139+
$this->encodedKey,
140+
0,
141+
$this->iv
142+
);
115143
}
116144
}
145+
146+
return $encryptedCreds;
117147
}
118148

119149
/**
@@ -124,6 +154,6 @@ private function readInCredentialsFile()
124154
*/
125155
public function decryptSecretValue($value)
126156
{
127-
return openssl_decrypt($value, "AES-128-ECB", 0, $this->iv);
157+
return openssl_decrypt($value, self::ENCRYPTION_ALGO, $this->encodedKey, 0, $this->iv);
128158
}
129159
}

src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ class MagentoWebDriver extends WebDriver
5656
'//div[@data-role="spinner"]'
5757
];
5858

59-
const STEP_OBJ_BACKTRACE_POS = 2;
60-
6159
/**
6260
* The module required fields, to be set in the suite .yml configuration file.
6361
*
@@ -594,8 +592,12 @@ public function dragAndDrop($source, $target, $xOffset = null, $yOffset = null)
594592
}
595593

596594
/**
597-
* @param $field
598-
* @param $value
595+
* Function used to fill sensitive crednetials with user data, data is decrypted immediately prior to fill to avoid
596+
* exposure in console or log.
597+
*
598+
* @param string $field
599+
* @param string $value
600+
* @return void
599601
*/
600602
public function fillSecretField($field, $value)
601603
{

src/Magento/FunctionalTestingFramework/Test/Util/ActionMergeUtil.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ private function resolveSecretFieldAccess($resolvedActions)
126126
* Returns a boolean based on whether or not the action attributes contain a reference to a secret field.
127127
*
128128
* @param array $actionAttributes
129-
* @return bool
129+
* @return boolean
130130
*/
131131
private function actionAttributeContainsSecretRef($actionAttributes)
132132
{

src/Magento/FunctionalTestingFramework/Test/Util/ActionObjectExtractor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ private function processLinkedActions($actionName, $actionData)
141141
* defined in the action group xml.
142142
*
143143
* @param string $actionType
144-
* @param array $actionAttributeData
144+
* @param array $actionAttributeData
145145
* @return array
146146
*/
147147
private function processActionGroupArgs($actionType, $actionAttributeData)

src/Magento/FunctionalTestingFramework/Util/Iterator/File.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@ public function __construct(array $paths)
3737
*/
3838
public function getFilename()
3939
{
40-
if ($this->current == null) {
41-
return null;
42-
}
43-
4440
return $this->data[$this->key()];
4541
}
4642

0 commit comments

Comments
 (0)