refactor domain and subdomain vars in tests

This commit is contained in:
ibizaman 2025-01-23 20:29:34 +01:00 committed by Pierre Penninckx
parent 441907b134
commit 072979fce2
12 changed files with 188 additions and 180 deletions

View file

@ -1,5 +1,8 @@
{ pkgs, lib }: { pkgs, lib }:
let let
inherit (lib) mkOption;
inherit (lib.types) str;
baseImports = { baseImports = {
imports = [ imports = [
(pkgs.path + "/nixos/modules/profiles/headless.nix") (pkgs.path + "/nixos/modules/profiles/headless.nix")
@ -8,9 +11,7 @@ let
}; };
accessScript = lib.makeOverridable ({ accessScript = lib.makeOverridable ({
subdomain hasSSL
, domain
, hasSSL
, waitForServices ? s: [] , waitForServices ? s: []
, waitForPorts ? p: [] , waitForPorts ? p: []
, waitForUnixSocket ? u: [] , waitForUnixSocket ? u: []
@ -18,13 +19,15 @@ let
, redirectSSO ? false , redirectSSO ? false
}: { nodes, ... }: }: { nodes, ... }:
let let
fqdn = "${subdomain}.${domain}"; cfg = nodes.server.test;
fqdn = "${cfg.subdomain}.${cfg.domain}";
proto_fqdn = if hasSSL args then "https://${fqdn}" else "http://${fqdn}"; proto_fqdn = if hasSSL args then "https://${fqdn}" else "http://${fqdn}";
args = { args = {
node.name = "server"; node.name = "server";
node.config = nodes.server; node.config = nodes.server;
inherit proto_fqdn; inherit fqdn proto_fqdn;
}; };
in in
'' ''
@ -36,7 +39,7 @@ let
'' ''
+ lib.strings.concatMapStrings (s: ''server.wait_for_unit("${s}")'' + "\n") ( + lib.strings.concatMapStrings (s: ''server.wait_for_unit("${s}")'' + "\n") (
waitForServices args waitForServices args
++ (lib.optionals redirectSSO [ "authelia-auth.${domain}.service" ]) ++ (lib.optionals redirectSSO [ "authelia-auth.${cfg.domain}.service" ])
) )
+ lib.strings.concatMapStrings (p: ''server.wait_for_open_port(${toString p})'' + "\n") ( + lib.strings.concatMapStrings (p: ''server.wait_for_open_port(${toString p})'' + "\n") (
waitForPorts args waitForPorts args
@ -57,7 +60,7 @@ let
+ " --connect-to ${fqdn}:443:server:443" + " --connect-to ${fqdn}:443:server:443"
+ " --connect-to ${fqdn}:80:server:80" + " --connect-to ${fqdn}:80:server:80"
# Client must be able to resolve talking to auth server # Client must be able to resolve talking to auth server
+ " --connect-to auth.${domain}:443:server:443" + " --connect-to auth.${cfg.domain}:443:server:443"
+ (f" --data '{data}'" if data != "" else "") + (f" --data '{data}'" if data != "" else "")
+ (f" --silent --output /dev/null --write-out '{format}'" if format != "" else "") + (f" --silent --output /dev/null --write-out '{format}'" if format != "" else "")
+ (f" {extra}" if extra != "" else "") + (f" {extra}" if extra != "" else "")
@ -83,8 +86,8 @@ let
if response['code'] != 200: if response['code'] != 200:
raise Exception(f"Code is {response['code']}") raise Exception(f"Code is {response['code']}")
if response['auth_host'] != "auth.${domain}": if response['auth_host'] != "auth.${cfg.domain}":
raise Exception(f"auth host should be auth.${domain} but is {response['auth_host']}") raise Exception(f"auth host should be auth.${cfg.domain} but is {response['auth_host']}")
if response['auth_query'] != "rd=${proto_fqdn}/": if response['auth_query'] != "rd=${proto_fqdn}/":
raise Exception(f"auth query should be rd=${proto_fqdn}/ but is {response['auth_query']}") raise Exception(f"auth query should be rd=${proto_fqdn}/ but is {response['auth_query']}")
'' ''
@ -114,18 +117,32 @@ in
backup = backupScript args; backup = backupScript args;
}; };
baseModule = { baseModule = { config, ... }: {
imports = options.test = {
[ domain = mkOption {
baseImports type = str;
../modules/blocks/postgresql.nix default = "example.com";
../modules/blocks/authelia.nix };
../modules/blocks/nginx.nix subdomain = mkOption {
../modules/blocks/hardcodedsecret.nix type = str;
]; };
fqdn = mkOption {
# HTTP(s) server port. type = str;
networking.firewall.allowedTCPPorts = [ 80 443 ]; readOnly = true;
default = "${config.test.subdomain}.${config.test.domain}";
};
};
imports = [
baseImports
../modules/blocks/postgresql.nix
../modules/blocks/authelia.nix
../modules/blocks/nginx.nix
../modules/blocks/hardcodedsecret.nix
];
config = {
# HTTP(s) server port.
networking.firewall.allowedTCPPorts = [ 80 443 ];
};
}; };
backup = backupOption: { config, ... }: { backup = backupOption: { config, ... }: {
@ -152,7 +169,7 @@ in
}; };
}; };
certs = domain: { config, ... }: { certs = { config, ... }: {
imports = [ imports = [
../modules/blocks/ssl.nix ../modules/blocks/ssl.nix
]; ];
@ -164,7 +181,7 @@ in
certs.selfsigned = { certs.selfsigned = {
n = { n = {
ca = config.shb.certs.cas.selfsigned.myca; ca = config.shb.certs.cas.selfsigned.myca;
domain = "*.${domain}"; domain = "*.${config.test.domain}";
group = "nginx"; group = "nginx";
}; };
}; };
@ -174,13 +191,13 @@ in
systemd.services.nginx.requires = [ config.shb.certs.certs.selfsigned.n.systemdService ]; systemd.services.nginx.requires = [ config.shb.certs.certs.selfsigned.n.systemdService ];
}; };
ldap = domain: pkgs: { config, ... }: { ldap = pkgs: { config, ... }: {
imports = [ imports = [
../modules/blocks/ldap.nix ../modules/blocks/ldap.nix
]; ];
networking.hosts = { networking.hosts = {
"127.0.0.1" = [ "ldap.${domain}" ]; "127.0.0.1" = [ "ldap.${config.test.domain}" ];
}; };
shb.hardcodedsecret.ldapUserPassword = { shb.hardcodedsecret.ldapUserPassword = {
@ -194,7 +211,7 @@ in
shb.ldap = { shb.ldap = {
enable = true; enable = true;
inherit domain; inherit (config.test) domain;
subdomain = "ldap"; subdomain = "ldap";
ldapPort = 3890; ldapPort = 3890;
webUIListenPort = 17170; webUIListenPort = 17170;
@ -204,18 +221,18 @@ in
}; };
}; };
sso = domain: pkgs: ssl: { config, ... }: { sso = pkgs: ssl: { config, ... }: {
imports = [ imports = [
../modules/blocks/authelia.nix ../modules/blocks/authelia.nix
]; ];
networking.hosts = { networking.hosts = {
"127.0.0.1" = [ "auth.${domain}" ]; "127.0.0.1" = [ "auth.${config.test.domain}" ];
}; };
shb.authelia = { shb.authelia = {
enable = true; enable = true;
inherit domain; inherit (config.test) domain;
subdomain = "auth"; subdomain = "auth";
ssl = config.shb.certs.certs.selfsigned.n; ssl = config.shb.certs.certs.selfsigned.n;

View file

@ -2,59 +2,56 @@
let let
pkgs' = pkgs; pkgs' = pkgs;
domain = "example.com";
healthUrl = "/health"; healthUrl = "/health";
loginUrl = "/UI/Login"; loginUrl = "/UI/Login";
testLib = pkgs.callPackage ../common.nix {}; testLib = pkgs.callPackage ../common.nix {};
# TODO: Test login # TODO: Test login
commonTestScript = appname: cfgPathFn: commonTestScript = appname: cfgPathFn: testLib.mkScripts {
let 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, fqdn, proto_fqdn, ... }: let
shbapp = node.config.shb.arr.${appname};
cfgPath = cfgPathFn shbapp;
apiKey = if (shbapp.settings ? ApiKey) then "01234567890123456789" else null;
in ''
# These curl requests still return a 200 even with sso redirect.
with subtest("health"):
response = curl(client, """{"code":%{response_code}}""", "${fqdn}${healthUrl}")
print("response =", response)
if response['code'] != 200:
raise Exception(f"Code is {response['code']}")
with subtest("login"):
response = curl(client, """{"code":%{response_code}}""", "${fqdn}${loginUrl}")
if response['code'] != 200:
raise Exception(f"Code is {response['code']}")
'' + lib.optionalString (apiKey != null) ''
with subtest("apikey"):
config = server.succeed("cat ${cfgPath}")
if "${apiKey}" not in config:
raise Exception(f"Unexpected API Key. Want '${apiKey}', got '{config}'")
'';
};
basic = appname: { config, ... }: {
test = {
subdomain = appname; subdomain = appname;
fqdn = "${subdomain}.${domain}";
in testLib.mkScripts {
inherit subdomain domain;
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 ''
# These curl requests still return a 200 even with sso redirect.
with subtest("health"):
response = curl(client, """{"code":%{response_code}}""", "${fqdn}${healthUrl}")
print("response =", response)
if response['code'] != 200:
raise Exception(f"Code is {response['code']}")
with subtest("login"):
response = curl(client, """{"code":%{response_code}}""", "${fqdn}${loginUrl}")
if response['code'] != 200:
raise Exception(f"Code is {response['code']}")
'' + lib.optionalString (apiKey != null) ''
with subtest("apikey"):
config = server.succeed("cat ${cfgPath}")
if "${apiKey}" not in config:
raise Exception(f"Unexpected API Key. Want '${apiKey}', got '{config}'")
'';
}; };
basic = appname: { ... }: {
shb.arr.${appname} = { shb.arr.${appname} = {
enable = true; enable = true;
inherit domain; inherit (config.test) subdomain domain;
subdomain = appname;
settings.ApiKey.source = pkgs.writeText "APIKey" "01234567890123456789"; # Needs to be >=20 characters. settings.ApiKey.source = pkgs.writeText "APIKey" "01234567890123456789"; # Needs to be >=20 characters.
}; };
@ -106,7 +103,7 @@ let
imports = [ imports = [
testLib.baseModule testLib.baseModule
../../modules/services/arr.nix ../../modules/services/arr.nix
(testLib.certs domain) testLib.certs
(basic appname) (basic appname)
(https appname) (https appname)
]; ];
@ -130,11 +127,11 @@ let
imports = [ imports = [
testLib.baseModule testLib.baseModule
../../modules/services/arr.nix ../../modules/services/arr.nix
(testLib.certs domain) testLib.certs
(basic appname) (basic appname)
(https appname) (https appname)
(testLib.ldap domain pkgs') (testLib.ldap pkgs')
(testLib.sso domain pkgs' config.shb.certs.certs.selfsigned.n) (testLib.sso pkgs' config.shb.certs.certs.selfsigned.n)
(sso appname) (sso appname)
]; ];
}; };

View file

@ -1,15 +1,10 @@
{ pkgs, lib, ... }: { pkgs, ... }:
let let
pkgs' = pkgs; pkgs' = pkgs;
testLib = pkgs.callPackage ../common.nix {}; testLib = pkgs.callPackage ../common.nix {};
subdomain = "a";
domain = "example.com";
fqdn = "${subdomain}.${domain}";
commonTestScript = testLib.accessScript { commonTestScript = testLib.accessScript {
inherit subdomain domain;
hasSSL = { node, ... }: !(isNull node.config.shb.audiobookshelf.ssl); hasSSL = { node, ... }: !(isNull node.config.shb.audiobookshelf.ssl);
waitForServices = { ... }: [ waitForServices = { ... }: [
"audiobookshelf.service" "audiobookshelf.service"
@ -23,10 +18,13 @@ let
# ''; # '';
}; };
basic = { basic = { config, ... }: {
test = {
subdomain = "a";
};
shb.audiobookshelf = { shb.audiobookshelf = {
enable = true; enable = true;
inherit subdomain domain; inherit (config.test) subdomain domain;
}; };
}; };
@ -72,7 +70,7 @@ in
imports = [ imports = [
testLib.baseModule testLib.baseModule
../../modules/services/audiobookshelf.nix ../../modules/services/audiobookshelf.nix
(testLib.certs domain) testLib.certs
basic basic
https https
]; ];
@ -90,11 +88,11 @@ in
imports = [ imports = [
testLib.baseModule testLib.baseModule
../../modules/services/audiobookshelf.nix ../../modules/services/audiobookshelf.nix
(testLib.certs domain) testLib.certs
basic basic
https https
(testLib.ldap domain pkgs') (testLib.ldap pkgs')
(testLib.sso domain pkgs' config.shb.certs.certs.selfsigned.n) (testLib.sso pkgs' config.shb.certs.certs.selfsigned.n)
sso sso
]; ];
}; };

View file

@ -1,14 +1,10 @@
{ pkgs, lib, ... }: { pkgs, ... }:
let let
pkgs' = pkgs; pkgs' = pkgs;
subdomain = "d";
domain = "example.com";
testLib = pkgs.callPackage ../common.nix {}; testLib = pkgs.callPackage ../common.nix {};
commonTestScript = testLib.mkScripts { commonTestScript = testLib.mkScripts {
inherit subdomain domain;
hasSSL = { node, ... }: !(isNull node.config.shb.deluge.ssl); hasSSL = { node, ... }: !(isNull node.config.shb.deluge.ssl);
waitForServices = { ... }: [ waitForServices = { ... }: [
"nginx.service" "nginx.service"
@ -74,9 +70,13 @@ let
''; '';
basic = { config, ... }: { basic = { config, ... }: {
test = {
subdomain = "d";
};
shb.deluge = { shb.deluge = {
enable = true; enable = true;
inherit domain subdomain; inherit (config.test) domain subdomain;
settings = { settings = {
downloadLocation = "/var/lib/deluge"; downloadLocation = "/var/lib/deluge";
@ -160,7 +160,7 @@ in
testLib.baseModule testLib.baseModule
../../modules/blocks/hardcodedsecret.nix ../../modules/blocks/hardcodedsecret.nix
../../modules/services/deluge.nix ../../modules/services/deluge.nix
(testLib.certs domain) testLib.certs
basic basic
https https
]; ];
@ -179,11 +179,11 @@ in
testLib.baseModule testLib.baseModule
../../modules/blocks/hardcodedsecret.nix ../../modules/blocks/hardcodedsecret.nix
../../modules/services/deluge.nix ../../modules/services/deluge.nix
(testLib.certs domain) testLib.certs
basic basic
https https
(testLib.ldap domain pkgs') (testLib.ldap pkgs')
(testLib.sso domain pkgs' config.shb.certs.certs.selfsigned.n) (testLib.sso pkgs' config.shb.certs.certs.selfsigned.n)
sso sso
]; ];
}; };
@ -203,7 +203,7 @@ in
testLib.baseModule testLib.baseModule
../../modules/blocks/hardcodedsecret.nix ../../modules/blocks/hardcodedsecret.nix
../../modules/services/deluge.nix ../../modules/services/deluge.nix
(testLib.certs domain) testLib.certs
basic basic
https https
prometheus prometheus

View file

@ -4,13 +4,9 @@ let
testLib = pkgs.callPackage ../common.nix {}; testLib = pkgs.callPackage ../common.nix {};
subdomain = "f";
domain = "example.com";
adminPassword = "AdminPassword"; adminPassword = "AdminPassword";
commonTestScript = testLib.mkScripts { commonTestScript = testLib.mkScripts {
inherit subdomain domain;
hasSSL = { node, ... }: !(isNull node.config.shb.forgejo.ssl); hasSSL = { node, ... }: !(isNull node.config.shb.forgejo.ssl);
waitForServices = { ... }: [ waitForServices = { ... }: [
"forgejo.service" "forgejo.service"
@ -26,9 +22,13 @@ let
}; };
basic = { config, ... }: { basic = { config, ... }: {
test = {
subdomain = "f";
};
shb.forgejo = { shb.forgejo = {
enable = true; enable = true;
inherit domain subdomain; inherit (config.test) subdomain domain;
adminPassword.result = config.shb.hardcodedsecret.forgejoAdminPassword.result; adminPassword.result = config.shb.hardcodedsecret.forgejoAdminPassword.result;
databasePassword.result = config.shb.hardcodedsecret.forgejoDatabasePassword.result; databasePassword.result = config.shb.hardcodedsecret.forgejoDatabasePassword.result;
@ -36,7 +36,7 @@ let
# Needed for gitea-runner-local to be able to ping forgejo. # Needed for gitea-runner-local to be able to ping forgejo.
networking.hosts = { networking.hosts = {
"127.0.0.1" = [ "${subdomain}.${domain}" ]; "127.0.0.1" = [ "${config.test.subdomain}.${config.test.domain}" ];
}; };
shb.hardcodedsecret.forgejoAdminPassword = { shb.hardcodedsecret.forgejoAdminPassword = {
@ -135,7 +135,7 @@ in
imports = [ imports = [
testLib.baseModule testLib.baseModule
../../modules/services/forgejo.nix ../../modules/services/forgejo.nix
(testLib.certs domain) testLib.certs
basic basic
https https
]; ];
@ -154,7 +154,7 @@ in
testLib.baseModule testLib.baseModule
../../modules/services/forgejo.nix ../../modules/services/forgejo.nix
basic basic
(testLib.ldap domain pkgs') (testLib.ldap pkgs')
ldap ldap
]; ];
}; };
@ -171,11 +171,11 @@ in
imports = [ imports = [
testLib.baseModule testLib.baseModule
../../modules/services/forgejo.nix ../../modules/services/forgejo.nix
(testLib.certs domain) testLib.certs
basic basic
https https
(testLib.ldap domain pkgs') (testLib.ldap pkgs')
(testLib.sso domain pkgs' config.shb.certs.certs.selfsigned.n) (testLib.sso pkgs' config.shb.certs.certs.selfsigned.n)
sso sso
]; ];
}; };

View file

@ -1,15 +1,8 @@
{ pkgs, lib, ... }: { pkgs, lib, ... }:
let let
pkgs' = pkgs;
testLib = pkgs.callPackage ../common.nix {}; testLib = pkgs.callPackage ../common.nix {};
subdomain = "g";
domain = "example.com";
fqdn = "${subdomain}.${domain}";
commonTestScript = lib.makeOverridable testLib.accessScript { commonTestScript = lib.makeOverridable testLib.accessScript {
inherit subdomain domain;
hasSSL = { node, ... }: !(isNull node.config.shb.grocy.ssl); hasSSL = { node, ... }: !(isNull node.config.shb.grocy.ssl);
waitForServices = { ... }: [ waitForServices = { ... }: [
"phpfpm-grocy.service" "phpfpm-grocy.service"
@ -24,9 +17,13 @@ let
}; };
basic = { config, ... }: { basic = { config, ... }: {
test = {
subdomain = "g";
};
shb.grocy = { shb.grocy = {
enable = true; enable = true;
inherit domain subdomain; inherit (config.test) subdomain domain;
}; };
}; };
@ -60,7 +57,7 @@ in
imports = [ imports = [
testLib.baseModule testLib.baseModule
../../modules/services/grocy.nix ../../modules/services/grocy.nix
(testLib.certs domain) testLib.certs
basic basic
https https
]; ];

View file

@ -4,13 +4,9 @@ let
testLib = pkgs.callPackage ../common.nix {}; testLib = pkgs.callPackage ../common.nix {};
subdomain = "h";
domain = "example.com";
adminPassword = "AdminPassword"; adminPassword = "AdminPassword";
commonTestScript = testLib.mkScripts { commonTestScript = testLib.mkScripts {
inherit subdomain domain;
hasSSL = { node, ... }: !(isNull node.config.shb.hledger.ssl); hasSSL = { node, ... }: !(isNull node.config.shb.hledger.ssl);
waitForServices = { ... }: [ waitForServices = { ... }: [
"hledger-web.service" "hledger-web.service"
@ -19,9 +15,13 @@ let
}; };
basic = { config, ... }: { basic = { config, ... }: {
test = {
subdomain = "h";
};
shb.hledger = { shb.hledger = {
enable = true; enable = true;
inherit domain subdomain; inherit (config.test) subdomain domain;
}; };
}; };
@ -78,7 +78,7 @@ in
imports = [ imports = [
testLib.baseModule testLib.baseModule
../../modules/services/hledger.nix ../../modules/services/hledger.nix
(testLib.certs domain) testLib.certs
basic basic
https https
]; ];
@ -96,11 +96,11 @@ in
imports = [ imports = [
testLib.baseModule testLib.baseModule
../../modules/services/hledger.nix ../../modules/services/hledger.nix
(testLib.certs domain) testLib.certs
basic basic
https https
(testLib.ldap domain pkgs') (testLib.ldap pkgs')
(testLib.sso domain pkgs' config.shb.certs.certs.selfsigned.n) (testLib.sso pkgs' config.shb.certs.certs.selfsigned.n)
sso sso
]; ];
}; };

View file

@ -1,14 +1,10 @@
{ pkgs, lib, ... }: { pkgs, ... }:
let let
pkgs' = pkgs; pkgs' = pkgs;
testLib = pkgs.callPackage ../common.nix {}; testLib = pkgs.callPackage ../common.nix {};
subdomain = "ha";
domain = "example.com";
commonTestScript = testLib.mkScripts { commonTestScript = testLib.mkScripts {
inherit subdomain domain;
hasSSL = { node, ... }: !(isNull node.config.shb.home-assistant.ssl); hasSSL = { node, ... }: !(isNull node.config.shb.home-assistant.ssl);
waitForServices = { ... }: [ waitForServices = { ... }: [
"home-assistant.service" "home-assistant.service"
@ -20,9 +16,13 @@ let
}; };
basic = { config, ... }: { basic = { config, ... }: {
test = {
subdomain = "ha";
};
shb.home-assistant = { shb.home-assistant = {
enable = true; enable = true;
inherit subdomain domain; inherit (config.test) subdomain domain;
config = { config = {
name = "Tiserbox"; name = "Tiserbox";
@ -146,7 +146,7 @@ in
imports = [ imports = [
testLib.baseModule testLib.baseModule
../../modules/services/home-assistant.nix ../../modules/services/home-assistant.nix
(testLib.certs domain) testLib.certs
basic basic
https https
]; ];
@ -165,7 +165,7 @@ in
testLib.baseModule testLib.baseModule
../../modules/services/home-assistant.nix ../../modules/services/home-assistant.nix
basic basic
(testLib.ldap domain pkgs') (testLib.ldap pkgs')
ldap ldap
]; ];
}; };

View file

@ -4,11 +4,7 @@ let
testLib = pkgs.callPackage ../common.nix {}; testLib = pkgs.callPackage ../common.nix {};
subdomain = "j";
domain = "example.com";
commonTestScript = testLib.mkScripts { commonTestScript = testLib.mkScripts {
inherit subdomain domain;
hasSSL = { node, ... }: !(isNull node.config.shb.jellyfin.ssl); hasSSL = { node, ... }: !(isNull node.config.shb.jellyfin.ssl);
waitForServices = { ... }: [ waitForServices = { ... }: [
"jellyfin.service" "jellyfin.service"
@ -19,10 +15,14 @@ let
]; ];
}; };
basic = { basic = { config, ... }: {
test = {
subdomain = "v";
};
shb.jellyfin = { shb.jellyfin = {
enable = true; enable = true;
inherit domain subdomain; inherit (config.test) subdomain domain;
}; };
}; };
@ -111,7 +111,7 @@ in
imports = [ imports = [
testLib.baseModule testLib.baseModule
../../modules/services/jellyfin.nix ../../modules/services/jellyfin.nix
(testLib.certs domain) testLib.certs
basic basic
https https
]; ];
@ -130,7 +130,7 @@ in
testLib.baseModule testLib.baseModule
../../modules/services/jellyfin.nix ../../modules/services/jellyfin.nix
basic basic
(testLib.ldap domain pkgs') (testLib.ldap pkgs')
ldap ldap
]; ];
}; };
@ -147,11 +147,11 @@ in
imports = [ imports = [
testLib.baseModule testLib.baseModule
../../modules/services/jellyfin.nix ../../modules/services/jellyfin.nix
(testLib.certs domain) testLib.certs
basic basic
https https
(testLib.ldap domain pkgs') (testLib.ldap pkgs')
(testLib.sso domain pkgs' config.shb.certs.certs.selfsigned.n) (testLib.sso pkgs' config.shb.certs.certs.selfsigned.n)
sso sso
]; ];
}; };

View file

@ -4,13 +4,9 @@ let
testLib = pkgs.callPackage ../common.nix {}; testLib = pkgs.callPackage ../common.nix {};
subdomain = "grafana";
domain = "example.com";
password = "securepw"; password = "securepw";
commonTestScript = testLib.accessScript { commonTestScript = testLib.accessScript {
inherit subdomain domain;
hasSSL = { node, ... }: !(isNull node.config.shb.monitoring.ssl); hasSSL = { node, ... }: !(isNull node.config.shb.monitoring.ssl);
waitForServices = { ... }: [ waitForServices = { ... }: [
"grafana.service" "grafana.service"
@ -21,9 +17,13 @@ let
}; };
basic = { config, ... }: { basic = { config, ... }: {
test = {
subdomain = "g";
};
shb.monitoring = { shb.monitoring = {
enable = true; enable = true;
inherit subdomain domain; inherit (config.test) subdomain domain;
grafanaPort = 3000; grafanaPort = 3000;
adminPassword.result = config.shb.hardcodedsecret."admin_password".result; adminPassword.result = config.shb.hardcodedsecret."admin_password".result;
@ -70,7 +70,7 @@ in
imports = [ imports = [
testLib.baseModule testLib.baseModule
../../modules/blocks/monitoring.nix ../../modules/blocks/monitoring.nix
(testLib.certs domain) testLib.certs
basic basic
https https
]; ];

View file

@ -5,14 +5,9 @@ let
adminPass = "rootpw"; adminPass = "rootpw";
oidcSecret = "oidcSecret"; oidcSecret = "oidcSecret";
subdomain = "n";
domain = "example.com";
fqdn = "${subdomain}.${domain}";
testLib = pkgs.callPackage ../common.nix {}; testLib = pkgs.callPackage ../common.nix {};
commonTestScript = testLib.mkScripts { commonTestScript = testLib.mkScripts {
inherit subdomain domain;
hasSSL = { node, ... }: !(isNull node.config.shb.nextcloud.ssl); hasSSL = { node, ... }: !(isNull node.config.shb.nextcloud.ssl);
waitForServices = { ... }: [ waitForServices = { ... }: [
"phpfpm-nextcloud.service" "phpfpm-nextcloud.service"
@ -21,7 +16,7 @@ let
waitForUnixSocket = { node, ... }: [ waitForUnixSocket = { node, ... }: [
node.config.services.phpfpm.pools.nextcloud.socket node.config.services.phpfpm.pools.nextcloud.socket
]; ];
extraScript = { node, proto_fqdn, ... }: '' extraScript = { node, fqdn, proto_fqdn, ... }: ''
import time import time
def find_in_logs(unit, text): def find_in_logs(unit, text):
@ -116,16 +111,20 @@ let
}; };
basic = { config, ... }: { basic = { config, ... }: {
test = {
subdomain = "n";
};
shb.nextcloud = { shb.nextcloud = {
enable = true; enable = true;
inherit domain subdomain; inherit (config.test) subdomain domain;
dataDir = "/var/lib/nextcloud"; dataDir = "/var/lib/nextcloud";
tracing = null; tracing = null;
defaultPhoneRegion = "US"; defaultPhoneRegion = "US";
# This option is only needed because we do not access Nextcloud at the default port in the VM. # This option is only needed because we do not access Nextcloud at the default port in the VM.
externalFqdn = "${fqdn}:8080"; externalFqdn = "${config.test.fqdn}:8080";
adminUser = adminUser; adminUser = adminUser;
adminPass.result = config.shb.hardcodedsecret.adminPass.result; adminPass.result = config.shb.hardcodedsecret.adminPass.result;
@ -273,7 +272,7 @@ in
imports = [ imports = [
testLib.baseModule testLib.baseModule
../../modules/services/nextcloud-server.nix ../../modules/services/nextcloud-server.nix
(testLib.certs domain) testLib.certs
basic basic
https https
]; ];
@ -292,7 +291,7 @@ in
imports = [ imports = [
testLib.baseModule testLib.baseModule
../../modules/services/nextcloud-server.nix ../../modules/services/nextcloud-server.nix
(testLib.certs domain) testLib.certs
basic basic
https https
previewgenerator previewgenerator
@ -311,7 +310,7 @@ in
imports = [ imports = [
testLib.baseModule testLib.baseModule
../../modules/services/nextcloud-server.nix ../../modules/services/nextcloud-server.nix
(testLib.certs domain) testLib.certs
basic basic
https https
externalstorage externalstorage
@ -330,10 +329,10 @@ in
imports = [ imports = [
testLib.baseModule testLib.baseModule
../../modules/services/nextcloud-server.nix ../../modules/services/nextcloud-server.nix
(testLib.certs domain) testLib.certs
basic basic
https https
(testLib.ldap domain pkgs') (testLib.ldap pkgs')
ldap ldap
]; ];
}; };
@ -350,12 +349,12 @@ in
imports = [ imports = [
testLib.baseModule testLib.baseModule
../../modules/services/nextcloud-server.nix ../../modules/services/nextcloud-server.nix
(testLib.certs domain) testLib.certs
basic basic
https https
(testLib.ldap domain pkgs') (testLib.ldap pkgs')
ldap ldap
(testLib.sso domain pkgs' config.shb.certs.certs.selfsigned.n) (testLib.sso pkgs' config.shb.certs.certs.selfsigned.n)
sso sso
]; ];
}; };

View file

@ -4,11 +4,7 @@ let
testLib = pkgs.callPackage ../common.nix {}; testLib = pkgs.callPackage ../common.nix {};
subdomain = "v";
domain = "example.com";
commonTestScript = testLib.mkScripts { commonTestScript = testLib.mkScripts {
inherit subdomain domain;
hasSSL = { node, ... }: !(isNull node.config.shb.vaultwarden.ssl); hasSSL = { node, ... }: !(isNull node.config.shb.vaultwarden.ssl);
waitForServices = { ... }: [ waitForServices = { ... }: [
"vaultwarden.service" "vaultwarden.service"
@ -51,10 +47,14 @@ let
}; };
basic = { config, ... }: { basic = { config, ... }: {
test = {
subdomain = "v";
};
shb.nginx.accessLog = true; shb.nginx.accessLog = true;
shb.vaultwarden = { shb.vaultwarden = {
enable = true; enable = true;
inherit subdomain domain; inherit (config.test) subdomain domain;
port = 8222; port = 8222;
databasePassword.result = config.shb.hardcodedsecret.passphrase.result; databasePassword.result = config.shb.hardcodedsecret.passphrase.result;
@ -115,7 +115,7 @@ in
testLib.baseModule testLib.baseModule
../../modules/blocks/hardcodedsecret.nix ../../modules/blocks/hardcodedsecret.nix
../../modules/services/vaultwarden.nix ../../modules/services/vaultwarden.nix
(testLib.certs domain) testLib.certs
basic basic
https https
]; ];
@ -152,11 +152,11 @@ in
testLib.baseModule testLib.baseModule
../../modules/blocks/hardcodedsecret.nix ../../modules/blocks/hardcodedsecret.nix
../../modules/services/vaultwarden.nix ../../modules/services/vaultwarden.nix
(testLib.certs domain) testLib.certs
basic basic
https https
(testLib.ldap domain pkgs') (testLib.ldap pkgs')
(testLib.sso domain pkgs' config.shb.certs.certs.selfsigned.n) (testLib.sso pkgs' config.shb.certs.certs.selfsigned.n)
sso sso
]; ];
}; };
@ -169,14 +169,14 @@ in
5432 5432
9091 9091
]; ];
extraScript = { proto_fqdn, ... }: '' extraScript = { node, proto_fqdn, ... }: ''
with subtest("unauthenticated access is not granted to /admin"): with subtest("unauthenticated access is not granted to /admin"):
response = curl(client, """{"code":%{response_code},"auth_host":"%{urle.host}","auth_query":"%{urle.query}","all":%{json}}""", "${proto_fqdn}/admin") response = curl(client, """{"code":%{response_code},"auth_host":"%{urle.host}","auth_query":"%{urle.query}","all":%{json}}""", "${proto_fqdn}/admin")
if response['code'] != 200: if response['code'] != 200:
raise Exception(f"Code is {response['code']}") raise Exception(f"Code is {response['code']}")
if response['auth_host'] != "auth.${domain}": if response['auth_host'] != "auth.${node.config.test.domain}":
raise Exception(f"auth host should be auth.${domain} but is {response['auth_host']}") raise Exception(f"auth host should be auth.${node.config.test.domain} but is {response['auth_host']}")
if response['auth_query'] != "rd=${proto_fqdn}/admin": if response['auth_query'] != "rd=${proto_fqdn}/admin":
raise Exception(f"auth query should be rd=${proto_fqdn}/admin but is {response['auth_query']}") raise Exception(f"auth query should be rd=${proto_fqdn}/admin but is {response['auth_query']}")
''; '';