diff --git a/dev/tests/unit/Magento/FunctionalTestFramework/Test/Util/ActionMergeUtilTest.php b/dev/tests/unit/Magento/FunctionalTestFramework/Test/Util/ActionMergeUtilTest.php index 0f367c226..7917d663b 100644 --- a/dev/tests/unit/Magento/FunctionalTestFramework/Test/Util/ActionMergeUtilTest.php +++ b/dev/tests/unit/Magento/FunctionalTestFramework/Test/Util/ActionMergeUtilTest.php @@ -8,6 +8,8 @@ use AspectMock\Test as AspectMock; use Magento\FunctionalTestingFramework\DataGenerator\Handlers\DataObjectHandler; use Magento\FunctionalTestingFramework\DataGenerator\Objects\EntityDataObject; +use Magento\FunctionalTestingFramework\Exceptions\TestReferenceException; +use Magento\FunctionalTestingFramework\Exceptions\XmlException; use Magento\FunctionalTestingFramework\Test\Objects\ActionObject; use Magento\FunctionalTestingFramework\Test\Util\ActionMergeUtil; use Magento\FunctionalTestingFramework\Test\Util\ActionObjectExtractor; @@ -100,7 +102,7 @@ public function testResolveActionStepEntityData() $dataFieldName = 'myfield'; $dataFieldValue = 'myValue'; $userInputKey = "userInput"; - $userinputValue = "{{" . "${dataObjectName}.${dataFieldName}}}"; + $userInputValue = "{{" . "${dataObjectName}.${dataFieldName}}}"; $actionName = "myAction"; $actionType = "myCustomType"; @@ -113,10 +115,10 @@ public function testResolveActionStepEntityData() AspectMock::double(DataObjectHandler::class, ['getInstance' => $mockDOHInstance]); // Create test object and action object - $actionAttributes = [$userInputKey => $userinputValue]; + $actionAttributes = [$userInputKey => $userInputValue]; $actions[$actionName] = new ActionObject($actionName, $actionType, $actionAttributes); - $this->assertEquals($userinputValue, $actions[$actionName]->getCustomActionAttributes()[$userInputKey]); + $this->assertEquals($userInputValue, $actions[$actionName]->getCustomActionAttributes()[$userInputKey]); $mergeUtil = new ActionMergeUtil("test", "TestCase"); $resolvedActions = $mergeUtil->resolveActionSteps($actions); @@ -127,8 +129,14 @@ public function testResolveActionStepEntityData() /** * Verify that an XmlException is thrown when an action references a non-existant action. * + * @throws TestReferenceException + * @throws XmlException * @return void */ + /** + * @throws TestReferenceException + * @throws XmlException + */ public function testNoActionException() { $actionObjects = []; @@ -151,6 +159,8 @@ public function testNoActionException() /** * Verify that a action is added after actions that have a wait (timeout property). * + * @throws TestReferenceException + * @throws XmlException * @return void */ public function testInsertWait() @@ -173,6 +183,111 @@ public function testInsertWait() $this->assertEquals($expected, $actual); } + /** + * Verify that a action is replaced by when secret _CREDS are referenced. + * + * @throws TestReferenceException + * @throws XmlException + */ + public function testValidFillFieldSecretFunction() + { + $actionObjectOne = new ActionObject( + 'actionKey1', + 'fillField', + ['userInput' => '{{_CREDS.username}}'] + ); + $actionObject = [$actionObjectOne]; + + $actionMergeUtil = new ActionMergeUtil('actionMergeUtilTest', 'TestCase'); + + $result = $actionMergeUtil->resolveActionSteps($actionObject); + + $expectedValue = new ActionObject( + 'actionKey1', + 'fillSecretField', + ['userInput' => '{{_CREDS.username}}'] + ); + $this->assertEquals($expectedValue, $result['actionKey1']); + } + + /** + * Verify that a action uses when secret _CREDS are referenced. + * + * @throws TestReferenceException + * @throws XmlException + */ + public function testValidMagentoCLISecretFunction() + { + $actionObjectOne = new ActionObject( + 'actionKey1', + 'magentoCLI', + ['command' => 'config:set cms/wysiwyg/enabled {{_CREDS.payment_authorizenet_login}}'] + ); + $actionObject = [$actionObjectOne]; + + $actionMergeUtil = new ActionMergeUtil('actionMergeUtilTest', 'TestCase'); + + $result = $actionMergeUtil->resolveActionSteps($actionObject); + + $expectedValue = new ActionObject( + 'actionKey1', + 'magentoCLISecret', + ['command' => 'config:set cms/wysiwyg/enabled {{_CREDS.payment_authorizenet_login}}'] + ); + $this->assertEquals($expectedValue, $result['actionKey1']); + } + + /** + * Verify that a override in a action uses when secret _CREDS are referenced. + * + * @throws TestReferenceException + * @throws XmlException + */ + public function testValidCreateDataSecretFunction() + { + $actionObjectOne = new ActionObject( + 'actionKey1', + 'field', + ['value' => '{{_CREDS.payment_authorizenet_login}}'] + ); + $actionObject = [$actionObjectOne]; + + $actionMergeUtil = new ActionMergeUtil('actionMergeUtilTest', 'TestCase'); + + $result = $actionMergeUtil->resolveActionSteps($actionObject); + + $expectedValue = new ActionObject( + 'actionKey1', + 'field', + ['value' => '{{_CREDS.payment_authorizenet_login}}'] + ); + $this->assertEquals($expectedValue, $result['actionKey1']); + } + + /** + * Verify that a action throws an exception when secret _CREDS are referenced. + * + * @throws TestReferenceException + * @throws XmlException + */ + public function testInvalidSecretFunctions() + { + $this->expectException(TestReferenceException::class); + $this->expectExceptionMessage( + 'You cannot reference secret data outside of the fillField, magentoCLI and createData actions' + ); + + $actionObjectOne = new ActionObject( + 'actionKey1', + 'click', + ['userInput' => '{{_CREDS.username}}'] + ); + $actionObject = [$actionObjectOne]; + + $actionMergeUtil = new ActionMergeUtil('actionMergeUtilTest', 'TestCase'); + $actionMergeUtil->resolveActionSteps($actionObject); + } + /** * After class functionality * @return void diff --git a/dev/tests/verification/Resources/ActionGroupUsingCreateData.txt b/dev/tests/verification/Resources/ActionGroupUsingCreateData.txt index 6831b0914..97369c6ea 100644 --- a/dev/tests/verification/Resources/ActionGroupUsingCreateData.txt +++ b/dev/tests/verification/Resources/ActionGroupUsingCreateData.txt @@ -31,7 +31,7 @@ class ActionGroupUsingCreateDataCest "hook", "ApiCategory", [], - null + [] ); $I->comment("[createConfigProductKey1] create 'ApiConfigurableProduct' entity"); @@ -40,7 +40,7 @@ class ActionGroupUsingCreateDataCest "hook", "ApiConfigurableProduct", ["createCategoryKey1"], - null + [] ); $I->comment("Exiting Action Group [Key1] actionGroupWithCreateData"); diff --git a/dev/tests/verification/Resources/ActionGroupWithDataOverrideTest.txt b/dev/tests/verification/Resources/ActionGroupWithDataOverrideTest.txt index 3785b4dd6..f9984944a 100644 --- a/dev/tests/verification/Resources/ActionGroupWithDataOverrideTest.txt +++ b/dev/tests/verification/Resources/ActionGroupWithDataOverrideTest.txt @@ -31,7 +31,7 @@ class ActionGroupWithDataOverrideTestCest "hook", "ReplacementPerson", [], - null + [] ); $I->comment("Entering Action Group [beforeGroup] FunctionalActionGroup"); diff --git a/dev/tests/verification/Resources/ActionGroupWithDataTest.txt b/dev/tests/verification/Resources/ActionGroupWithDataTest.txt index 3e812cdd0..79bda5f1b 100644 --- a/dev/tests/verification/Resources/ActionGroupWithDataTest.txt +++ b/dev/tests/verification/Resources/ActionGroupWithDataTest.txt @@ -31,7 +31,7 @@ class ActionGroupWithDataTestCest "hook", "ReplacementPerson", [], - null + [] ); $I->comment("Entering Action Group [beforeGroup] FunctionalActionGroup"); diff --git a/dev/tests/verification/Resources/ActionGroupWithNoDefaultTest.txt b/dev/tests/verification/Resources/ActionGroupWithNoDefaultTest.txt index 955596301..b24362028 100644 --- a/dev/tests/verification/Resources/ActionGroupWithNoDefaultTest.txt +++ b/dev/tests/verification/Resources/ActionGroupWithNoDefaultTest.txt @@ -31,7 +31,7 @@ class ActionGroupWithNoDefaultTestCest "hook", "ReplacementPerson", [], - null + [] ); $I->comment("Entering Action Group [beforeGroup] FunctionalActionGroup"); diff --git a/dev/tests/verification/Resources/ActionGroupWithPersistedData.txt b/dev/tests/verification/Resources/ActionGroupWithPersistedData.txt index aba5c5796..f774269ea 100644 --- a/dev/tests/verification/Resources/ActionGroupWithPersistedData.txt +++ b/dev/tests/verification/Resources/ActionGroupWithPersistedData.txt @@ -31,7 +31,7 @@ class ActionGroupWithPersistedDataCest "hook", "ReplacementPerson", [], - null + [] ); $I->comment("Entering Action Group [beforeGroup] FunctionalActionGroup"); @@ -78,7 +78,7 @@ class ActionGroupWithPersistedDataCest "test", "DefaultPerson", [], - null + [] ); $I->comment("Entering Action Group [actionGroupWithPersistedData1] FunctionalActionGroupWithData"); diff --git a/dev/tests/verification/Resources/ActionGroupWithStepKeyReferences.txt b/dev/tests/verification/Resources/ActionGroupWithStepKeyReferences.txt index 336cd6610..d83447d03 100644 --- a/dev/tests/verification/Resources/ActionGroupWithStepKeyReferences.txt +++ b/dev/tests/verification/Resources/ActionGroupWithStepKeyReferences.txt @@ -34,7 +34,7 @@ class ActionGroupWithStepKeyReferencesCest "test", "simpleData", [], - null + [] ); $grabTextDataActionGroup = $I->grabTextFrom(".class"); // stepKey: grabTextDataActionGroup @@ -46,7 +46,6 @@ class ActionGroupWithStepKeyReferencesCest $action3ActionGroup = $I->executeJS($action3ActionGroup); // stepKey: action3ActionGroup $action4ActionGroup = $I->magentoCLI($action4ActionGroup, "\"stuffHere\""); // stepKey: action4ActionGroup $I->comment($action4ActionGroup); - $date = new \DateTime(); $date->setTimestamp(strtotime("{$action5}")); $date->setTimezone(new \DateTimeZone("America/Los_Angeles")); @@ -82,7 +81,7 @@ class ActionGroupWithStepKeyReferencesCest "test", "{$action10}", [], - null + [] ); $action11ActionGroup = $I->grabAttributeFrom($action11ActionGroup, "someInput"); // stepKey: action11ActionGroup diff --git a/dev/tests/verification/Resources/ActionGroupWithTopLevelPersistedData.txt b/dev/tests/verification/Resources/ActionGroupWithTopLevelPersistedData.txt index fffaebbfd..c579d165e 100644 --- a/dev/tests/verification/Resources/ActionGroupWithTopLevelPersistedData.txt +++ b/dev/tests/verification/Resources/ActionGroupWithTopLevelPersistedData.txt @@ -31,7 +31,7 @@ class ActionGroupWithTopLevelPersistedDataCest "hook", "ReplacementPerson", [], - null + [] ); $I->comment("Entering Action Group [beforeGroup] FunctionalActionGroup"); diff --git a/dev/tests/verification/Resources/ArgumentWithSameNameAsElement.txt b/dev/tests/verification/Resources/ArgumentWithSameNameAsElement.txt index 4ccc2d169..5b9f838a4 100644 --- a/dev/tests/verification/Resources/ArgumentWithSameNameAsElement.txt +++ b/dev/tests/verification/Resources/ArgumentWithSameNameAsElement.txt @@ -31,7 +31,7 @@ class ArgumentWithSameNameAsElementCest "hook", "ReplacementPerson", [], - null + [] ); $I->comment("Entering Action Group [beforeGroup] FunctionalActionGroup"); diff --git a/dev/tests/verification/Resources/AssertTest.txt b/dev/tests/verification/Resources/AssertTest.txt index 697bc3d21..1f8eef56e 100644 --- a/dev/tests/verification/Resources/AssertTest.txt +++ b/dev/tests/verification/Resources/AssertTest.txt @@ -30,7 +30,7 @@ class AssertTestCest "hook", "ReplacementPerson", [], - null + [] ); } @@ -50,7 +50,7 @@ class AssertTestCest "test", "UniquePerson", [], - null + [] ); $grabTextFrom1 = $I->grabTextFrom(".copyright>span"); // stepKey: grabTextFrom1 diff --git a/dev/tests/verification/Resources/BasicActionGroupTest.txt b/dev/tests/verification/Resources/BasicActionGroupTest.txt index 17e5e2bdf..c6b3cec81 100644 --- a/dev/tests/verification/Resources/BasicActionGroupTest.txt +++ b/dev/tests/verification/Resources/BasicActionGroupTest.txt @@ -31,7 +31,7 @@ class BasicActionGroupTestCest "hook", "ReplacementPerson", [], - null + [] ); $I->comment("Entering Action Group [beforeGroup] FunctionalActionGroup"); diff --git a/dev/tests/verification/Resources/BasicFunctionalTest.txt b/dev/tests/verification/Resources/BasicFunctionalTest.txt index 3cb373a4c..fc4284005 100644 --- a/dev/tests/verification/Resources/BasicFunctionalTest.txt +++ b/dev/tests/verification/Resources/BasicFunctionalTest.txt @@ -121,7 +121,6 @@ class BasicFunctionalTestCest $grabValueFromKey1 = $I->grabValueFrom(".functionalTestSelector"); // stepKey: grabValueFromKey1 $magentoCli1 = $I->magentoCLI("maintenance:enable", "\"stuffHere\""); // stepKey: magentoCli1 $I->comment($magentoCli1); - $I->makeScreenshot("screenShotInput"); // stepKey: makeScreenshotKey1 $I->maximizeWindow(); // stepKey: maximizeWindowKey1 $I->moveBack(); // stepKey: moveBackKey1 diff --git a/dev/tests/verification/Resources/DataActionsTest.txt b/dev/tests/verification/Resources/DataActionsTest.txt index 5d1ee9e00..728bef2e7 100644 --- a/dev/tests/verification/Resources/DataActionsTest.txt +++ b/dev/tests/verification/Resources/DataActionsTest.txt @@ -30,7 +30,7 @@ class DataActionsTestCest "hook", "entity", [], - null + [] ); $I->comment("[updateInBefore] update 'createdInBefore' entity to 'entity'"); @@ -64,7 +64,7 @@ class DataActionsTestCest "test", "entity", [], - null + [] ); $I->comment("[updateInTest] update 'createdInTest' entity to 'entity'"); diff --git a/dev/tests/verification/Resources/DataReplacementTest.txt b/dev/tests/verification/Resources/DataReplacementTest.txt index 211dfd5a1..4eb305e32 100644 --- a/dev/tests/verification/Resources/DataReplacementTest.txt +++ b/dev/tests/verification/Resources/DataReplacementTest.txt @@ -53,6 +53,5 @@ class DataReplacementTestCest $I->fillField(".selector", "0"); // stepKey: insertZero $insertCommand = $I->magentoCLI("do something Doe" . msq("uniqueData") . " with uniqueness"); // stepKey: insertCommand $I->comment($insertCommand); - } } diff --git a/dev/tests/verification/Resources/ExtendParentDataTest.txt b/dev/tests/verification/Resources/ExtendParentDataTest.txt index a80f3cf19..a91c2f464 100644 --- a/dev/tests/verification/Resources/ExtendParentDataTest.txt +++ b/dev/tests/verification/Resources/ExtendParentDataTest.txt @@ -33,7 +33,7 @@ class ExtendParentDataTestCest "test", "extendParentData", [], - null + [] ); $I->searchAndMultiSelectOption("#selector", ["otherName"]); // stepKey: getName diff --git a/dev/tests/verification/Resources/ExtendedParameterArrayTest.txt b/dev/tests/verification/Resources/ExtendedParameterArrayTest.txt index 41bea9d6f..21212ba1a 100644 --- a/dev/tests/verification/Resources/ExtendedParameterArrayTest.txt +++ b/dev/tests/verification/Resources/ExtendedParameterArrayTest.txt @@ -33,7 +33,7 @@ class ExtendParentDataTestCest "test", "extendParentData", [], - null + [] ); $I->searchAndMultiSelectOption("#selector", ["otherName"]); $I->searchAndMultiSelectOption("#selector", ["extendName"]); diff --git a/dev/tests/verification/Resources/HookActionsTest.txt b/dev/tests/verification/Resources/HookActionsTest.txt index 74a49eca3..3068e6ac1 100644 --- a/dev/tests/verification/Resources/HookActionsTest.txt +++ b/dev/tests/verification/Resources/HookActionsTest.txt @@ -30,7 +30,7 @@ class HookActionsTestCest "hook", "sampleCreatedEntity", [], - null + [] ); $I->comment("[sampleDeleteBefore] delete entity 'sampleCreateBefore'"); @@ -45,7 +45,7 @@ class HookActionsTestCest "hook", "sampleCreatedEntity", [], - null + [] ); } @@ -62,7 +62,7 @@ class HookActionsTestCest "hook", "sampleCreatedEntity", [], - null + [] ); $I->comment("[sampleDeleteAfter] delete entity 'sampleCreateForAfter'"); diff --git a/dev/tests/verification/Resources/LocatorFunctionTest.txt b/dev/tests/verification/Resources/LocatorFunctionTest.txt index 4c96f100b..ad9a1a9e7 100644 --- a/dev/tests/verification/Resources/LocatorFunctionTest.txt +++ b/dev/tests/verification/Resources/LocatorFunctionTest.txt @@ -33,7 +33,7 @@ class LocatorFunctionTestCest "test", "ReplacementPerson", [], - null + [] ); $I->click(Locator::contains("'label'", "'Name'")); // stepKey: SimpleLocator diff --git a/dev/tests/verification/Resources/MergedActionGroupTest.txt b/dev/tests/verification/Resources/MergedActionGroupTest.txt index 03ab1287b..9bd6c0ded 100644 --- a/dev/tests/verification/Resources/MergedActionGroupTest.txt +++ b/dev/tests/verification/Resources/MergedActionGroupTest.txt @@ -31,7 +31,7 @@ class MergedActionGroupTestCest "hook", "ReplacementPerson", [], - null + [] ); $I->comment("Entering Action Group [beforeGroup] FunctionalActionGroup"); diff --git a/dev/tests/verification/Resources/MultipleActionGroupsTest.txt b/dev/tests/verification/Resources/MultipleActionGroupsTest.txt index e0796ae39..4f12b2f07 100644 --- a/dev/tests/verification/Resources/MultipleActionGroupsTest.txt +++ b/dev/tests/verification/Resources/MultipleActionGroupsTest.txt @@ -31,7 +31,7 @@ class MultipleActionGroupsTestCest "hook", "ReplacementPerson", [], - null + [] ); $I->comment("Entering Action Group [beforeGroup] FunctionalActionGroup"); diff --git a/dev/tests/verification/Resources/PageReplacementTest.txt b/dev/tests/verification/Resources/PageReplacementTest.txt index 6b27b55b1..c7bede23e 100644 --- a/dev/tests/verification/Resources/PageReplacementTest.txt +++ b/dev/tests/verification/Resources/PageReplacementTest.txt @@ -33,7 +33,7 @@ class PageReplacementTestCest "test", "simpleData", [], - null + [] ); $I->amOnPage("/page.html"); // stepKey: noParamPage diff --git a/dev/tests/verification/Resources/ParameterArrayTest.txt b/dev/tests/verification/Resources/ParameterArrayTest.txt index 8f49ca05c..8e278b826 100644 --- a/dev/tests/verification/Resources/ParameterArrayTest.txt +++ b/dev/tests/verification/Resources/ParameterArrayTest.txt @@ -33,7 +33,7 @@ class ParameterArrayTestCest "test", "simpleParamData", [], - null + [] ); $I->searchAndMultiSelectOption("#selector", ["name"]); // stepKey: xmlSimpleReplace diff --git a/dev/tests/verification/Resources/PersistedReplacementTest.txt b/dev/tests/verification/Resources/PersistedReplacementTest.txt index 2c5d99bc2..6058e34f5 100644 --- a/dev/tests/verification/Resources/PersistedReplacementTest.txt +++ b/dev/tests/verification/Resources/PersistedReplacementTest.txt @@ -30,7 +30,7 @@ class PersistedReplacementTestCest "hook", "ReplacementPerson", [], - null + [] ); } @@ -50,7 +50,7 @@ class PersistedReplacementTestCest "test", "simpleData", [], - null + [] ); $I->fillField("#selector", "StringBefore " . PersistedObjectHandler::getInstance()->retrieveEntityField('createdData', 'firstname', 'test') . " StringAfter"); // stepKey: inputReplace diff --git a/dev/tests/verification/Resources/PersistenceActionGroupAppendingTest.txt b/dev/tests/verification/Resources/PersistenceActionGroupAppendingTest.txt index af6507abc..bc5e16294 100644 --- a/dev/tests/verification/Resources/PersistenceActionGroupAppendingTest.txt +++ b/dev/tests/verification/Resources/PersistenceActionGroupAppendingTest.txt @@ -31,7 +31,7 @@ class PersistenceActionGroupAppendingTestCest "hook", "entity", [], - null + [] ); $I->comment("[updateDataACTIONGROUPBEFORE] update 'createDataACTIONGROUPBEFORE' entity to 'newEntity'"); @@ -77,7 +77,7 @@ class PersistenceActionGroupAppendingTestCest "test", "entity", [], - null + [] ); $I->comment("[updateDataACTIONGROUP] update 'createDataACTIONGROUP' entity to 'newEntity'"); diff --git a/dev/tests/verification/Resources/PersistenceCustomFieldsTest.txt b/dev/tests/verification/Resources/PersistenceCustomFieldsTest.txt index 68ded6711..4853619e1 100644 --- a/dev/tests/verification/Resources/PersistenceCustomFieldsTest.txt +++ b/dev/tests/verification/Resources/PersistenceCustomFieldsTest.txt @@ -25,9 +25,7 @@ class PersistenceCustomFieldsTestCest public function _before(AcceptanceTester $I) { $createData1Fields['firstname'] = "Mac"; - $createData1Fields['lastname'] = "Doe"; - $I->comment("[createData1] create 'DefaultPerson' entity"); PersistedObjectHandler::getInstance()->createEntity( "createData1", @@ -38,7 +36,6 @@ class PersistenceCustomFieldsTestCest ); $createData2Fields['firstname'] = PersistedObjectHandler::getInstance()->retrieveEntityField('createData1', 'firstname', 'hook'); - $I->comment("[createData2] create 'uniqueData' entity"); PersistedObjectHandler::getInstance()->createEntity( "createData2", @@ -60,9 +57,7 @@ class PersistenceCustomFieldsTestCest public function PersistenceCustomFieldsTest(AcceptanceTester $I) { $createdDataFields['favoriteIndex'] = "1"; - $createdDataFields['middlename'] = "Kovacs"; - $I->comment("[createdData] create 'simpleData' entity"); PersistedObjectHandler::getInstance()->createEntity( "createdData", @@ -73,9 +68,7 @@ class PersistenceCustomFieldsTestCest ); $createdData3Fields['firstname'] = "Takeshi"; - $createdData3Fields['lastname'] = "Kovacs"; - $I->comment("[createdData3] create 'UniquePerson' entity"); PersistedObjectHandler::getInstance()->createEntity( "createdData3", @@ -87,7 +80,6 @@ class PersistenceCustomFieldsTestCest $I->comment("Entering Action Group [createdAG] PersistenceActionGroup"); $createDataAG1CreatedAGFields['firstname'] = "string1"; - $I->comment("[createDataAG1CreatedAG] create 'simpleData' entity"); PersistedObjectHandler::getInstance()->createEntity( "createDataAG1CreatedAG", @@ -98,7 +90,6 @@ class PersistenceCustomFieldsTestCest ); $createDataAG2CreatedAGFields['firstname'] = "Jane"; - $I->comment("[createDataAG2CreatedAG] create 'simpleData' entity"); PersistedObjectHandler::getInstance()->createEntity( "createDataAG2CreatedAG", @@ -109,7 +100,6 @@ class PersistenceCustomFieldsTestCest ); $createDataAG3CreatedAGFields['firstname'] = PersistedObjectHandler::getInstance()->retrieveEntityField('createdData3', 'firstname', 'test'); - $I->comment("[createDataAG3CreatedAG] create 'simpleData' entity"); PersistedObjectHandler::getInstance()->createEntity( "createDataAG3CreatedAG", diff --git a/dev/tests/verification/Resources/SectionReplacementTest.txt b/dev/tests/verification/Resources/SectionReplacementTest.txt index a237faf38..aab4a87a0 100644 --- a/dev/tests/verification/Resources/SectionReplacementTest.txt +++ b/dev/tests/verification/Resources/SectionReplacementTest.txt @@ -52,7 +52,7 @@ class SectionReplacementTestCest "test", "simpleData", [], - null + [] ); $I->click("#element ." . PersistedObjectHandler::getInstance()->retrieveEntityField('createdData', 'firstname', 'test')); // stepKey: selectorReplaceOneParamPersisted diff --git a/dev/tests/verification/TestModule/Test/SecretCredentialDataTest.xml b/dev/tests/verification/TestModule/Test/SecretCredentialDataTest.xml new file mode 100644 index 000000000..4044a86e3 --- /dev/null +++ b/dev/tests/verification/TestModule/Test/SecretCredentialDataTest.xml @@ -0,0 +1,27 @@ + + + + + + + 123 + 12.34 + + + {{_CREDS.payment_authorizenet_trans_key}} + {{_CREDS.carriers_dhl_account_eu}} + + + + + + + + + diff --git a/dev/tests/verification/Tests/SecretCredentialDataTest.php b/dev/tests/verification/Tests/SecretCredentialDataTest.php new file mode 100644 index 000000000..46391feee --- /dev/null +++ b/dev/tests/verification/Tests/SecretCredentialDataTest.php @@ -0,0 +1,75 @@ +comment("[createProductWithFieldOverridesUsingHardcodedData1] create '_defaultProduct' entity"); + PersistedObjectHandler::getInstance()->createEntity( + "createProductWithFieldOverridesUsingHardcodedData1", + "test", + "_defaultProduct", + [], + $createProductWithFieldOverridesUsingHardcodedData1Fields + ); + + $createProductWithFieldOverridesUsingSecretCredData1Fields['qty'] = + CredentialStore::getInstance()->getSecret("payment_authorizenet_trans_key"); + + $createProductWithFieldOverridesUsingSecretCredData1Fields['price'] = + CredentialStore::getInstance()->getSecret("carriers_dhl_account_eu"); + + $I->comment("[createProductWithFieldOverridesUsingSecretCredData1] create '_defaultProduct' entity"); + PersistedObjectHandler::getInstance()->createEntity( + "createProductWithFieldOverridesUsingSecretCredData1", + "test", + "_defaultProduct", + [], + $createProductWithFieldOverridesUsingSecretCredData1Fields + ); + + $I->fillField("#username", "Hardcoded"); // stepKey: fillFieldUsingHardCodedData1 + $I->fillSecretField("#username", CredentialStore::getInstance()->getSecret("carriers_dhl_id_eu")); + // stepKey: fillFieldUsingSecretCredData1 + $magentoCliUsingHardcodedData1 = $I->magentoCLI("config:set cms/wysiwyg/enabled 0"); + // stepKey: magentoCliUsingHardcodedData1 + $I->comment($magentoCliUsingHardcodedData1); + + $magentoCliUsingSecretCredData1 = $I->magentoCLI("config:set cms/wysiwyg/enabled " . + CredentialStore::getInstance()->getSecret("payment_authorizenet_login")); + // stepKey: magentoCliUsingSecretCredData1 + $I->comment($magentoCliUsingSecretCredData1); + } +} diff --git a/src/Magento/FunctionalTestingFramework/DataGenerator/Handlers/CredentialStore.php b/src/Magento/FunctionalTestingFramework/DataGenerator/Handlers/CredentialStore.php index 3f635a040..a83540683 100644 --- a/src/Magento/FunctionalTestingFramework/DataGenerator/Handlers/CredentialStore.php +++ b/src/Magento/FunctionalTestingFramework/DataGenerator/Handlers/CredentialStore.php @@ -156,4 +156,22 @@ public function decryptSecretValue($value) { return openssl_decrypt($value, self::ENCRYPTION_ALGO, $this->encodedKey, 0, $this->iv); } + + /** + * Takes a string that contains encrypted data at runtime and decrypts each value. + * + * @param string $string + * @return mixed + */ + public function decryptAllSecretsInString($string) + { + $newString = $string; + foreach ($this->credentials as $name => $secretValue) { + if (strpos($newString, $secretValue) !== false) { + $decryptedValue = $this->decryptSecretValue($secretValue); + $newString = str_replace($secretValue, $decryptedValue, $newString); + } + } + return $newString; + } } diff --git a/src/Magento/FunctionalTestingFramework/DataGenerator/Handlers/PersistedObjectHandler.php b/src/Magento/FunctionalTestingFramework/DataGenerator/Handlers/PersistedObjectHandler.php index 64bb5f0a0..cc35bbc52 100644 --- a/src/Magento/FunctionalTestingFramework/DataGenerator/Handlers/PersistedObjectHandler.php +++ b/src/Magento/FunctionalTestingFramework/DataGenerator/Handlers/PersistedObjectHandler.php @@ -84,6 +84,10 @@ public function createEntity( foreach ($dependentObjectKeys as $objectKey) { $retrievedDependentObjects[] = $this->retrieveEntity($objectKey, $scope); } + + foreach ($overrideFields as $index => $field) { + $overrideFields[$index] = CredentialStore::getInstance()->decryptAllSecretsInString($field); + } $retrievedEntity = DataObjectHandler::getInstance()->getObject($entity); $persistedObject = new DataPersistenceHandler( diff --git a/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php b/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php index 93e6a5968..d268e23b4 100644 --- a/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php +++ b/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php @@ -620,7 +620,7 @@ public function dragAndDrop($source, $target, $xOffset = null, $yOffset = null) } /** - * Function used to fill sensitive crednetials with user data, data is decrypted immediately prior to fill to avoid + * Function used to fill sensitive credentials with user data, data is decrypted immediately prior to fill to avoid * exposure in console or log. * * @param string $field @@ -636,6 +636,24 @@ public function fillSecretField($field, $value) $this->fillField($field, $decryptedValue); } + /** + * Function used to create data that contains sensitive credentials in a override. + * The data is decrypted immediately prior to data creation to avoid exposure in console or log. + * + * @param string $command + * @param null $arguments + * @throws TestFrameworkException + * @return string + */ + public function magentoCLISecret($command, $arguments = null) + { + // to protect any secrets from being printed to console the values are executed only at the webdriver level as a + // decrypted value + + $decryptedCommand = CredentialStore::getInstance()->decryptAllSecretsInString($command); + return $this->magentoCLI($decryptedCommand, $arguments); + } + /** * Override for _failed method in Codeception method. Adds png and html attachments to allure report * following parent execution of test failure processing. diff --git a/src/Magento/FunctionalTestingFramework/Test/Objects/ActionObject.php b/src/Magento/FunctionalTestingFramework/Test/Objects/ActionObject.php index 19bd58721..dd7c20b18 100644 --- a/src/Magento/FunctionalTestingFramework/Test/Objects/ActionObject.php +++ b/src/Magento/FunctionalTestingFramework/Test/Objects/ActionObject.php @@ -154,7 +154,7 @@ public function __construct( $this->linkedAction = $linkedAction; $this->actionOrigin = $actionOrigin; - if ($order == ActionObject::MERGE_ACTION_ORDER_AFTER) { + if ($order === ActionObject::MERGE_ACTION_ORDER_AFTER) { $this->orderOffset = 1; } } diff --git a/src/Magento/FunctionalTestingFramework/Test/Util/ActionMergeUtil.php b/src/Magento/FunctionalTestingFramework/Test/Util/ActionMergeUtil.php index 65fe7c857..2a939a8c7 100644 --- a/src/Magento/FunctionalTestingFramework/Test/Util/ActionMergeUtil.php +++ b/src/Magento/FunctionalTestingFramework/Test/Util/ActionMergeUtil.php @@ -29,6 +29,8 @@ class ActionMergeUtil const DEFAULT_SKIP_ON_ORDER = 'before'; const DEFAULT_SKIP_OFF_ORDER = 'after'; const DEFAULT_WAIT_ORDER = 'after'; + const APPROVED_ACTIONS = ['fillField', 'magentoCLI', 'field']; + const SECRET_MAPPING = ['fillField' => 'fillSecretField', 'magentoCLI' => 'magentoCLISecret']; /** * Array holding final resulting steps @@ -95,7 +97,7 @@ public function resolveActionSteps($parsedSteps, $skipActionGroupResolution = fa /** * Takes an array of actions and resolves any references to secret fields. The function then validates whether the - * refernece is valid and replaces the function name accordingly to hide arguments at runtime. + * reference is valid and replaces the function name accordingly to hide arguments at runtime. * * @param ActionObject[] $resolvedActions * @return ActionObject[] @@ -106,22 +108,28 @@ private function resolveSecretFieldAccess($resolvedActions) $actions = []; foreach ($resolvedActions as $resolvedAction) { $action = $resolvedAction; - $hasSecretRef = $this->actionAttributeContainsSecretRef($resolvedAction->getCustomActionAttributes()); + $actionHasSecretRef = $this->actionAttributeContainsSecretRef($resolvedAction->getCustomActionAttributes()); + $actionType = $resolvedAction->getType(); - if ($resolvedAction->getType() !== 'fillField' && $hasSecretRef) { - throw new TestReferenceException("You cannot reference secret data outside of fill field actions"); + if ($actionHasSecretRef && !(in_array($actionType, self::APPROVED_ACTIONS))) { + throw new TestReferenceException("You cannot reference secret data outside " . + "of the fillField, magentoCLI and createData actions"); } - if ($resolvedAction->getType() === 'fillField' && $hasSecretRef) { - $action = new ActionObject( - $action->getStepKey(), - 'fillSecretField', - $action->getCustomActionAttributes(), - $action->getLinkedAction(), - $action->getActionOrigin() - ); + // Do NOT remap actions that don't need it. + if (isset(self::SECRET_MAPPING[$actionType]) && $actionHasSecretRef) { + $actionType = self::SECRET_MAPPING[$actionType]; } + $action = new ActionObject( + $action->getStepKey(), + $actionType, + $action->getCustomActionAttributes(), + $action->getLinkedAction(), + $action->getOrderOffset(), + $action->getActionOrigin() + ); + $actions[$action->getStepKey()] = $action; } @@ -261,7 +269,7 @@ private function insertReadinessSkips() * * @param array $parsedSteps * @return void - * @throws XmlException + * @throws TestReferenceException */ private function sortActions($parsedSteps) { diff --git a/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php b/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php index 9e878277e..d07c5e1e0 100644 --- a/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php +++ b/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php @@ -755,7 +755,7 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato if (count($customEntityFields) > 1) { $createEntityFunctionCall .= ",\n\t\t\t\${$stepKey}Fields"; } else { - $createEntityFunctionCall .= ",\n\t\t\tnull"; + $createEntityFunctionCall .= ",\n\t\t\t[]"; } if ($storeCode !== null) { $createEntityFunctionCall .= ",\n\t\t\t\"{$storeCode}\""; @@ -1266,6 +1266,7 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato ); break; case "magentoCLI": + case "magentoCLISecret": $testSteps .= $this->wrapFunctionCallWithReturnValue( $stepKey, $actor, @@ -1275,7 +1276,7 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato ); $testSteps .= sprintf(self::STEP_KEY_ANNOTATION, $stepKey) . PHP_EOL; $testSteps .= sprintf( - "\t\t$%s->comment(\$%s);\n", + "\t\t$%s->comment(\$%s);", $actor, $stepKey ); @@ -1287,7 +1288,11 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato $actionObject->getActionOrigin() )[0]; $argRef = "\t\t\$"; - $argRef .= str_replace(ucfirst($fieldKey), "", $stepKey) . "Fields['{$fieldKey}'] = ${input};\n"; + + $input = $this->resolveAllRuntimeReferences([$input])[0]; + $argRef .= str_replace(ucfirst($fieldKey), "", $stepKey) . + "Fields['{$fieldKey}'] = ${input};"; + $testSteps .= $argRef; break; case "generateDate":