at master 3.7 kB view raw
1{ lib, pkgs, ... }: 2 3let 4 certs = import ./common/acme/server/snakeoil-certs.nix; 5 inherit (certs) domain; 6 7 # this is a demo user created by IDM_CREATE_DEMO_USERS=true 8 demoUser = "alan"; 9 demoPassword = "demo"; 10 11 adminUser = "admin"; 12 adminPassword = "hunter2"; 13 testRunner = 14 pkgs.writers.writePython3Bin "test-runner" 15 { 16 libraries = [ pkgs.python3Packages.selenium ]; 17 flakeIgnore = [ "E501" ]; 18 } 19 '' 20 import sys 21 from selenium.webdriver.common.by import By 22 from selenium.webdriver import Firefox 23 from selenium.webdriver.firefox.options import Options 24 from selenium.webdriver.support.ui import WebDriverWait 25 from selenium.webdriver.support import expected_conditions as EC 26 27 options = Options() 28 options.add_argument('--headless') 29 driver = Firefox(options=options) 30 31 host = sys.argv[1] 32 user = sys.argv[2] 33 password = sys.argv[3] 34 35 driver.get(f"https://{host}/") 36 wait = WebDriverWait(driver, 60) 37 wait.until(EC.title_contains("Sign in")) 38 wait.until(EC.url_contains(f"https://{host}/signin/v1/identifier")) 39 wait.until(EC.visibility_of_element_located((By.ID, 'oc-login-username'))) 40 driver.find_element(By.ID, 'oc-login-username').send_keys(user) 41 driver.find_element(By.ID, 'oc-login-password').send_keys(password) 42 wait.until(EC.visibility_of_element_located((By.XPATH, '//button[@type="submit"]'))) 43 driver.find_element(By.XPATH, '//button[@type="submit"]').click() 44 wait.until(EC.visibility_of_element_located((By.ID, 'new-file-menu-btn'))) 45 wait.until(EC.title_contains("Personal")) 46 ''; 47in 48 49{ 50 name = "opencloud"; 51 52 meta.maintainers = with lib.maintainers; [ 53 christoph-heiss 54 k900 55 ]; 56 57 nodes.machine = { 58 virtualisation.memorySize = 2048; 59 environment.systemPackages = [ 60 pkgs.firefox-unwrapped 61 pkgs.geckodriver 62 testRunner 63 ]; 64 65 networking.hosts."127.0.0.1" = [ domain ]; 66 security.pki.certificateFiles = [ certs.ca.cert ]; 67 68 services.opencloud = { 69 enable = true; 70 url = "https://${domain}:9200"; 71 environment = { 72 ADMIN_PASSWORD = adminPassword; 73 IDM_CREATE_DEMO_USERS = "true"; 74 IDM_LDAPS_CERT = "${certs.${domain}.cert}"; 75 IDM_LDAPS_KEY = "${certs.${domain}.key}"; 76 OC_INSECURE = "false"; 77 OC_LDAP_URI = "ldaps://${domain}:9235"; 78 OC_LDAP_CACERT = "${certs.${domain}.cert}"; 79 OC_HTTP_TLS_ENABLED = "true"; 80 OC_HTTP_TLS_CERTIFICATE = "${certs.${domain}.cert}"; 81 OC_HTTP_TLS_KEY = "${certs.${domain}.key}"; 82 PROXY_TLS = "true"; 83 PROXY_TRANSPORT_TLS_CERT = "${certs.${domain}.cert}"; 84 PROXY_TRANSPORT_TLS_KEY = "${certs.${domain}.key}"; 85 PROXY_INSECURE_BACKENDS = "true"; 86 }; 87 }; 88 }; 89 90 testScript = '' 91 start_all() 92 machine.wait_for_unit("opencloud.service") 93 machine.wait_for_open_port(9200) 94 95 # wait for OpenCloud to fully come up 96 machine.sleep(10) 97 98 with subtest("opencloud bin works"): 99 machine.succeed("${lib.getExe pkgs.opencloud} version") 100 101 with subtest("web interface presents start page"): 102 machine.succeed("curl -sSf https://${domain}:9200 | grep '<title>OpenCloud</title>'") 103 104 with subtest("use the web interface to log in with the provisioned admin user"): 105 machine.succeed("PYTHONUNBUFFERED=1 systemd-cat -t test-runner test-runner ${domain}:9200 ${adminUser} ${adminPassword}") 106 107 with subtest("use the web interface to log in with a demo user"): 108 machine.succeed("PYTHONUNBUFFERED=1 systemd-cat -t test-runner test-runner ${domain}:9200 ${demoUser} ${demoPassword}") 109 ''; 110}