Skip to content

Commit e688fd6

Browse files
committed
Add ability to configure multiple OTPs
1 parent 5a6bdf5 commit e688fd6

File tree

6 files changed

+24
-14
lines changed

6 files changed

+24
-14
lines changed

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

+1
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ class BasicFunctionalTestCest
113113
$generateDateKey2 = $date->format("H:i:s");
114114

115115
$getOtp = $I->getOTP(); // stepKey: getOtp
116+
$getOtpWithInput = $I->getOTP("someInput"); // stepKey: getOtpWithInput
116117
$grabAttributeFromKey1 = $I->grabAttributeFrom(".functionalTestSelector", "someInput"); // stepKey: grabAttributeFromKey1
117118
$grabCookieKey1 = $I->grabCookie("grabCookieInput", ['domain' => 'www.google.com']); // stepKey: grabCookieKey1
118119
$grabFromCurrentUrlKey1 = $I->grabFromCurrentUrl("/grabCurrentUrl"); // stepKey: grabFromCurrentUrlKey1

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

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
<generateDate date="Now" format="H:i:s" stepKey="generateDateKey"/>
7070
<generateDate date="Now" format="H:i:s" stepKey="generateDateKey2" timezone="UTC"/>
7171
<getOTP stepKey="getOtp"/>
72+
<getOTP stepKey="getOtpWithInput" userInput="someInput"/>
7273
<grabAttributeFrom selector=".functionalTestSelector" userInput="someInput" stepKey="grabAttributeFromKey1" />
7374
<grabCookie userInput="grabCookieInput" parameterArray="['domain' => 'www.google.com']" stepKey="grabCookieKey1" />
7475
<grabFromCurrentUrl regex="/grabCurrentUrl" stepKey="grabFromCurrentUrlKey1" />

Diff for: src/Magento/FunctionalTestingFramework/DataTransport/Auth/Tfa/OTP.php

+16-11
Original file line numberDiff line numberDiff line change
@@ -20,42 +20,47 @@ class OTP
2020
/**
2121
* TOTP object
2222
*
23-
* @var TOTP
23+
* @var TOTP[]
2424
*/
25-
private static $totp = null;
25+
private static $totps = [];
2626

2727
/**
2828
* Return OTP for custom secret stored in `magento/tfa/OTP_SHARED_SECRET`
2929
*
30+
* @param string|null $path
3031
* @return string
3132
* @throws TestFrameworkException
3233
*/
33-
public static function getOTP()
34+
public static function getOTP($path = null)
3435
{
35-
return self::create()->now();
36+
if ($path === null) {
37+
$path = self::OTP_SHARED_SECRET_PATH;
38+
}
39+
return self::create($path)->now();
3640
}
3741

3842
/**
3943
* Create TOTP object
4044
*
45+
* @param string $path
4146
* @return TOTP
4247
* @throws TestFrameworkException
4348
*/
44-
private static function create()
49+
private static function create($path)
4550
{
46-
if (self::$totp === null) {
51+
if (!isset(self::$totps[$path])) {
4752
try {
4853
// Get shared secret from Credential storage
49-
$encryptedSecret = CredentialStore::getInstance()->getSecret(self::OTP_SHARED_SECRET_PATH);
54+
$encryptedSecret = CredentialStore::getInstance()->getSecret($path);
5055
$secret = CredentialStore::getInstance()->decryptSecretValue($encryptedSecret);
5156
} catch (TestFrameworkException $e) {
5257
throw new TestFrameworkException('Unable to get OTP' . PHP_EOL . $e->getMessage());
5358
}
5459

55-
self::$totp = TOTP::create($secret);
56-
self::$totp->setIssuer('MFTF');
57-
self::$totp->setLabel('MFTF Testing');
60+
self::$totps[$path] = TOTP::create($secret);
61+
self::$totps[$path]->setIssuer('MFTF');
62+
self::$totps[$path]->setLabel('MFTF Testing');
5863
}
59-
return self::$totp;
64+
return self::$totps[$path];
6065
}
6166
}

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -970,12 +970,13 @@ public function makeScreenshot($name = null)
970970
/**
971971
* Return OTP based on a shared secret
972972
*
973+
* @param string|null $secretsPath
973974
* @return string
974975
* @throws TestFrameworkException
975976
*/
976-
public function getOTP()
977+
public function getOTP($secretsPath = null)
977978
{
978-
return OTP::getOTP();
979+
return OTP::getOTP($secretsPath);
979980
}
980981

981982
/**

Diff for: src/Magento/FunctionalTestingFramework/Test/etc/Actions/customActions.xsd

+1
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@
335335
</xs:annotation>
336336
<xs:simpleContent>
337337
<xs:extension base="xs:string">
338+
<xs:attribute ref="userInput"/>
338339
<xs:attributeGroup ref="commonActionAttributes"/>
339340
</xs:extension>
340341
</xs:simpleContent>

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -1262,7 +1262,8 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato
12621262
$testSteps .= $this->wrapFunctionCallWithReturnValue(
12631263
$stepKey,
12641264
$actor,
1265-
$actionObject
1265+
$actionObject,
1266+
$input
12661267
);
12671268
break;
12681269
case "resizeWindow":

0 commit comments

Comments
 (0)