Skip to content

Commit 3510e9f

Browse files
authored
Merge pull request #702 from magento/MQE-2122
MQE-2122: MFTF 2FA documentation
2 parents ce21f48 + b73d01b commit 3510e9f

File tree

3 files changed

+74
-0
lines changed

3 files changed

+74
-0
lines changed

docs/configure-2fa.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Configuring MFTF for Two-Factor Authentication (2FA)
2+
3+
Using two-factor authentication (2FA) with MFTF is possible with some configurations settings in Magento.
4+
In this document, we will use Google as the authentication provider.
5+
6+
## Configure Magento {#config-magento-2fa}
7+
8+
To prepare Magento for MFTF testing when 2FA is enabled, set the following configurations through the Magento CLI.
9+
10+
First, select `Google Authenticator` as Magento's 2FA provider:
11+
12+
```bash
13+
bin/magento config:set twofactorauth/general/force_providers google
14+
```
15+
16+
Now set the OTP window to `60` seconds:
17+
18+
```bash
19+
bin/magento config:set twofactorauth/google/otp_window 60
20+
```
21+
22+
Set a base32-encoded `secret` for `Google Authenticator` to generate a OTP for the default admin user that you set for `MAGENTO_ADMIN_USERNAME` in `.env`:
23+
24+
```bash
25+
bin/magento security:tfa:google:set-secret <MAGENTO_ADMIN_USERNAME> <OTP_SHARED_SECRET>
26+
```
27+
28+
## Configure the MFTF {#config-mftf-2fa}
29+
30+
Save the same base32-encoded `secret` in a MFTF credential storage, e.g. `.credentials` file, `HashiCorp Vault` or `AWS Secrets Manager`.
31+
More details are [here](./credentials.md).
32+
33+
The path of the `secret` should be:
34+
35+
```conf
36+
magento/tfa/OTP_SHARED_SECRET
37+
```
38+
39+
## GetOTP {#getOTP}
40+
41+
A one-time password (OTP) is required when an admin user logs into the Magento admin.
42+
Use the action `getOTP` [Reference](./test/actions.md#getotp) to generate the code and use it for the `Authenticator code` text field in 2FA - Google Auth page.
43+
44+
Note:
45+
You will need to set the `secret` for any non-default admin users first, before using `getOTP`. For example:
46+
47+
```xml
48+
<magentoCLI command="security:tfa:google:set-secret admin2 {{_CREDS.magento/tfa/OTP_SHARED_SECRET}}" stepKey="setSecret"/>
49+
```

docs/getting-started.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ Clean the cache after changing the configuration values:
109109
bin/magento cache:clean config full_page
110110
```
111111

112+
### Testing with the Magento Two-Factor Authentication (2FA) extension {#2fa}
113+
114+
If the Magento instance under test has the [Magento Two-Factor Authentication (2FA) extension][] installed and enabled, additional configurations is needed to run MFTF tests. Learn more in [Configure MFTF for Magento with Two-Factor Authentication (2FA)](./configure-2fa.md).
115+
112116
### Webserver configuration {#web-server-configuration}
113117

114118
The MFTF does not support executing CLI commands if your web server points to `<MAGE_ROOT_DIR>/pub` directory as recommended in the [Installation Guide][Installation Guide docroot]. For the MFTF to execute the CLI commands, the web server must point to the Magento root directory.
@@ -357,3 +361,4 @@ allure serve dev/tests/_output/allure-results/
357361
[test suite]: suite.html
358362
[Find your MFTF version]: introduction.html#find-your-mftf-version
359363
[Installation Guide docroot]: https://devdocs.magento.com/guides/v2.3/install-gde/tutorials/change-docroot-to-pub.html
364+
[Magento Two-Factor Authentication (2FA) extension]: https://devdocs.magento.com/guides/v2.3/security/two-factor-authentication.html

docs/test/actions.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ The following test actions return a variable:
150150
* [grabTextFrom](#grabtextfrom)
151151
* [grabValueFrom](#grabvaluefrom)
152152
* [executeJS](#executejs)
153+
* [getOTP](#getotp)
153154

154155
Learn more in [Using data returned by test actions](../data.md#use-data-returned-by-test-actions).
155156

@@ -1072,6 +1073,25 @@ The `ProductAttributeOptionGetter` entity must be defined in the corresponding [
10721073

10731074
This action can optionally contain one or more [requiredEntity](#requiredentity) child elements.
10741075

1076+
### getOTP
1077+
1078+
Generate a one-time password (OTP) based on a saved `secret` at path `magento/tfa/OTP_SHARED_SECRET` in a MFTF credential storage.
1079+
The one-time password (OTP) is returned and accessible through the stepkey.
1080+
1081+
MFTF use TOTP from [Spomky-Labs/otphp](https://github.com/Spomky-Labs/otphp), if you want to learn more about this action.
1082+
1083+
Attribute|Type|Use|Description
1084+
---|---|---|---
1085+
`stepKey`|string|required| A unique identifier of the action.
1086+
`before`|string|optional| `stepKey` of action that must be executed next.
1087+
`after`|string|optional| `stepKey` of preceding action.
1088+
1089+
#### Example
1090+
1091+
```xml
1092+
<getOTP stepKey="getOtp"/>
1093+
```
1094+
10751095
### grabAttributeFrom
10761096

10771097
See [grabAttributeFrom docs on codeception.com](http://codeception.com/docs/modules/WebDriver#grabAttributeFrom).

0 commit comments

Comments
 (0)