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

165 lines
4.6 KiB
Nix
Raw Normal View History

{ pkgs, lib, ... }:
let
2024-03-20 06:50:41 +01:00
pkgs' = pkgs;
2024-07-12 13:01:26 +02:00
domain = "example.com";
healthUrl = "/health";
loginUrl = "/UI/Login";
2024-07-12 13:01:26 +02:00
testLib = pkgs.callPackage ../common.nix {};
2024-07-12 13:01:26 +02:00
# TODO: Test login
commonTestScript = appname: cfgPathFn:
let
2024-07-16 10:38:26 +02:00
subdomain = appname;
fqdn = "${subdomain}.${domain}";
2024-07-16 11:23:57 +02:00
in lib.makeOverridable testLib.accessScript {
2024-07-16 10:38:26 +02:00
inherit subdomain domain;
2024-07-12 13:01:26 +02:00
hasSSL = { node, ... }: !(isNull node.config.shb.arr.${appname}.ssl);
waitForServices = { ... }: [
"${appname}.service"
"nginx.service"
];
waitForPorts = { node, ... }: [
node.config.shb.arr.${appname}.settings.Port
];
extraScript = { node, proto_fqdn, ... }: let
shbapp = node.config.shb.arr.${appname};
cfgPath = cfgPathFn shbapp;
apiKey = if (shbapp.settings ? ApiKey) then "01234567890123456789" else null;
in ''
2024-07-16 11:23:57 +02:00
# These curl requests still return a 200 even with sso redirect.
2024-07-12 13:01:26 +02:00
with subtest("health"):
response = curl(client, """{"code":%{response_code}}""", "${fqdn}${healthUrl}")
2024-07-16 11:23:57 +02:00
print("response =", response)
2024-07-12 13:01:26 +02:00
if response['code'] != 200:
raise Exception(f"Code is {response['code']}")
2024-07-12 13:01:26 +02:00
with subtest("login"):
response = curl(client, """{"code":%{response_code}}""", "${fqdn}${loginUrl}")
2024-07-12 13:01:26 +02:00
if response['code'] != 200:
raise Exception(f"Code is {response['code']}")
'' + lib.optionalString (apiKey != null) ''
2024-07-12 13:01:26 +02:00
with subtest("apikey"):
config = server.succeed("cat ${cfgPath}")
if "${apiKey}" not in config:
raise Exception(f"Unexpected API Key. Want '${apiKey}', got '{config}'")
'';
};
2024-07-16 10:38:26 +02:00
base = testLib.base pkgs' [
../../modules/services/arr.nix
];
basic = appname: { ... }: {
shb.arr.${appname} = {
enable = true;
inherit domain;
subdomain = appname;
settings.ApiKey.source = pkgs.writeText "APIKey" "01234567890123456789"; # Needs to be >=20 characters.
};
};
basicTest = appname: cfgPathFn: pkgs.testers.runNixOSTest {
2024-07-16 11:23:57 +02:00
name = "arr_${appname}_basic";
nodes.server = { config, pkgs, ... }: {
imports = [
2024-07-16 10:38:26 +02:00
base
(basic appname)
];
2024-07-16 10:38:26 +02:00
};
2024-07-16 10:38:26 +02:00
nodes.client = {};
testScript = commonTestScript appname cfgPathFn;
};
2024-07-16 10:38:26 +02:00
https = appname: { config, ...}: {
shb.arr.${appname} = {
ssl = config.shb.certs.certs.selfsigned.n;
};
};
httpsTest = appname: cfgPathFn: pkgs.testers.runNixOSTest {
2024-07-16 11:23:57 +02:00
name = "arr_${appname}_https";
2024-07-16 10:38:26 +02:00
nodes.server = { config, pkgs, ... }: {
imports = [
base
(testLib.certs domain)
2024-07-16 11:23:57 +02:00
(basic appname)
2024-07-16 10:38:26 +02:00
(https appname)
];
};
nodes.client = {};
testScript = commonTestScript appname cfgPathFn;
};
2024-07-16 10:38:26 +02:00
2024-07-16 11:23:57 +02:00
sso = appname: { config, ...}: {
shb.arr.${appname} = {
authEndpoint = "https://${config.shb.authelia.subdomain}.${config.shb.authelia.domain}";
};
};
ssoTest = appname: cfgPathFn: pkgs.testers.runNixOSTest {
name = "arr_${appname}_sso";
nodes.server = { config, pkgs, ... }: {
imports = [
base
(testLib.certs domain)
(basic appname)
(https appname)
(testLib.ldap domain pkgs')
(testLib.sso domain pkgs' config.shb.certs.certs.selfsigned.n)
(sso appname)
];
};
nodes.client = {};
testScript = (commonTestScript appname cfgPathFn).override {
redirectSSO = true;
};
};
2024-07-16 10:38:26 +02:00
radarrCfgFn = cfg: "${cfg.dataDir}/config.xml";
sonarrCfgFn = cfg: "${cfg.dataDir}/config.xml";
bazarrCfgFn = cfg: "/var/lib/bazarr/config.xml";
readarrCfgFn = cfg: "${cfg.dataDir}/config.xml";
lidarrCfgFn = cfg: "${cfg.dataDir}/config.xml";
jackettCfgFn = cfg: "${cfg.dataDir}/ServerConfig.json";
in
{
2024-07-16 10:38:26 +02:00
radarr_basic = basicTest "radarr" radarrCfgFn;
radarr_https = httpsTest "radarr" radarrCfgFn;
2024-07-16 11:23:57 +02:00
radarr_sso = ssoTest "radarr" radarrCfgFn;
2024-07-16 10:38:26 +02:00
sonarr_basic = basicTest "sonarr" sonarrCfgFn;
sonarr_https = httpsTest "sonarr" sonarrCfgFn;
2024-07-16 11:23:57 +02:00
sonarr_sso = ssoTest "sonarr" sonarrCfgFn;
2024-07-16 10:38:26 +02:00
bazarr_basic = basicTest "bazarr" bazarrCfgFn;
bazarr_https = httpsTest "bazarr" bazarrCfgFn;
2024-07-16 11:23:57 +02:00
bazarr_sso = ssoTest "bazarr" bazarrCfgFn;
2024-07-16 10:38:26 +02:00
readarr_basic = basicTest "readarr" readarrCfgFn;
readarr_https = httpsTest "readarr" readarrCfgFn;
2024-07-16 11:23:57 +02:00
readarr_sso = ssoTest "readarr" readarrCfgFn;
2024-07-16 10:38:26 +02:00
lidarr_basic = basicTest "lidarr" lidarrCfgFn;
lidarr_https = httpsTest "lidarr" lidarrCfgFn;
2024-07-16 11:23:57 +02:00
lidarr_sso = ssoTest "lidarr" lidarrCfgFn;
2024-07-16 10:38:26 +02:00
jackett_basic = basicTest "jackett" jackettCfgFn;
jackett_https = httpsTest "jackett" jackettCfgFn;
2024-07-16 11:23:57 +02:00
jackett_sso = ssoTest "jackett" jackettCfgFn;
}