notes: 2.3.0 -> 2.3.1 (#352950)
[NixPkgs.git] / nixos / tests / filesender.nix
blob346e315956fb9aeb1437cfe69a24d2639bf360f3
1 import ./make-test-python.nix ({ pkgs, lib, ... }: {
2   name = "filesender";
3   meta = {
4     maintainers = with lib.maintainers; [ nhnn ];
5     broken = pkgs.stdenv.hostPlatform.isAarch64; # selenium.common.exceptions.WebDriverException: Message: Unsupported platform/architecture combination: linux/aarch64
6   };
8   nodes.filesender = { ... }: let
9     format = pkgs.formats.php { };
10   in {
11     networking.firewall.allowedTCPPorts = [ 80 ];
13     services.filesender.enable = true;
14     services.filesender.localDomain = "filesender";
15     services.filesender.settings = {
16       auth_sp_saml_authentication_source = "default";
17       auth_sp_saml_uid_attribute = "uid";
18       storage_filesystem_path = "/tmp";
19       site_url = "http://filesender";
20       force_ssl = false;
21       admin = "";
22       admin_email = "admin@localhost";
23       email_reply_to = "noreply@localhost";
24     };
25     services.simplesamlphp.filesender = {
26       settings = {
27         baseurlpath = "http://filesender/saml";
28         "module.enable".exampleauth = true;
29       };
30       authSources = {
31         admin = [ "core:AdminPassword" ];
32         default = format.lib.mkMixedArray [ "exampleauth:UserPass" ] {
33           "user:password" = {
34             uid = [ "user" ];
35             cn = [ "user" ];
36             mail = [ "user@nixos.org" ];
37           };
38         };
39       };
40     };
41   };
43   nodes.client =
44     { pkgs
45     , nodes
46     , ...
47     }:
48     let
49       filesenderIP = (builtins.head (nodes.filesender.networking.interfaces.eth1.ipv4.addresses)).address;
50     in
51     {
52       networking.hosts.${filesenderIP} = [ "filesender" ];
54       environment.systemPackages =
55         let
56           username = "user";
57           password = "password";
58           browser-test =
59             pkgs.writers.writePython3Bin "browser-test"
60               {
61                 libraries = [ pkgs.python3Packages.selenium ];
62                 flakeIgnore = [ "E124" "E501" ];
63               } ''
64               from selenium.webdriver.common.by import By
65               from selenium.webdriver import Firefox
66               from selenium.webdriver.firefox.options import Options
67               from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
68               from selenium.webdriver.firefox.service import Service
69               from selenium.webdriver.support.ui import WebDriverWait
70               from selenium.webdriver.support import expected_conditions as EC
71               from subprocess import STDOUT
72               import string
73               import random
74               import logging
75               import time
76               selenium_logger = logging.getLogger("selenium")
77               selenium_logger.setLevel(logging.DEBUG)
78               selenium_logger.addHandler(logging.StreamHandler())
79               profile = FirefoxProfile()
80               profile.set_preference("browser.download.folderList", 2)
81               profile.set_preference("browser.download.manager.showWhenStarting", False)
82               profile.set_preference("browser.download.dir", "/tmp/firefox")
83               profile.set_preference("browser.helperApps.neverAsk.saveToDisk", "text/plain;text/txt")
84               options = Options()
85               options.profile = profile
86               options.add_argument('--headless')
87               service = Service(log_output=STDOUT)
88               driver = Firefox(options=options)
89               driver.set_window_size(1024, 768)
90               driver.implicitly_wait(30)
91               driver.get('http://filesender/')
92               wait = WebDriverWait(driver, 20)
93               wait.until(EC.title_contains("FileSender"))
94               driver.find_element(By.ID, "btn_logon").click()
95               wait.until(EC.title_contains("Enter your username and password"))
96               driver.find_element(By.ID, 'username').send_keys(
97                   '${username}'
98               )
99               driver.find_element(By.ID, 'password').send_keys(
100                   '${password}'
101               )
102               driver.find_element(By.ID, "submit_button").click()
103               wait.until(EC.title_contains("FileSender"))
104               wait.until(EC.presence_of_element_located((By.ID, "topmenu_logoff")))
105               test_string = "".join(random.choices(string.ascii_uppercase + string.digits, k=20))
106               with open("/tmp/test_file.txt", "w") as file:
107                   file.write(test_string)
108               driver.find_element(By.ID, "files").send_keys("/tmp/test_file.txt")
109               time.sleep(2)
110               driver.find_element(By.CSS_SELECTOR, '.start').click()
111               wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, ".download_link")))
112               download_link = driver.find_element(By.CSS_SELECTOR, '.download_link > textarea').get_attribute('value').strip()
113               driver.get(download_link)
114               wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, ".download")))
115               driver.find_element(By.CSS_SELECTOR, '.download').click()
116               wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, ".ui-dialog-buttonset > button:nth-child(2)")))
117               driver.find_element(By.CSS_SELECTOR, ".ui-dialog-buttonset > button:nth-child(2)").click()
118               driver.close()
119               driver.quit()
120             '';
121         in
122         [
123           pkgs.firefox-unwrapped
124           pkgs.geckodriver
125           browser-test
126         ];
127     };
129   testScript = ''
130     start_all()
131     filesender.wait_for_file("/run/phpfpm/filesender.sock")
132     filesender.wait_for_open_port(80)
133     if "If you have received an invitation to access this site as a guest" not in client.wait_until_succeeds("curl -sS -f http://filesender"):
134       raise Exception("filesender returned invalid html")
135     client.succeed("browser-test")
136   '';