2024-06-10 08:29:40 +02:00
|
|
|
{ pkgs, lib, ... }:
|
|
|
|
let
|
|
|
|
pkgs' = pkgs;
|
|
|
|
|
|
|
|
subdomain = "d";
|
|
|
|
domain = "example.com";
|
|
|
|
|
2024-07-12 13:01:26 +02:00
|
|
|
testLib = pkgs.callPackage ../common.nix {};
|
|
|
|
|
2024-07-16 10:38:26 +02:00
|
|
|
commonTestScript = lib.makeOverridable testLib.accessScript {
|
|
|
|
inherit subdomain domain;
|
2024-07-12 13:01:26 +02:00
|
|
|
hasSSL = { node, ... }: !(isNull node.config.shb.deluge.ssl);
|
|
|
|
waitForServices = { ... }: [
|
|
|
|
"nginx.service"
|
|
|
|
"deluged.service"
|
|
|
|
"delugeweb.service"
|
|
|
|
];
|
|
|
|
waitForPorts = { node, ... }: [
|
|
|
|
node.config.shb.deluge.daemonPort
|
|
|
|
node.config.shb.deluge.webPort
|
|
|
|
];
|
2024-07-16 10:38:26 +02:00
|
|
|
extraScript = { node, proto_fqdn, ... }: ''
|
2024-07-12 13:01:26 +02:00
|
|
|
print(${node.name}.succeed('journalctl -n100 -u deluged'))
|
|
|
|
print(${node.name}.succeed('systemctl status deluged'))
|
|
|
|
print(${node.name}.succeed('systemctl status delugeweb'))
|
2024-06-10 08:29:40 +02:00
|
|
|
|
|
|
|
with subtest("web connect"):
|
2024-07-16 10:38:26 +02:00
|
|
|
print(server.succeed("cat ${node.config.services.deluge.dataDir}/.config/deluge/auth"))
|
|
|
|
|
2024-08-15 02:38:12 +02:00
|
|
|
response = curl(client, "", "${proto_fqdn}/json", extra = unline_with(" ", """
|
2024-07-16 10:38:26 +02:00
|
|
|
-H "Content-Type: application/json"
|
|
|
|
-H "Accept: application/json"
|
2024-08-15 02:38:12 +02:00
|
|
|
"""), data = unline_with(" ", """
|
2024-07-16 10:38:26 +02:00
|
|
|
{"method": "auth.login", "params": ["deluge"], "id": 1}
|
2024-08-15 02:38:12 +02:00
|
|
|
"""))
|
2024-06-10 08:29:40 +02:00
|
|
|
print(response)
|
2024-07-16 10:38:26 +02:00
|
|
|
if response['error']:
|
|
|
|
raise Exception(f"error is {response['error']}")
|
2024-06-10 08:29:40 +02:00
|
|
|
if not response['result']:
|
2024-07-16 10:38:26 +02:00
|
|
|
raise Exception(f"response is {response}")
|
|
|
|
|
2024-08-15 02:38:12 +02:00
|
|
|
response = curl(client, "", "${proto_fqdn}/json", extra = unline_with(" ", """
|
2024-07-16 10:38:26 +02:00
|
|
|
-H "Content-Type: application/json"
|
|
|
|
-H "Accept: application/json"
|
2024-08-15 02:38:12 +02:00
|
|
|
"""), data = unline_with(" ", """
|
2024-07-16 10:38:26 +02:00
|
|
|
{"method": "web.get_hosts", "params": [], "id": 1}
|
2024-08-15 02:38:12 +02:00
|
|
|
"""))
|
2024-06-10 08:29:40 +02:00
|
|
|
print(response)
|
2024-07-16 10:38:26 +02:00
|
|
|
if response['error']:
|
|
|
|
raise Exception(f"error is {response['error']}")
|
2024-06-10 08:29:40 +02:00
|
|
|
|
|
|
|
hostID = response['result'][0][0]
|
2024-08-15 02:38:12 +02:00
|
|
|
response = curl(client, "", "${proto_fqdn}/json", extra = unline_with(" ", """
|
2024-07-16 10:38:26 +02:00
|
|
|
-H "Content-Type: application/json"
|
|
|
|
-H "Accept: application/json"
|
2024-08-15 02:38:12 +02:00
|
|
|
"""), data = unline_with(" ", f"""
|
2024-07-16 10:38:26 +02:00
|
|
|
{{"method": "web.connect", "params": ["{hostID}"], "id": 1}}
|
2024-08-15 02:38:12 +02:00
|
|
|
"""))
|
2024-06-10 08:29:40 +02:00
|
|
|
print(response)
|
|
|
|
if response['error']:
|
|
|
|
raise Exception(f"result had an error {response['error']}")
|
|
|
|
'';
|
2024-07-16 10:38:26 +02:00
|
|
|
};
|
2024-06-10 08:29:40 +02:00
|
|
|
|
2024-06-10 08:30:14 +02:00
|
|
|
prometheusTestScript = { nodes, ... }:
|
|
|
|
''
|
|
|
|
server.wait_for_open_port(${toString nodes.server.services.prometheus.exporters.deluge.port})
|
|
|
|
with subtest("prometheus"):
|
|
|
|
response = server.succeed(
|
|
|
|
"curl -sSf "
|
|
|
|
+ " http://localhost:${toString nodes.server.services.prometheus.exporters.deluge.port}/metrics"
|
|
|
|
)
|
|
|
|
print(response)
|
|
|
|
'';
|
|
|
|
|
2024-07-16 10:38:26 +02:00
|
|
|
base = testLib.base pkgs' [
|
|
|
|
../../modules/services/deluge.nix
|
|
|
|
];
|
2024-06-10 08:29:40 +02:00
|
|
|
|
|
|
|
basic = { config, ... }: {
|
|
|
|
shb.deluge = {
|
|
|
|
enable = true;
|
|
|
|
inherit domain subdomain;
|
|
|
|
|
|
|
|
settings = {
|
|
|
|
downloadLocation = "/var/lib/deluge";
|
|
|
|
};
|
|
|
|
|
|
|
|
extraUsers = {
|
|
|
|
user.password.source = pkgs.writeText "userpw" "userpw";
|
|
|
|
};
|
|
|
|
|
|
|
|
localclientPasswordFile = pkgs.writeText "localclientpw" "localclientpw";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
prometheus = {
|
|
|
|
shb.deluge = {
|
|
|
|
prometheusScraperPasswordFile = pkgs.writeText "prompw" "prompw";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
https = { config, ...}: {
|
|
|
|
shb.deluge = {
|
|
|
|
ssl = config.shb.certs.certs.selfsigned.n;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
sso = { config, ... }: {
|
|
|
|
shb.deluge = {
|
|
|
|
authEndpoint = "https://${config.shb.authelia.subdomain}.${config.shb.authelia.domain}";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
in
|
|
|
|
{
|
|
|
|
basic = pkgs.testers.runNixOSTest {
|
|
|
|
name = "deluge_basic";
|
|
|
|
|
2024-07-16 10:38:26 +02:00
|
|
|
nodes.server = {
|
|
|
|
imports = [
|
|
|
|
base
|
|
|
|
basic
|
|
|
|
];
|
|
|
|
};
|
2024-06-10 08:29:40 +02:00
|
|
|
|
|
|
|
nodes.client = {};
|
|
|
|
|
2024-07-16 10:38:26 +02:00
|
|
|
testScript = commonTestScript;
|
2024-06-10 08:29:40 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
https = pkgs.testers.runNixOSTest {
|
|
|
|
name = "deluge_https";
|
|
|
|
|
2024-07-16 10:38:26 +02:00
|
|
|
nodes.server = {
|
|
|
|
imports = [
|
|
|
|
base
|
|
|
|
(testLib.certs domain)
|
|
|
|
basic
|
|
|
|
https
|
|
|
|
];
|
|
|
|
};
|
2024-06-10 08:29:40 +02:00
|
|
|
|
|
|
|
nodes.client = {};
|
|
|
|
|
2024-07-16 10:38:26 +02:00
|
|
|
testScript = commonTestScript;
|
2024-06-10 08:29:40 +02:00
|
|
|
};
|
|
|
|
|
2024-07-16 10:38:26 +02:00
|
|
|
sso = pkgs.testers.runNixOSTest {
|
|
|
|
name = "deluge_sso";
|
|
|
|
|
|
|
|
nodes.server = { config, ... }: {
|
|
|
|
imports = [
|
|
|
|
base
|
|
|
|
(testLib.certs domain)
|
|
|
|
basic
|
|
|
|
https
|
|
|
|
(testLib.ldap domain pkgs')
|
|
|
|
(testLib.sso domain pkgs' config.shb.certs.certs.selfsigned.n)
|
|
|
|
sso
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
|
|
|
nodes.client = {};
|
|
|
|
|
|
|
|
testScript = commonTestScript.override {
|
|
|
|
redirectSSO = true;
|
|
|
|
};
|
|
|
|
};
|
2024-06-10 08:30:14 +02:00
|
|
|
|
|
|
|
prometheus = pkgs.testers.runNixOSTest {
|
|
|
|
name = "deluge_https";
|
|
|
|
|
2024-07-16 10:38:26 +02:00
|
|
|
nodes.server = {
|
|
|
|
imports = [
|
|
|
|
base
|
|
|
|
(testLib.certs domain)
|
|
|
|
basic
|
|
|
|
https
|
|
|
|
prometheus
|
|
|
|
];
|
|
|
|
};
|
2024-06-10 08:30:14 +02:00
|
|
|
|
|
|
|
nodes.client = {};
|
|
|
|
|
|
|
|
testScript = inputs:
|
|
|
|
(commonTestScript inputs)
|
|
|
|
+ (prometheusTestScript inputs);
|
|
|
|
};
|
2024-06-10 08:29:40 +02:00
|
|
|
}
|