@@ -20,30 +20,34 @@ 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
30
* @return string
31
31
* @throws TestFrameworkException
32
32
*/
33
- public static function getOTP ()
33
+ public static function getOTP ($ path = null )
34
34
{
35
- return self ::create ()->now ();
35
+ if ($ path === null ) {
36
+ $ path = self ::OTP_SHARED_SECRET_PATH ;
37
+ }
38
+ return self ::create ($ path )->now ();
36
39
}
37
40
38
41
/**
39
42
* Create TOTP object
40
43
*
44
+ * @param $path
41
45
* @return TOTP
42
46
* @throws TestFrameworkException
43
47
*/
44
- private static function create ()
48
+ private static function create ($ path )
45
49
{
46
- if (self ::$ totp === null ) {
50
+ if (! isset ( self ::$ totps [ $ path ]) ) {
47
51
try {
48
52
// Get shared secret from Credential storage
49
53
$ encryptedSecret = CredentialStore::getInstance ()->getSecret (self ::OTP_SHARED_SECRET_PATH );
@@ -52,10 +56,10 @@ private static function create()
52
56
throw new TestFrameworkException ('Unable to get OTP ' . PHP_EOL . $ e ->getMessage ());
53
57
}
54
58
55
- self ::$ totp = TOTP ::create ($ secret );
56
- self ::$ totp ->setIssuer ('MFTF ' );
57
- self ::$ totp ->setLabel ('MFTF Testing ' );
59
+ self ::$ totps [ $ path ] = TOTP ::create ($ secret );
60
+ self ::$ totps [ $ path ] ->setIssuer ('MFTF ' );
61
+ self ::$ totps [ $ path ] ->setLabel ('MFTF Testing ' );
58
62
}
59
- return self ::$ totp ;
63
+ return self ::$ totps [ $ path ] ;
60
64
}
61
65
}
0 commit comments