Skip to content

MQE-1427 - Support _CREDS in <magentoCLI> action and in Data #368

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 42 commits into from
Jun 28, 2019
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
66fb4c2
MQE-1427: Support _CREDS in <magentoCLI> action and in Data
ivy00johns Jun 11, 2019
55e6421
MQE-1427: Support _CREDS in <magentoCLI> action and in Data
ivy00johns Jun 11, 2019
5fc6347
MQE-1427: Support _CREDS in <magentoCLI> action and in Data
ivy00johns Jun 13, 2019
052e15d
Merge branch 'develop' into MQE-1427
ivy00johns Jun 13, 2019
d9060d7
MQE-1427: Support _CREDS in <magentoCLI> action and in Data
ivy00johns Jun 14, 2019
98480cf
Merge remote-tracking branch 'origin/MQE-1427' into MQE-1427
ivy00johns Jun 14, 2019
6dcd2f4
MQE-1427: Support _CREDS in <magentoCLI> action and in Data
ivy00johns Jun 14, 2019
7b8de7e
MQE-1427: Support _CREDS in <magentoCLI> action and in Data
ivy00johns Jun 14, 2019
acf87b6
MQE-1427: Support _CREDS in <magentoCLI> action and in Data
ivy00johns Jun 14, 2019
ecb5a8a
Merge branch 'develop' into MQE-1427
ivy00johns Jun 14, 2019
b0e821f
MQE-1427: Support _CREDS in <magentoCLI> action and in Data
ivy00johns Jun 14, 2019
bffe7d6
Merge remote-tracking branch 'origin/MQE-1427' into MQE-1427
ivy00johns Jun 14, 2019
847e5ff
MQE-1427: Support _CREDS in <magentoCLI> action and in Data
ivy00johns Jun 14, 2019
eeb174a
MQE-1427: Support _CREDS in <magentoCLI> action and in Data
ivy00johns Jun 17, 2019
352b660
MQE-1427: Support _CREDS in <magentoCLI> action and in Data
ivy00johns Jun 17, 2019
0eaaa01
MQE-1427: Support _CREDS in <magentoCLI> action and in Data
ivy00johns Jun 17, 2019
f83c893
MQE-1427: Support _CREDS in <magentoCLI> action and in Data
ivy00johns Jun 17, 2019
2d5e178
MQE-1427: Support _CREDS in <magentoCLI> action and in Data
ivy00johns Jun 18, 2019
7c837c3
Merge branch 'develop' into MQE-1427
ivy00johns Jun 18, 2019
7a1a4e5
MQE-1427: Support _CREDS in <magentoCLI> action and in Data
ivy00johns Jun 18, 2019
e4ddde9
Merge remote-tracking branch 'origin/MQE-1427' into MQE-1427
ivy00johns Jun 18, 2019
ad99e96
MQE-1427: Support _CREDS in <magentoCLI> action and in Data
ivy00johns Jun 18, 2019
0cd5a47
Merge branch 'develop' into MQE-1427
ivy00johns Jun 18, 2019
d1b3be3
MQE-1427: Support _CREDS in <magentoCLI> action and in Data
ivy00johns Jun 18, 2019
6cf6400
MQE-1427: Support _CREDS in <magentoCLI> action and in Data
ivy00johns Jun 18, 2019
1e22a8c
MQE-1427: Support _CREDS in <magentoCLI> action and in Data
ivy00johns Jun 19, 2019
fd66a0c
MQE-1427: Support _CREDS in <magentoCLI> action and in Data
ivy00johns Jun 19, 2019
537b404
MQE-1427: Support _CREDS in <magentoCLI> action and in Data
ivy00johns Jun 19, 2019
82a80c6
MQE-1427: Support _CREDS in <magentoCLI> action and in Data
ivy00johns Jun 20, 2019
c38ab37
MQE-1427: Support _CREDS in <magentoCLI> action and in Data
ivy00johns Jun 20, 2019
a07275f
MQE-1427: Support _CREDS in <magentoCLI> action and in Data
ivy00johns Jun 20, 2019
9510135
MQE-1427: Support _CREDS in <magentoCLI> action and in Data
ivy00johns Jun 20, 2019
29b37f4
MQE-1427: Support _CREDS in <magentoCLI> action and in Data
ivy00johns Jun 20, 2019
9f96927
MQE-1427: Support _CREDS in <magentoCLI> action and in Data
ivy00johns Jun 20, 2019
3d2d857
MQE-1427: Support _CREDS in <magentoCLI> action and in Data
ivy00johns Jun 20, 2019
8cd1a39
MQE-1427: Support _CREDS in <magentoCLI> action and in Data
ivy00johns Jun 21, 2019
9ef7ea7
MQE-1427: Support _CREDS in <magentoCLI> action and in Data
ivy00johns Jun 21, 2019
637c3eb
MQE-1427: Support _CREDS in <magentoCLI> action and in Data
ivy00johns Jun 21, 2019
32fac0c
MQE-1427: Support _CREDS in <magentoCLI> action and in Data
ivy00johns Jun 21, 2019
cd0d237
MQE-1427: Support _CREDS in <magentoCLI> action and in Data
ivy00johns Jun 21, 2019
d103842
MQE-1427: Support _CREDS in <magentoCLI> action and in Data
ivy00johns Jun 24, 2019
c5286e6
Merge branch 'develop' into MQE-1427
KevinBKozan Jun 28, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -100,7 +102,7 @@ public function testResolveActionStepEntityData()
$dataFieldName = 'myfield';
$dataFieldValue = 'myValue';
$userInputKey = "userInput";
$userinputValue = "{{" . "${dataObjectName}.${dataFieldName}}}";
$userInputValue = "{{" . "${dataObjectName}.${dataFieldName}}}";
$actionName = "myAction";
$actionType = "myCustomType";

