@@ -20,42 +20,47 @@ class OTP
20
20
/**
21
21
* TOTP object
22
22
*
23
- * @var TOTP
23
+ * @var TOTP[]
24
24
*/
25
- private static $ totp = null ;
25
+ private static $ totps = [] ;
26
26
27
27
/**
28
28
* Return OTP for custom secret stored in `magento/tfa/OTP_SHARED_SECRET`
29
29
*
30
+ * @param string|null $path
30
31
* @return string
31
32
* @throws TestFrameworkException
32
33
*/
33
- public static function getOTP ()
34
+ public static function getOTP ($ path = null )
34
35
{
35
- return self ::create ()->now ();
36
+ if ($ path === null ) {
37
+ $ path = self ::OTP_SHARED_SECRET_PATH ;
38
+ }
39
+ return self ::create ($ path )->now ();
36
40
}
37
41
38
42
/**
39
43
* Create TOTP object
40
44
*
45
+ * @param string $path
41
46
* @return TOTP
42
47
* @throws TestFrameworkException
43
48
*/
44
- private static function create ()
49
+ private static function create ($ path )
45
50
{
46
- if (self ::$ totp === null ) {
51
+ if (! isset ( self ::$ totps [ $ path ]) ) {
47
52
try {
48
53
// Get shared secret from Credential storage
49
- $ encryptedSecret = CredentialStore::getInstance ()->getSecret (self :: OTP_SHARED_SECRET_PATH );
54
+ $ encryptedSecret = CredentialStore::getInstance ()->getSecret ($ path );
50
55
$ secret = CredentialStore::getInstance ()->decryptSecretValue ($ encryptedSecret );
51
56
} catch (TestFrameworkException $ e ) {
52
57
throw new TestFrameworkException ('Unable to get OTP ' . PHP_EOL . $ e ->getMessage ());
53
58
}
54
59
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 ' );
58
63
}
59
- return self ::$ totp ;
64
+ return self ::$ totps [ $ path ] ;
60
65
}
61
66
}
0 commit comments