1
0
Fork 0
selfhostblocks/test/services/deluge.nix

190 lines
4.7 KiB
Nix
Raw Normal View History

{ 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'))
with subtest("web connect"):
2024-07-16 10:38:26 +02:00
print(server.succeed("cat ${node.config.services.deluge.dataDir}/.config/deluge/auth"))
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"
"""), data = unline_with(" ", """
2024-07-16 10:38:26 +02:00
{"method": "auth.login", "params": ["deluge"], "id": 1}
"""))
print(response)
2024-07-16 10:38:26 +02:00
if response['error']:
raise Exception(f"error is {response['error']}")
if not response['result']:
2024-07-16 10:38:26 +02:00
raise Exception(f"response is {response}")
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"
"""), data = unline_with(" ", """
2024-07-16 10:38:26 +02:00
{"method": "web.get_hosts", "params": [], "id": 1}
"""))
print(response)
2024-07-16 10:38:26 +02:00
if response['error']:
raise Exception(f"error is {response['error']}")
hostID = response['result'][0][0]
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"
"""), data = unline_with(" ", f"""
2024-07-16 10:38:26 +02:00
{{"method": "web.connect", "params": ["{hostID}"], "id": 1}}
"""))
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: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
];
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
];
};
nodes.client = {};
2024-07-16 10:38:26 +02:00
testScript = commonTestScript;
};
https = pkgs.testers.runNixOSTest {
name = "deluge_https";
2024-07-16 10:38:26 +02:00
nodes.server = {
imports = [
base
(testLib.certs domain)
basic
https
];
};
nodes.client = {};
2024-07-16 10:38:26 +02:00
testScript = commonTestScript;
};
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);
};
}