This repository has been archived by the owner on Nov 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
selenium_eduvpn.py
70 lines (54 loc) · 1.81 KB
/
selenium_eduvpn.py
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
import os
import sys
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.firefox.options import Options
def login_eduvpn(authURL):
options = Options()
options.add_argument("-headless")
driver = webdriver.Firefox(options=options)
login_oauth(driver, authURL)
# Cleanup
driver.close()
# Logs in to the default vpn user portal with selenium
def login_oauth(driver, authURL):
# Go to the oauth url and verify the title
driver.get(authURL)
print(driver.title)
assert "VPN Portal - Sign In" in driver.title
# Get credentials
portal_user = os.getenv("PORTAL_USER")
if portal_user is None:
print("Error: No portal username set, set the PORTAL_USER env var")
sys.exit(1)
portal_pass = os.getenv("PORTAL_PASS")
if portal_pass is None:
print("Error: No portal password set, set the PORTAL_PASS env var")
sys.exit(1)
# Fill in username
elem = driver.find_element("name", "userName")
elem.clear()
elem.send_keys(portal_user)
# Fill in password
elem = driver.find_element("name", "userPass")
elem.clear()
elem.send_keys(portal_pass)
# Click login button
driver.find_element(
"css selector", ".frm > fieldset:nth-child(2) > button:nth-child(2)"
).click()
# Check that we have reached the approve application page
print(driver.title)
assert "VPN Portal - Approve Application" in driver.title
# Click approve
driver.find_element(
"css selector", ".frm > fieldset:nth-child(1) > button:nth-child(1)"
).click()
if __name__ == "__main__":
# Invalid arguments
if len(sys.argv) != 2:
print("Error: no auth url specified")
sys.exit(1)
# Login to the portal
authURL = sys.argv[1]
login_eduvpn(authURL)