Skip to content

Commit 593fa72

Browse files
authored
nixos/tests/vaultwarden: fix UI testing (#408026)
2 parents 4279efe + 94e7e3f commit 593fa72

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

nixos/tests/vaultwarden.nix

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,17 @@ let
3636
from selenium.webdriver.firefox.options import Options
3737
from selenium.webdriver.support.ui import WebDriverWait
3838
from selenium.webdriver.support import expected_conditions as EC
39+
from selenium.common.exceptions import ElementClickInterceptedException
40+
41+
42+
def click_when_unobstructed(mark):
43+
while True:
44+
try:
45+
wait.until(EC.element_to_be_clickable(mark)).click()
46+
break
47+
except ElementClickInterceptedException:
48+
continue
49+
3950
4051
options = Options()
4152
options.add_argument('--headless')
@@ -74,7 +85,7 @@ let
7485
)
7586
driver.find_element(By.XPATH, "//button[contains(., 'Log in with master password')]").click()
7687
77-
wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, 'button#newItemDropdown'))).click()
88+
click_when_unobstructed((By.CSS_SELECTOR, 'button#newItemDropdown'))
7889
driver.find_element(By.XPATH, "//button[contains(., 'Item')]").click()
7990
8091
driver.find_element(By.CSS_SELECTOR, 'input#name').send_keys(
@@ -178,6 +189,8 @@ let
178189
testScript
179190
else
180191
''
192+
import json
193+
181194
start_all()
182195
server.wait_for_unit("vaultwarden.service")
183196
server.wait_for_open_port(8080)
@@ -202,11 +215,9 @@ let
202215
client.succeed(f"bw --nointeraction --raw --session {key} sync -f")
203216
204217
with subtest("get the password with the cli"):
205-
password = client.wait_until_succeeds(
206-
f"bw --nointeraction --raw --session {key} list items | ${pkgs.jq}/bin/jq -r .[].login.password",
207-
timeout=60
208-
)
209-
assert password.strip() == "${storedPassword}"
218+
output = json.loads(client.succeed(f"bw --nointeraction --raw --session {key} list items"))
219+
220+
assert output[0]['login']['password'] == "${storedPassword}"
210221
211222
with subtest("Check systemd unit hardening"):
212223
server.log(server.succeed("systemd-analyze security vaultwarden.service | grep -v ✓"))

0 commit comments

Comments
 (0)