Skip to content
This repository was archived by the owner on Sep 2, 2025. It is now read-only.

Commit 2762c8a

Browse files
author
ada
committed
Added screenshots
1 parent 21999c0 commit 2762c8a

File tree

6 files changed

+101
-11
lines changed

6 files changed

+101
-11
lines changed
54.1 KB
Loading
307 KB
Loading

synthetics/test-config/auth-multifactor-email.rst

Lines changed: 82 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,89 @@ Multifactor authentication through email
55
******************************************************************
66

77
.. meta::
8-
:description: PLACEHOLDER.
8+
:description: Multifactor authentication allows your test to authenticate to a target page by sending it a code it receives through email.
99

1010

11-
PLACEHOLDER.
11+
.. :note:: This authentication method applies to browser tests only.
12+
13+
If your test target sends a one time passcode (OTP) through email for multifactor authentication, your browser test must retrieve the OTP from the email message and enter it into the input field on the target's page. To do this, configure your browser test as follows.
14+
15+
16+
Prerequisites
17+
============================
18+
19+
You must have an email service that supports connecting to your email account and managing your emails through an API. The steps below feature an example using the :new-page:`Nylas service <http://nylas.com>`. For detailed information on how to retrieve messages from this service, refer to its :new-page:`API documentation https://developer.nylas.com/docs/api/v3/ecc/?redirect=api#get-/v3/grants/-grant_id-/messages`.
20+
21+
Additionally, the steps below demonstrate the use of http://Github.com to send an authorization email, which is essential for extracting the OTP from it.
22+
23+
Limitations
24+
============================
25+
26+
Your email service must be accessible through an API. Some services may not be accessible during Synthetics tests due to violations of Content-Security-Policy (CSP). In such instances, a workaround is to implement third-party services on your server and provide an endpoint configured with CSP to allow connect-src.
27+
28+
1. On the browser test's configuration page, select the :guilabel:`Simple` toggle.
29+
30+
2. select :guilabel:`Edit steps or synthetic transactions`.
31+
32+
3. Add a step of type :guilabel:`Go to url`, and in :guilabel:`URL`, enter the URL of the target's authentication page.
33+
34+
4. Add a step of type :guilabel:`Save return value from JavaScript`, and in the code field, paste the following JavaScript.
35+
This script retrieves data from a specified URL using ``XMLHttpRequest`` and extracts the OTP from that data. You configure your test to save this OTP in a custom variable named ``otp``.
36+
.. :note:: In the script, set the variable url to the URL of your own email inbox API endpoint.
37+
.. :note:: If you are utilizing the Nylas service, you can locate unread emails by searching for specific text in the subject line or other parameters. For more information, please refer to the :new-page:`Nylas API documentation for messages <https://developer.nylas.com/docs/api/v3/ecc/?redirect=api#get-/v3/grants/-grant_id-/messages>`.
38+
39+
.. code-block:: javascript
40+
41+
function getOtp() {
42+
const grantId = "<NYLAS_GRANT_ID>";
43+
const jwToken = "<NYLAS_API_KEY>";
44+
const from = "[email protected]";
45+
const subject = "Your GitHub launch code";
46+
const unread = "true";
47+
const url = "https://api.us.nylas.com/v3/grants/" + grantId + "/messages?limit=1&unread=" + unread + "from=" + from + "&subject=" + subject;
48+
var request = new XMLHttpRequest();
49+
request.open("GET", url, false);
50+
request.setRequestHeader('Authorization', 'Bearer ' + jwToken)
51+
request.send();
52+
if (request.status == 200) {
53+
return parseOtp(JSON.parse(request.responseText));
54+
}
55+
return "ERR";
56+
}
57+
58+
function parseOtp(jsonResponse) {
59+
const firstInbound = jsonResponse. data[0];
60+
if (firstInbound && firstInbound.snippet) {
61+
// Extract the number using a regular expression
62+
const match = firstInbound.snippet.match(/\\b\\d{8}\\b/);
63+
if (match) {
64+
return match[0]; // Return the first matched number
65+
}
66+
}
67+
return "NO-OTP";
68+
}
69+
return getOtp();
70+
71+
5. Add a step of type :guilabel:`Wait`:, and specify a wait time in milliseconds. This time needs to be long enough for the target to send the OTP code to your email service, and for your JavaScript to process the OTP.
72+
73+
6. Add a step of type :guilabel:`Fill in field`, and set it up as follows:
74+
75+
1. In :guilabel:Selec`tor, enter the ID of the element on the target page where the user must enter the OTP.
76+
77+
2. In :guilabel:`Value`, enter the name of the custom varialble your JavaScript stored the OTP in, prefixed with custom. and enclosed in double curly braces. For example, ``{{custom.otp}}``.
78+
79+
.. image:: /_images/synthetics/auth-multifactor-email-fillinfield.png
80+
:width: 70%
81+
:alt: Screenshot showing the "Fill in field" step.
82+
83+
7. To verify that the login succeeded, add a step of type :guilabel:`Assert text present`, and set it up as follows:
84+
85+
1. In :guilabel:`Text`, enter a string that should be visible on the test target page only when login is successful.
86+
87+
2. (Optional) Set :guilabel:`Wait for up to` to a large enough value, in milliseconds, to ensure that the page loads.
88+
89+
8. Select :guilabel:`Submit`.
90+
91+
To verify that the login is working, select :guilabel:`Try now`. Results may take a while. The :guilabel:`Try now result` pane should display each screen that your test navigated to on the target page, plus the message :guilabel:`Success`.
1292

1393

synthetics/test-config/auth-multifactor-sms.rst

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,13 @@ Some services may not be accessible during Synthetics tests due to violations of
4343
:width: 70%
4444
:alt: Screenshot showing the "Go to URL" step.
4545

46-
47-
4. Add a step of type :guilabel:`Save return value from JavaScript`, and in the code field, paste the following JavaScript.
48-
This script retrieves data from a specified URL using ``XMLHttpRequest`` and extracts the OTP from that data. You configure your test to save this OTP in a global variable named ``otp``.
46+
4. Add a step of type :guilabel:`Save return value from JavaScript`, and in the code field, paste the following JavaScript. This script retrieves data from a specified URL using ``XMLHttpRequest`` and extracts the OTP from that data. You configure your test to save this OTP in a global variable named ``otp``.
4947

5048
.. :note:: In the script, set the variable url to the URL of your own virtual phone number's SMS service.
5149
52-
.. image:: /_images/synthetics/auth-multifactor-sms-three.png
53-
:width: 70%
54-
:alt: Screenshot showing the JavaScript that retrieves data from a specified URL.
50+
.. image:: /_images/synthetics/auth-multifactor-sms-three.png
51+
:width: 70%
52+
:alt: Screenshot showing the JavaScript that retrieves data from a specified URL.
5553

5654
.. code-block:: javascript
5755
@@ -87,7 +85,7 @@ Some services may not be accessible during Synthetics tests due to violations of
8785

8886
2. In :guilabel:`Value`, enter the name of the custom varialble your JavaScript stored the OTP in, prefixed with custom. and enclosed in double curly braces. For example, ``{{custom.otp}}``.
8987

90-
.. image:: /_images/synthetics/auth-multifactor-sms-four.png
88+
.. image:: /_images/synthetics/auth-multifactor-sms-fillinfield.png
9189
:width: 70%
9290
:alt: Screenshot showing the "Fill in field" step.
9391

synthetics/test-config/auth-multifactor-sso.rst

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,21 @@ Multifactor authentication through SSO and Active Directory
55
******************************************************************
66

77
.. meta::
8-
:description: PLACEHOLDER.
8+
:description: Multifactor authentication allows your test to authenticate to a target page by logging in through an SSO or Active Directory service.
99

1010

11-
PLACEHOLDER.
11+
Authorization through Single Sign-On (SSO) is similar to :ref:`basic authentication <auth-basic-html-login>`. To create a test of that uses SSO or AD login, you must configure a series of steps that include opening the webpage, selecting the SSO authentication link, and entering the required information for SSO authentication. Additional webpages may load during this process, so it's crucial that you include steps to confirm that all the components of each webpage have fully loaded before proceeding.
12+
13+
SSO authentication frequently involves additional authentication factors. If the identity provider (such as Google, Microsoft, Okta, Duo, and so on) does not mandate an extra login factor, your test might only need the authentication steps that are illustrated in the example below:
14+
15+
.. image:: /_images/synthetics/auth-multifactor-sso-sample.png
16+
:width: 70%
17+
:alt: Screenshot showing steps to create in a synthetic test that authenicates with SSO or Active Directory.
18+
19+
20+
Limitations
21+
======================================
22+
23+
Identity providers often require various additional factors for login, such as verification via email, SMS, or TOTP. In such cases, it is essential to modify or add steps to accommodate these additional login factors.
1224

1325

0 commit comments

Comments
 (0)