Skip to content

Commit 903a04a

Browse files
committed
MQE-1070: Hide Sensitive Creds in Allure Report
- encrypt creds for display and decrypt on execution
1 parent 642e02a commit 903a04a

File tree

3 files changed

+71
-8
lines changed

3 files changed

+71
-8
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
public function testBasicEncryptDecrypt()
17+
{
18+
$testKey = 'myKey';
19+
$testValue = 'myValue';
20+
21+
AspectMock::double(CredentialStore::class, [
22+
'readInCredentialsFile' => ["$testKey=$testValue"]
23+
]);
24+
25+
$encryptedCred = CredentialStore::getInstance()->getSecret($testKey);
26+
27+
// assert the value we've gotten is in fact not identical to our test value
28+
$this->assertNotEquals($testValue, $encryptedCred);
29+
30+
$actualValue = CredentialStore::getInstance()->decryptSecretValue($encryptedCred);
31+
32+
// assert that we are able to successfully decrypt our secret value
33+
$this->assertEquals($testValue, $actualValue);
34+
}
35+
}

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: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ class MagentoWebDriver extends WebDriver
5252
'//div[@data-role="spinner"]'
5353
];
5454

55-
const STEP_OBJ_BACKTRACE_POS = 2;
56-
5755
/**
5856
* The module required fields, to be set in the suite .yml configuration file.
5957
*

0 commit comments

Comments
 (0)