-
Notifications
You must be signed in to change notification settings - Fork 0
/
status.py
97 lines (71 loc) · 2.58 KB
/
status.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import requests
import os
import sys
import logging
from dotenv import load_dotenv
from selenium.webdriver import Firefox
from selenium.webdriver.firefox.service import Service
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions
from webdriver_manager.firefox import GeckoDriverManager
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
load_dotenv()
options = Options()
if os.environ.get("CI") != None:
options.headless = True
browser = Firefox(service=Service(GeckoDriverManager().install()), options=options)
browser.set_page_load_timeout(15)
def report():
logger.info("Reporting a status: {}".format(status))
requests.post(
"https://bitwardentest.hund.io/state_webhook/watchdog/61cd8a01386fb37c3d04b049",
headers={"X-WEBHOOK-KEY": os.environ.get("WEBHOOK_KEY")},
params={"status": status},
).raise_for_status()
def get(selector, or_else):
try:
return WebDriverWait(browser, 10).until(
expected_conditions.presence_of_element_located(selector)
)
except Exception as e:
logger.exception(e)
error(or_else)
def assertEqual(value, expected, or_else):
if value != expected:
error(or_else)
def error(or_else):
browser.save_screenshot("screenshot.png")
logger.info(or_else)
sys.exit(or_else)
try:
###### Outage ######
status = -1
browser.get("https://vault.bitwarden.com/#/")
assert browser.title == "Bitwarden Web Vault"
username = get((By.ID, "email"), "Couldn't get login email input")
username.send_keys(os.environ.get("EMAIL"))
password = get((By.ID, "masterPassword"), "Couldn't get login password input")
password.send_keys(os.environ.get("MASTER_PASSWORD"))
password.send_keys(Keys.RETURN)
###### Degradation ######
status = 0
an_item = get((By.LINK_TEXT, "Test item"), "Couldn't get the test item")
an_item.click()
item_username = get(
(By.ID, "loginUsername"), "Couldn't get the entry username"
).get_attribute("value")
item_password = get(
(By.ID, "loginPassword"), "Couldn't get the entry password"
).get_attribute("value")
assertEqual(item_username, "username", "Entry username did not match")
assertEqual(item_password, "password", "Entry password did not match")
###### Ok ######
status = 1
finally:
browser.quit()
report()
assert status == 1