Expand All @@ -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);
Expand All @@ -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 = [];
Expand All @@ -151,6 +159,8 @@ public function testNoActionException()
/**
* Verify that a <waitForPageLoad> action is added after actions that have a wait (timeout property).
*
* @throws TestReferenceException
* @throws XmlException
* @return void
*/
public function testInsertWait()
Expand All @@ -173,6 +183,111 @@ public function testInsertWait()
$this->assertEquals($expected, $actual);
}

/**
* Verify that a <fillField> action is replaced by <fillSecretField> 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 <magentoCLI> action uses <magentoCLI> 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 <field> override in a <createData> action uses <field> 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 <click> 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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../../../src/Magento/FunctionalTestingFramework/Test/etc/testSchema.xsd">
<test name="secretCredentialDataTest">
<createData entity="_defaultProduct" stepKey="createProductWithFieldOverridesUsingHardcodedData1">
<field key="qty">123</field>
<field key="price">12.34</field>
</createData>
<createData entity="_defaultProduct" stepKey="createProductWithFieldOverridesUsingSecretCredData1">
<field key="qty">{{_CREDS.payment_authorizenet_trans_key}}</field>
<field key="price">{{_CREDS.carriers_dhl_account_eu}}</field>
</createData>

<fillField selector="{{AdminLoginFormSection.username}}" userInput="Hardcoded" stepKey="fillFieldUsingHardCodedData1"/>
<fillField selector="{{AdminLoginFormSection.username}}" userInput="{{_CREDS.carriers_dhl_id_eu}}" stepKey="fillFieldUsingSecretCredData1"/>

<magentoCLI command="config:set cms/wysiwyg/enabled 0" stepKey="magentoCliUsingHardcodedData1"/>
<magentoCLI command="config:set cms/wysiwyg/enabled {{_CREDS.payment_authorizenet_login}}" stepKey="magentoCliUsingSecretCredData1"/>
</test>
</tests>
75 changes: 75 additions & 0 deletions dev/tests/verification/Tests/SecretCredentialDataTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\AcceptanceTest\_default\Backend;

use Magento\FunctionalTestingFramework\AcceptanceTester;
use Magento\FunctionalTestingFramework\DataGenerator\Handlers\CredentialStore;
use Magento\FunctionalTestingFramework\DataGenerator\Handlers\PersistedObjectHandler;
use \Codeception\Util\Locator;
use Yandex\Allure\Adapter\Annotation\Features;
use Yandex\Allure\Adapter\Annotation\Stories;
use Yandex\Allure\Adapter\Annotation\Title;
use Yandex\Allure\Adapter\Annotation\Description;
use Yandex\Allure\Adapter\Annotation\Parameter;
use Yandex\Allure\Adapter\Annotation\Severity;
use Yandex\Allure\Adapter\Model\SeverityLevel;
use Yandex\Allure\Adapter\Annotation\TestCaseId;

/**
*/
class SecretCredentialDataTestCest
{
/**
* @Features({"AdminNotification"})
* @Parameter(name = "AcceptanceTester", value="$I")
* @param AcceptanceTester $I
* @return void
* @throws \Exception
*/
public function secretCredentialDataTest(AcceptanceTester $I)
{
$createProductWithFieldOverridesUsingHardcodedData1Fields['qty'] = "123";

$createProductWithFieldOverridesUsingHardcodedData1Fields['price'] = "12.34";

$I->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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -636,6 +636,24 @@ public function fillSecretField($field, $value)
$this->fillField($field, $decryptedValue);
}

/**
* Function used to create data that contains sensitive credentials in a <createData> <field> 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 mixed
*/
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);
$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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
Loading