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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
import ./make-test-python.nix ({ pkgs, lib, ... }: {
name = "filesender";
meta = {
maintainers = with lib.maintainers; [ nhnn ];
broken = pkgs.stdenv.hostPlatform.isAarch64; # selenium.common.exceptions.WebDriverException: Message: Unsupported platform/architecture combination: linux/aarch64
};
nodes.filesender = { ... }: let
format = pkgs.formats.php { };
in {
networking.firewall.allowedTCPPorts = [ 80 ];
services.filesender.enable = true;
services.filesender.localDomain = "filesender";
services.filesender.settings = {
auth_sp_saml_authentication_source = "default";
auth_sp_saml_uid_attribute = "uid";
storage_filesystem_path = "/tmp";
site_url = "http://filesender";
force_ssl = false;
admin = "";
admin_email = "admin@localhost";
email_reply_to = "noreply@localhost";
};
services.simplesamlphp.filesender = {
settings = {
baseurlpath = "http://filesender/saml";
"module.enable".exampleauth = true;
};
authSources = {
admin = [ "core:AdminPassword" ];
default = format.lib.mkMixedArray [ "exampleauth:UserPass" ] {
"user:password" = {
uid = [ "user" ];
cn = [ "user" ];
mail = [ "user@nixos.org" ];
};
};
};
};
};
nodes.client =
{ pkgs
, nodes
, ...
}:
let
filesenderIP = (builtins.head (nodes.filesender.networking.interfaces.eth1.ipv4.addresses)).address;
in
{
networking.hosts.${filesenderIP} = [ "filesender" ];
environment.systemPackages =
let
username = "user";
password = "password";
browser-test =
pkgs.writers.writePython3Bin "browser-test"
{
libraries = [ pkgs.python3Packages.selenium ];
flakeIgnore = [ "E124" "E501" ];
} ''
from selenium.webdriver.common.by import By
from selenium.webdriver import Firefox
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
from selenium.webdriver.firefox.service import Service
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from subprocess import STDOUT
import string
import random
import logging
import time
selenium_logger = logging.getLogger("selenium")
selenium_logger.setLevel(logging.DEBUG)
selenium_logger.addHandler(logging.StreamHandler())
profile = FirefoxProfile()
profile.set_preference("browser.download.folderList", 2)
profile.set_preference("browser.download.manager.showWhenStarting", False)
profile.set_preference("browser.download.dir", "/tmp/firefox")
profile.set_preference("browser.helperApps.neverAsk.saveToDisk", "text/plain;text/txt")
options = Options()
options.profile = profile
options.add_argument('--headless')
service = Service(log_output=STDOUT)
driver = Firefox(options=options)
driver.set_window_size(1024, 768)
driver.implicitly_wait(30)
driver.get('http://filesender/')
wait = WebDriverWait(driver, 20)
wait.until(EC.title_contains("FileSender"))
driver.find_element(By.ID, "btn_logon").click()
wait.until(EC.title_contains("Enter your username and password"))
driver.find_element(By.ID, 'username').send_keys(
'${username}'
)
driver.find_element(By.ID, 'password').send_keys(
'${password}'
)
driver.find_element(By.ID, "submit_button").click()
wait.until(EC.title_contains("FileSender"))
wait.until(EC.presence_of_element_located((By.ID, "topmenu_logoff")))
test_string = "".join(random.choices(string.ascii_uppercase + string.digits, k=20))
with open("/tmp/test_file.txt", "w") as file:
file.write(test_string)
driver.find_element(By.ID, "files").send_keys("/tmp/test_file.txt")
time.sleep(2)
driver.find_element(By.CSS_SELECTOR, '.start').click()
wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, ".download_link")))
download_link = driver.find_element(By.CSS_SELECTOR, '.download_link > textarea').get_attribute('value').strip()
driver.get(download_link)
wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, ".download")))
driver.find_element(By.CSS_SELECTOR, '.download').click()
wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, ".ui-dialog-buttonset > button:nth-child(2)")))
driver.find_element(By.CSS_SELECTOR, ".ui-dialog-buttonset > button:nth-child(2)").click()
driver.close()
driver.quit()
'';
in
[
pkgs.firefox-unwrapped
pkgs.geckodriver
browser-test
];
};
testScript = ''
start_all()
filesender.wait_for_file("/run/phpfpm/filesender.sock")
filesender.wait_for_open_port(80)
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"):
raise Exception("filesender returned invalid html")
client.succeed("browser-test")
'';
})
|