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

141 lines
3.1 KiB
Nix
Raw Normal View History

2024-05-25 00:02:38 +02:00
{ pkgs, lib, ... }:
let
pkgs' = pkgs;
2024-07-12 13:01:26 +02:00
testLib = pkgs.callPackage ../common.nix {};
2024-05-25 00:02:38 +02:00
subdomain = "v";
domain = "example.com";
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.vaultwarden.ssl);
waitForServices = { ... }: [
"vaultwarden.service"
"nginx.service"
];
waitForPorts = { node, ... }: [
8222
5432
];
};
2024-05-25 00:02:38 +02:00
2024-07-16 10:38:26 +02:00
base = testLib.base pkgs' [
../../modules/services/vaultwarden.nix
];
2024-05-25 00:02:38 +02:00
basic = { config, ... }: {
shb.vaultwarden = {
enable = true;
inherit subdomain domain;
2024-07-16 10:38:26 +02:00
2024-05-25 00:02:38 +02:00
port = 8222;
databasePasswordFile = pkgs.writeText "pwfile" "DBPASSWORDFILE";
};
2024-07-16 10:38:26 +02:00
# networking.hosts = {
# "127.0.0.1" = [ fqdn ];
2024-05-25 00:02:38 +02:00
# };
};
2024-07-16 10:38:26 +02:00
https = { config, ... }: {
shb.vaultwarden = {
2024-05-25 00:02:38 +02:00
ssl = config.shb.certs.certs.selfsigned.n;
};
2024-07-16 10:38:26 +02:00
};
2024-05-25 00:02:38 +02:00
2024-07-16 10:38:26 +02:00
# Not yet supported
# ldap = { config, ... }: {
# # shb.vaultwarden = {
# # ldapEndpoint = "http://127.0.0.1:${builtins.toString config.shb.ldap.webUIListenPort}";
# # };
# };
2024-05-25 00:02:38 +02:00
2024-07-16 10:38:26 +02:00
sso = { config, ... }: {
2024-05-25 00:02:38 +02:00
shb.vaultwarden = {
authEndpoint = "https://${config.shb.authelia.subdomain}.${config.shb.authelia.domain}";
};
};
in
{
basic = pkgs.testers.runNixOSTest {
name = "vaultwarden_basic";
2024-07-16 10:38:26 +02:00
nodes.server = {
imports = [
base
basic
];
};
nodes.client = {};
testScript = commonTestScript;
};
https = pkgs.testers.runNixOSTest {
name = "vaultwarden_https";
nodes.server = {
imports = [
base
(testLib.certs domain)
basic
https
];
};
2024-05-25 00:02:38 +02:00
nodes.client = {};
testScript = commonTestScript;
};
# Not yet supported
#
# ldap = pkgs.testers.runNixOSTest {
# name = "vaultwarden_ldap";
#
# nodes.server = lib.mkMerge [
# base
# basic
# ldap
# ];
#
# nodes.client = {};
#
# testScript = commonTestScript;
# };
sso = pkgs.testers.runNixOSTest {
name = "vaultwarden_sso";
2024-07-16 10:38:26 +02:00
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
];
};
2024-05-25 00:02:38 +02:00
nodes.client = {};
2024-07-16 10:38:26 +02:00
testScript = commonTestScript.override {
extraScript = { proto_fqdn, ... }: ''
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")
if response['code'] != 200:
raise Exception(f"Code is {response['code']}")
if response['auth_host'] != "auth.${domain}":
raise Exception(f"auth host should be auth.${domain} but is {response['auth_host']}")
if response['auth_query'] != "rd=${proto_fqdn}/admin":
raise Exception(f"auth query should be rd=${proto_fqdn}/admin but is {response['auth_query']}")
'';
};
2024-05-25 00:02:38 +02:00
};
}