-
Notifications
You must be signed in to change notification settings - Fork 0
/
utility.js
81 lines (56 loc) · 1.84 KB
/
utility.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/* eslint-disable no-undef */
const readline = require('readline');
async function isHomePage(page) {
await page.waitForFunction(() => {
return window.location.href === "https://www.att.com/";
})
return "home";
}
async function isLoginPage(page) {
await page.waitForFunction(() => {
return window.location.href.startsWith("https://signin.att.com/dynamic/iamLRR/LrrController?IAM_OP=login");
})
return "login";
}
async function isMFAPage(page) {
await page.waitForFunction(() => {
return window.location.href.startsWith("https://signin.att.com/dynamic/iamLRR/LrrController?IAM_OP=OTP");
})
return "mfa";
}
async function isBillingPage(page) {
await page.waitForFunction(() => {
return window.location.href === "https://www.att.com/acctmgmt/billandpay";
})
return "billing";
}
async function getMFA(page, host) {
const [hostTile] = await page.$x(`//div[@id='radio-form-container']/div[contains(., '${host}')]`);
if (!hostTile) throw new Error("no host found in MFA!");
await hostTile.click();
await page.click("input#submitDest");
await page.waitForFunction(() => {
return !!document.querySelector("input#codeValue");
})
const mfaCode = await askQuestion("What's the MFA code from your phone? Enter:");
await page.focus("input#codeValue");
await page.keyboard.type(mfaCode);
await page.click("input#submitCodeButton");
function askQuestion(query) {
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
return new Promise(resolve => rl.question(`\u001b[1;36m${query}\u001b[0m`, ans => {
rl.close();
resolve(ans);
}))
}
}
module.exports = {
isHomePage,
isLoginPage,
isMFAPage,
isBillingPage,
getMFA,
}