Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.

Commit 5732faf

Browse files
authored
Merge pull request #3278 from magento/ds_MAGEDOC-3232_mftf-credentials
Add the MFTF Credentials topic
2 parents d9d12b3 + bc3051b commit 5732faf

File tree

4 files changed

+122
-19
lines changed

4 files changed

+122
-19
lines changed

_data/toc/magento-functional-testing-framework-guide-2_3.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
label: Magento Functional Testing Framework Guide version 2.3
2-
versionless: true
32
pages:
43

54
- label: Introduction
@@ -72,6 +71,10 @@ pages:
7271
url: /mftf/2.3/reporting.html
7372
versionless: true
7473

74+
- label: Credentials
75+
url: /mftf/2.3/credentials.html
76+
versionless: true
77+
7578
- label: Configuration
7679
url: /mftf/2.3/configuration.html
7780
versionless: true

mftf/2.3/credentials.md

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
---
2+
---
3+
4+
# Credentials
5+
6+
When you test functionality that involves external services such as UPS, FedEx, PayPal, or SignifyD, use the MFTF credentials feature to hide sensitive [data][] like integration tokens and API keys.
7+
8+
## Define sensitive data in `.credentials`
9+
10+
The MFTF creates a sample file for credentials during [initial setup][]: `magento2/dev/tests/acceptance/.credentials.example`.
11+
The file contains an example list of keys for fields that can require credentials.
12+
13+
### Create `.credentials`
14+
15+
To make the MFTF process the file with credentials, change directories to `magento2/dev/tests/acceptance/` and copy `.credentials.example` to `.credentials`.
16+
17+
```bash
18+
cd dev/tests/acceptance/
19+
```
20+
21+
```bash
22+
cp .credentials.example .credentials
23+
```
24+
25+
### Add `.credentials` to `.gitignore`
26+
27+
Verify that the file is excluded from tracking by `.gitignore` (unless you need this behavior):
28+
29+
```bash
30+
git check-ignore .credentials
31+
```
32+
33+
The command outputs the path if the file is excluded:
34+
35+
```terminal
36+
.credentials
37+
```
38+
39+
### Define sensitive data
40+
41+
Open the `.credentials` file, uncomment the fields you want to use, and add your values:
42+
43+
```config
44+
...
45+
# Credentials for the USPS service
46+
carriers_usps_userid=test_user
47+
carriers_usps_password=Lmgxvrq89uPwECeV
48+
49+
# Credentials for the DHL service
50+
#carriers/dhl/id_us=
51+
#carriers/dhl/password_us=
52+
....
53+
```
54+
55+
{: .bs-callout .bs-callout-info }
56+
The `/` symbol is not supported in a key name.
57+
58+
You are free to use any other keys you like, as they are merely the keys to reference from your tests.
59+
60+
```conf
61+
# Credentials for the MyAwesome service
62+
my_awesome_service_token=rRVSVnh3cbDsVG39oTMz4A
63+
64+
# Credentials for the USPS service
65+
carriers_usps_userid=test_user
66+
carriers_usps_password=Lmgxvrq89uPwECeV
67+
....
68+
```
69+
70+
## Use credentials in a test
71+
72+
<!--{% raw %}-->
73+
Access the data defined in the `.credentials` file using the [`fillField`][] action with the `userInput` attribute.
74+
Define the value as a reference to the corresponding key in the credentials file such as `{{_CREDS.my_data_key}}`:
75+
76+
- `_CREDS` is an environment constant pointing to the `.credentials` file
77+
- `my_data_key` is a key in the the `.credentials` file that contains the value to be used in a test step
78+
79+
For example:
80+
81+
```xml
82+
<fillField stepKey="FillApiToken" selector=".api-token" userInput="{{_CREDS.my_data_key}}" />
83+
```
84+
85+
## Implementation details
86+
87+
The generated tests do not contain credentials values.
88+
The MFTF dynamically retrieves, encrypts, and decrypts the sensitive data during test execution.
89+
Decrypted credentials do not appear in the console, error logs, or [test reports][].
90+
The decrypted values are only available in the `.credentials` file.
91+
92+
{: .bs-callout .bs-callout-info }
93+
The MFTF tests delivered with Magento application do not use credentials and do not cover external services, because of sensitivity of the data.
94+
95+
<!--{% endraw %}-->
96+
97+
<!-- Link definitions -->
98+
[`fillField`]: test/actions.html#fillfield
99+
[data]: data.html
100+
[initial setup]: getting-started.html
101+
[test reports]: reporting.html

