From 94e7e3f3506249fc65c83b9c5879799eb685e1aa Mon Sep 17 00:00:00 2001 From: networkException Date: Sat, 17 May 2025 17:30:51 +0200 Subject: [PATCH] nixos/tests/vaultwarden: fix UI testing This patch fixes a failure in the Selenium UI testing script by waiting for an element to be clickable. This allows the Angular to render properly. --- nixos/tests/vaultwarden.nix | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/nixos/tests/vaultwarden.nix b/nixos/tests/vaultwarden.nix index c656e9ef1a06..ce1e1de21abe 100644 --- a/nixos/tests/vaultwarden.nix +++ b/nixos/tests/vaultwarden.nix @@ -36,6 +36,17 @@ let from selenium.webdriver.firefox.options import Options from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC + from selenium.common.exceptions import ElementClickInterceptedException + + + def click_when_unobstructed(mark): + while True: + try: + wait.until(EC.element_to_be_clickable(mark)).click() + break + except ElementClickInterceptedException: + continue + options = Options() options.add_argument('--headless') @@ -74,7 +85,7 @@ let ) driver.find_element(By.XPATH, "//button[contains(., 'Log in with master password')]").click() - wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, 'button#newItemDropdown'))).click() + click_when_unobstructed((By.CSS_SELECTOR, 'button#newItemDropdown')) driver.find_element(By.XPATH, "//button[contains(., 'Item')]").click() driver.find_element(By.CSS_SELECTOR, 'input#name').send_keys( @@ -178,6 +189,8 @@ let testScript else '' + import json + start_all() server.wait_for_unit("vaultwarden.service") server.wait_for_open_port(8080) @@ -202,11 +215,9 @@ let client.succeed(f"bw --nointeraction --raw --session {key} sync -f") with subtest("get the password with the cli"): - password = client.wait_until_succeeds( - f"bw --nointeraction --raw --session {key} list items | ${pkgs.jq}/bin/jq -r .[].login.password", - timeout=60 - ) - assert password.strip() == "${storedPassword}" + output = json.loads(client.succeed(f"bw --nointeraction --raw --session {key} list items")) + + assert output[0]['login']['password'] == "${storedPassword}" with subtest("Check systemd unit hardening"): server.log(server.succeed("systemd-analyze security vaultwarden.service | grep -v ✓"))