1
0
Fork 0

commonalize audiobookshelf tests

This commit is contained in:
ibizaman 2024-06-06 22:22:44 -07:00 committed by Pierre Penninckx
parent 121371716b
commit 30be3d1262

View file

@ -2,11 +2,15 @@
let let
pkgs' = pkgs; pkgs' = pkgs;
subdomain = "a";
domain = "example.com";
fqdn = "${subdomain}.${domain}";
# TODO: Test login # TODO: Test login
commonTestScript = { nodes, ... }: commonTestScript = { nodes, ... }:
let let
hasSSL = !(isNull nodes.server.shb.audiobookshelf.ssl); hasSSL = !(isNull nodes.server.shb.audiobookshelf.ssl);
fqdn = if hasSSL then "https://a.example.com" else "http://a.example.com"; proto_fqdn = if hasSSL then "https://${fqdn}" else "http://${fqdn}";
in in
'' ''
import json import json
@ -26,66 +30,38 @@ let
def curl(target, format, endpoint, succeed=True): def curl(target, format, endpoint, succeed=True):
return json.loads(target.succeed( return json.loads(target.succeed(
"curl --fail-with-body --silent --show-error --output /dev/null --location" "curl --fail-with-body --silent --show-error --output /dev/null --location"
+ " --connect-to a.example.com:443:server:443" + " --connect-to ${fqdn}:443:server:443"
+ " --connect-to a.example.com:80:server:80" + " --connect-to ${fqdn}:80:server:80"
+ f" --write-out '{format}'" + f" --write-out '{format}'"
+ " " + endpoint + " " + endpoint
)) ))
with subtest("access"): with subtest("access"):
response = curl(client, """{"code":%{response_code}}""", "${fqdn}") response = curl(client, """{"code":%{response_code}}""", "${proto_fqdn}")
if response['code'] != 200: if response['code'] != 200:
raise Exception(f"Code is {response['code']}") raise Exception(f"Code is {response['code']}")
''; '';
in
{
basic = pkgs.testers.runNixOSTest {
name = "audiobookshelf-basic";
nodes.server = { config, pkgs, ... }: { base = {
imports = [ imports = [
(pkgs'.path + "/nixos/modules/profiles/headless.nix") (pkgs'.path + "/nixos/modules/profiles/headless.nix")
(pkgs'.path + "/nixos/modules/profiles/qemu-guest.nix") (pkgs'.path + "/nixos/modules/profiles/qemu-guest.nix")
{ {
options = { options = {
shb.backup = lib.mkOption { type = lib.types.anything; }; shb.backup = lib.mkOption { type = lib.types.anything; };
shb.authelia = lib.mkOption { type = lib.types.anything; };
}; };
} }
../../modules/services/audiobookshelf.nix ../../modules/services/audiobookshelf.nix
]; ];
shb.audiobookshelf = {
enable = true;
domain = "example.com";
subdomain = "a";
};
# Nginx port. # Nginx port.
networking.firewall.allowedTCPPorts = [ 80 ]; networking.firewall.allowedTCPPorts = [ 80 443 ];
}; };
nodes.client = {}; certs = { config, ... }: {
testScript = commonTestScript;
};
cert = pkgs.testers.runNixOSTest {
name = "audiobookshelf-cert";
nodes.server = { config, pkgs, ... }: {
imports = [ imports = [
(pkgs'.path + "/nixos/modules/profiles/headless.nix")
(pkgs'.path + "/nixos/modules/profiles/qemu-guest.nix")
{
options = {
shb.backup = lib.mkOption { type = lib.types.anything; };
shb.authelia = lib.mkOption { type = lib.types.anything; };
};
}
../../modules/blocks/nginx.nix
../../modules/blocks/ssl.nix ../../modules/blocks/ssl.nix
../../modules/services/audiobookshelf.nix
]; ];
shb.certs = { shb.certs = {
@ -95,7 +71,7 @@ in
certs.selfsigned = { certs.selfsigned = {
n = { n = {
ca = config.shb.certs.cas.selfsigned.myca; ca = config.shb.certs.cas.selfsigned.myca;
domain = "*.example.com"; domain = "*.${domain}";
group = "nginx"; group = "nginx";
}; };
}; };
@ -103,46 +79,31 @@ in
systemd.services.nginx.after = [ config.shb.certs.certs.selfsigned.n.systemdService ]; systemd.services.nginx.after = [ config.shb.certs.certs.selfsigned.n.systemdService ];
systemd.services.nginx.requires = [ config.shb.certs.certs.selfsigned.n.systemdService ]; systemd.services.nginx.requires = [ config.shb.certs.certs.selfsigned.n.systemdService ];
};
basic = {
shb.audiobookshelf = { shb.audiobookshelf = {
enable = true; enable = true;
domain = "example.com"; inherit subdomain domain;
subdomain = "a"; };
};
https = { config, ... }: {
shb.audiobookshelf = {
ssl = config.shb.certs.certs.selfsigned.n; ssl = config.shb.certs.certs.selfsigned.n;
}; };
# Nginx port.
networking.firewall.allowedTCPPorts = [ 80 443 ];
shb.nginx.accessLog = true;
}; };
nodes.client = {}; sso = { config, ... }: {
testScript = commonTestScript;
};
sso = pkgs.testers.runNixOSTest {
name = "audiobookshelf-sso";
nodes.server = { config, pkgs, ... }: {
imports = [ imports = [
(pkgs'.path + "/nixos/modules/profiles/headless.nix")
(pkgs'.path + "/nixos/modules/profiles/qemu-guest.nix")
{
options = {
shb.backup = lib.mkOption { type = lib.types.anything; };
};
}
../../modules/blocks/authelia.nix ../../modules/blocks/authelia.nix
../../modules/blocks/ldap.nix ../../modules/blocks/ldap.nix
../../modules/blocks/postgresql.nix ../../modules/blocks/postgresql.nix
../../modules/blocks/ssl.nix
../../modules/services/audiobookshelf.nix
]; ];
shb.ldap = { shb.ldap = {
enable = true; enable = true;
domain = "example.com"; inherit domain;
subdomain = "ldap"; subdomain = "ldap";
ldapPort = 3890; ldapPort = 3890;
webUIListenPort = 17170; webUIListenPort = 17170;
@ -151,25 +112,9 @@ in
jwtSecretFile = pkgs.writeText "jwtSecret" "jwtSecret"; jwtSecretFile = pkgs.writeText "jwtSecret" "jwtSecret";
}; };
shb.certs = {
cas.selfsigned.myca = {
name = "My CA";
};
certs.selfsigned = {
n = {
ca = config.shb.certs.cas.selfsigned.myca;
domain = "*.example.com";
group = "nginx";
};
};
};
systemd.services.nginx.after = [ config.shb.certs.certs.selfsigned.n.systemdService ];
systemd.services.nginx.requires = [ config.shb.certs.certs.selfsigned.n.systemdService ];
shb.authelia = { shb.authelia = {
enable = true; enable = true;
domain = "example.com"; inherit domain;
subdomain = "auth"; subdomain = "auth";
ssl = config.shb.certs.certs.selfsigned.n; ssl = config.shb.certs.certs.selfsigned.n;
@ -190,17 +135,60 @@ in
}; };
shb.audiobookshelf = { shb.audiobookshelf = {
enable = true;
domain = "example.com";
subdomain = "a";
ssl = config.shb.certs.certs.selfsigned.n;
authEndpoint = "https://${config.shb.authelia.subdomain}.${config.shb.authelia.domain}"; authEndpoint = "https://${config.shb.authelia.subdomain}.${config.shb.authelia.domain}";
ssoSecretFile = pkgs.writeText "ssoSecretFile" "ssoSecretFile"; ssoSecretFile = pkgs.writeText "ssoSecretFile" "ssoSecretFile";
}; };
# Nginx port.
networking.firewall.allowedTCPPorts = [ 80 443 ];
}; };
in
{
basic = pkgs.testers.runNixOSTest {
name = "audiobookshelf-basic";
nodes.server = lib.mkMerge [
base
basic
{
options = {
shb.authelia = lib.mkOption { type = lib.types.anything; };
};
}
];
nodes.client = {};
testScript = commonTestScript;
};
https = pkgs.testers.runNixOSTest {
name = "audiobookshelf-https";
nodes.server = lib.mkMerge [
base
certs
basic
https
{
options = {
shb.authelia = lib.mkOption { type = lib.types.anything; };
};
}
];
nodes.client = {};
testScript = commonTestScript;
};
sso = pkgs.testers.runNixOSTest {
name = "audiobookshelf-sso";
nodes.server = lib.mkMerge [
base
certs
basic
https
sso
];
nodes.client = {}; nodes.client = {};