Skip to content

Commit 3a3fcd5

Browse files
ACQE-7425: Unable to Read .credentials Values in Page Builder Module
Added more tags in the allow list to reger secret data
1 parent 201f04a commit 3a3fcd5

File tree

6 files changed

+56
-4
lines changed

6 files changed

+56
-4
lines changed

Diff for: dev/tests/unit/Magento/FunctionalTestFramework/Test/Util/ActionMergeUtilTest.php

+28-1
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ public function testInvalidSecretFunctions(): void
284284
{
285285
$this->expectException(TestReferenceException::class);
286286
$this->expectExceptionMessage(
287-
'You cannot reference secret data outside of the fillField, magentoCLI and createData actions'
287+
'You cannot reference secret data outside of the fillField, magentoCLI, seeInField and createData actions'
288288
);
289289

290290
$actionObjectOne = new ActionObject(
@@ -307,4 +307,31 @@ public static function tearDownAfterClass(): void
307307
{
308308
TestLoggingUtil::getInstance()->clearMockLoggingUtil();
309309
}
310+
311+
/**
312+
* Verify that a <seeInField> action is replaced by <seeInSecretField> when secret _CREDS are referenced.
313+
*
314+
* @return void
315+
* @throws TestReferenceException
316+
* @throws XmlException
317+
*/
318+
public function testValidSeeInSecretFieldFunction(): void
319+
{
320+
$actionObjectOne = new ActionObject(
321+
'actionKey1',
322+
'seeInField',
323+
['userInput' => '{{_CREDS.username}}', 'requiredCredentials' => 'username']
324+
);
325+
$actionObject = [$actionObjectOne];
326+
327+
$actionMergeUtil = new ActionMergeUtil('actionMergeUtilTest', 'TestCase');
328+
$result = $actionMergeUtil->resolveActionSteps($actionObject);
329+
330+
$expectedValue = new ActionObject(
331+
'actionKey1',
332+
'seeInSecretField',
333+
['userInput' => '{{_CREDS.username}}','requiredCredentials' => 'username']
334+
);
335+
$this->assertEquals($expectedValue, $result['actionKey1']);
336+
}
310337
}

Diff for: dev/tests/verification/Resources/BasicFunctionalTest.txt

+1
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ class BasicFunctionalTestCest
170170
$I->seeElementInDOM(".functionalTestSelector"); // stepKey: seeElementInDOMKey1
171171
$I->seeInCurrentUrl("/functionalUrl"); // stepKey: seeInCurrentUrlKey1
172172
$I->seeInField(".functionalTestSelector", "someInput"); // stepKey: seeInFieldKey1
173+
$I->seeInSecretField(".functionalTestSelector", $I->getSecret("someKey")); // stepKey: seeInFieldKey2
173174
$I->seeInPageSource("Home Page"); // stepKey: seeInPageSourceKey1
174175
$I->seeInPageSource("<h1 class=\"page-title\">"); // stepKey: seeInPageSourceKey2
175176
$I->seeInPopup("someInput"); // stepKey: seeInPopupKey1

Diff for: dev/tests/verification/TestModule/Test/BasicFunctionalTest/BasicFunctionalTest.xml

+1
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@
108108
<seeElementInDOM selector=".functionalTestSelector" stepKey="seeElementInDOMKey1"/>
109109
<seeInCurrentUrl url="/functionalUrl" stepKey="seeInCurrentUrlKey1"/>
110110
<seeInField selector=".functionalTestSelector" userInput="someInput" stepKey="seeInFieldKey1" />
111+
<seeInField selector=".functionalTestSelector" userInput="{{_CREDS.someKey}}" stepKey="seeInFieldKey2" />
111112
<seeInPageSource html="Home Page" stepKey="seeInPageSourceKey1"/>
112113
<seeInPageSource html="&#60;h1 class&#61;&#34;page-title&#34;&#62;" stepKey="seeInPageSourceKey2"/>
113114
<seeInPopup userInput="someInput" stepKey="seeInPopupKey1"/>

Diff for: src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php

+21
Original file line numberDiff line numberDiff line change
@@ -884,6 +884,27 @@ public function magentoCLISecret($command, $timeout = null, $arguments = null)
884884
return $this->magentoCLI($decryptedCommand, $timeout, $arguments);
885885
}
886886

887+
/**
888+
* Function used to verify sensitive credentials in the data, data is decrypted immediately prior to see to avoid
889+
* exposure in console or log.
890+
*
891+
* @param string $field
892+
* @param string $value
893+
* @return void
894+
* @throws TestFrameworkException
895+
*/
896+
public function seeInSecretField(string $field, string $value):void
897+
{
898+
// to protect any secrets from being printed to console the values are executed only at the webdriver level as a
899+
// decrypted value
900+
901+
$decryptedValue = CredentialStore::getInstance()->decryptSecretValue($value);
902+
if ($decryptedValue === false) {
903+
throw new TestFrameworkException("\nFailed to decrypt value {$value} for field {$field}\n");
904+
}
905+
$this->seeInField($field, $decryptedValue);
906+
}
907+
887908
/**
888909
* Override for _failed method in Codeception method. Adds png and html attachments to allure report
889910
* following parent execution of test failure processing.

Diff for: src/Magento/FunctionalTestingFramework/Test/Util/ActionMergeUtil.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ class ActionMergeUtil
2626
const DEFAULT_SKIP_ON_ORDER = 'before';
2727
const DEFAULT_SKIP_OFF_ORDER = 'after';
2828
const DEFAULT_WAIT_ORDER = 'after';
29-
const APPROVED_ACTIONS = ['fillField', 'magentoCLI', 'field', 'waitForElement', 'seeInField'];
30-
const SECRET_MAPPING = ['fillField' => 'fillSecretField', 'magentoCLI' => 'magentoCLISecret'];
29+
const APPROVED_ACTIONS = ['fillField', 'magentoCLI', 'field', 'seeInField'];
30+
const SECRET_MAPPING = ['fillField' => 'fillSecretField', 'magentoCLI' => 'magentoCLISecret',
31+
'seeInField' => 'seeInSecretField'];
3132
const CREDS_REGEX = "/{{_CREDS\.([\w|\/]+)}}/";
3233

3334
/**
@@ -110,7 +111,7 @@ private function resolveSecretFieldAccess($resolvedActions)
110111

111112
if ($actionHasSecretRef && !(in_array($actionType, self::APPROVED_ACTIONS))) {
112113
throw new TestReferenceException("You cannot reference secret data outside " .
113-
"of the fillField, magentoCLI and createData actions");
114+
"of the fillField, magentoCLI, seeInField and createData actions");
114115
}
115116

116117
// Do NOT remap actions that don't need it.

Diff for: src/Magento/FunctionalTestingFramework/Util/TestGenerator.php

+1
Original file line numberDiff line numberDiff line change
@@ -1343,6 +1343,7 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato
13431343
case "loadSessionSnapshot":
13441344
case "seeInField":
13451345
case "seeOptionIsSelected":
1346+
case "seeInSecretField":
13461347
$testSteps .= $this->wrapFunctionCall($actor, $actionObject, $selector, $input);
13471348
break;
13481349
case "seeInPageSource":

0 commit comments

Comments
 (0)