mftf/2.3/data.md

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,13 @@ redirect_from: /guides/v2.3/magento-functional-testing-framework/2.3/data.html
88
_This topic was updated due to the {{page.mftf-release}} MFTF release._
99
{: style="text-align: right"}
1010

11-
Tests require data to function properly.
12-
13-
The MFTF allows you to specify and use `<data>` entities defined in XML. Default `<data>` entities are provided for use and as templates for entity creation and manipulation.
14-
11+
The MFTF enables you to specify and use `<data>` entities defined in XML. Default `<data>` entities are provided for use and as templates for entity creation and manipulation.
1512
The following diagram shows the XML structure of an MFTF data object:
1613

1714
{%include_relative img/data-dia.svg%}
1815

19-
### Supply data to test by reference to a data entity
16+
## Supply data to test by reference to a data entity
17+
2018
{%raw%}
2119
Test steps requiring `<data>` input in an action, like filling a field with a string, may reference an attribute from a data entity:
2220

@@ -29,8 +27,7 @@ In this example:
2927
* `SimpleSubCategory` is an entity name.
3028
* `name` is a `<data>` key of the entity. The corresponding value will be assigned to `userInput` as a result.
3129

32-
****
33-
#### Environmental data
30+
### Environmental data
3431

3532
```xml
3633
userInput="{{_ENV.MAGENTO_ADMIN_USERNAME}}"
@@ -40,23 +37,24 @@ In this example:
4037

4138
* `_ENV` is a reference to the `dev/tests/acceptance/.env` file, where basic environment variables are set.
4239
* `MAGENTO_ADMIN_USERNAME` is a name of an environment variable.
43-
The corresponding value will be assigned to `userInput` as a result.
40+
The corresponding value will be assigned to `userInput` as a result.
4441

45-
#### Sensitive data
42+
### Sensitive data
4643

4744
```xml
48-
userInput="{{_CREDS.MY_SECRET_TOKEN}}"
45+
userInput="{{_CREDS.my_secret_token}}"
4946
```
5047

5148
In this example:
5249

53-
* `_CREDS` is a reference to the `dev/tests/acceptance/.credentials` file, where sensitive data and secrets are stored for use in a test.
50+
* `_CREDS` is a constant to reference to the `dev/tests/acceptance/.credentials` file, where sensitive data and secrets are stored for use in a test.
5451
* `MY_SECRET_TOKEN` is the name of a key in the credentials variable.
55-
The corresponding value of the credential will be assigned to `userInput` as a result.
56-
* Credential values are not generated into a test. Instead, they are dynamically retrieved, encrypted and decrypted when used by a specific action during the test's execution.
57-
* References to credentials do not appear decrypted in the console, error logs or test reports, their values can only be seen decrypted in the .credentials file in which they are stored.
52+
The corresponding value of the credential will be assigned to `userInput` as a result.
53+
* The decrypted values are only available in the `.credentials` file in which they are stored.
5854

59-
### Persist a data entity as a prerequisite of a test
55+
Learn more in [Credentials][].
56+
57+
## Persist a data entity as a prerequisite of a test
6058

6159
A test can specify an entity to be persisted (created in the database) so that the test actions could operate on the existing known data.
6260

@@ -84,7 +82,8 @@ The current scope is preferred, then widening to _test > hook > suite_ or _hook
8482
This emphasizes the practice for the `stepKey` of `createData` to be descriptive and unique, as a duplicated `stepKey` in both a `<test>` and `<before>` prefers the `<test>` data.'
8583
%}
8684

87-
### Use data returned by test actions
85+
## Use data returned by test actions
86+
8887
{%raw%}
8988
A test can also reference data that was returned as a result of [test actions](./test/actions.html#actions-returning-a-variable), like the action `<grabValueFrom selector="someSelector" stepKey="grabStepKey>`.
9089

@@ -97,7 +96,7 @@ The following example shows the usage of `grabValueFrom` in testing, where the r
9796
<fillField selector=".functionalTestSelector" userInput="{$grabStepKey}" stepKey="fillFieldKey1"/>
9897
```
9998

100-
### Hard-coded data input
99+
## Hard-coded data input
101100

102101
The data to operate against can be included as literals in a test. Hard-coded data input can be useful in assertions.
103102

mftf/2.3/reporting.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ Refer to the [Reporting section][] for more Allure CLI details.
354354

355355
<!-- Link definitions -->
356356

357-
[`after`]: test#after-tag
357+
[`after`]: test.html#after-tag
358358
[`run:group`]: commands/mftf.html#rungroup
359359
[`run:test`]: commands/mftf.html#runtest
360360
[Allure Framework]: https://docs.qameta.io/allure/

0 commit comments

Comments
 (0)