You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 19, 2024. It is now read-only.
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
_This topic was updated due to the {{page.mftf-release}} MFTF release._
9
9
{: style="text-align: right"}
10
10
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.
15
12
The following diagram shows the XML structure of an MFTF data object:
16
13
17
14
{%include_relative img/data-dia.svg%}
18
15
19
-
### Supply data to test by reference to a data entity
16
+
## Supply data to test by reference to a data entity
17
+
20
18
{%raw%}
21
19
Test steps requiring `<data>` input in an action, like filling a field with a string, may reference an attribute from a data entity:
22
20
@@ -29,8 +27,7 @@ In this example:
29
27
*`SimpleSubCategory` is an entity name.
30
28
*`name` is a `<data>` key of the entity. The corresponding value will be assigned to `userInput` as a result.
31
29
32
-
****
33
-
#### Environmental data
30
+
### Environmental data
34
31
35
32
```xml
36
33
userInput="{{_ENV.MAGENTO_ADMIN_USERNAME}}"
@@ -40,23 +37,24 @@ In this example:
40
37
41
38
*`_ENV` is a reference to the `dev/tests/acceptance/.env` file, where basic environment variables are set.
42
39
*`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.
44
41
45
-
####Sensitive data
42
+
### Sensitive data
46
43
47
44
```xml
48
-
userInput="{{_CREDS.MY_SECRET_TOKEN}}"
45
+
userInput="{{_CREDS.my_secret_token}}"
49
46
```
50
47
51
48
In this example:
52
49
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.
54
51
*`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.
58
54
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
60
58
61
59
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.
62
60
@@ -84,7 +82,8 @@ The current scope is preferred, then widening to _test > hook > suite_ or _hook
84
82
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.'
85
83
%}
86
84
87
-
### Use data returned by test actions
85
+
## Use data returned by test actions
86
+
88
87
{%raw%}
89
88
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>`.
90
89
@@ -97,7 +96,7 @@ The following example shows the usage of `grabValueFrom` in testing, where the r
0 commit comments