2024-03-04 02:25:26 +01:00
|
|
|
{ pkgs, lib, ... }:
|
2024-03-05 05:36:47 +01:00
|
|
|
let
|
2024-03-20 06:50:41 +01:00
|
|
|
pkgs' = pkgs;
|
|
|
|
|
2024-06-07 07:58:47 +02:00
|
|
|
subdomain = "g";
|
|
|
|
domain = "example.com";
|
|
|
|
fqdn = "${subdomain}.${domain}";
|
|
|
|
|
2024-03-05 05:36:47 +01:00
|
|
|
# TODO: Test login
|
|
|
|
commonTestScript = { nodes, ... }:
|
|
|
|
let
|
|
|
|
hasSSL = !(isNull nodes.server.shb.grocy.ssl);
|
2024-06-10 08:26:17 +02:00
|
|
|
proto_fqdn = if hasSSL then "https://${fqdn}" else "http://${fqdn}";
|
2024-03-05 05:36:47 +01:00
|
|
|
in
|
|
|
|
''
|
|
|
|
import json
|
|
|
|
import os
|
|
|
|
import pathlib
|
|
|
|
|
|
|
|
start_all()
|
|
|
|
server.wait_for_unit("phpfpm-grocy.service")
|
|
|
|
server.wait_for_unit("nginx.service")
|
|
|
|
server.wait_for_open_unix_socket("${nodes.server.services.phpfpm.pools.grocy.socket}")
|
|
|
|
|
|
|
|
if ${if hasSSL then "True" else "False"}:
|
|
|
|
server.copy_from_vm("/etc/ssl/certs/ca-certificates.crt")
|
|
|
|
client.succeed("rm -r /etc/ssl/certs")
|
|
|
|
client.copy_from_host(str(pathlib.Path(os.environ.get("out", os.getcwd())) / "ca-certificates.crt"), "/etc/ssl/certs/ca-certificates.crt")
|
|
|
|
|
|
|
|
def curl(target, format, endpoint, succeed=True):
|
|
|
|
return json.loads(target.succeed(
|
|
|
|
"curl --fail-with-body --silent --show-error --output /dev/null --location"
|
2024-06-10 08:26:17 +02:00
|
|
|
+ " --connect-to ${fqdn}:443:server:443"
|
|
|
|
+ " --connect-to ${fqdn}:80:server:80"
|
2024-03-05 05:36:47 +01:00
|
|
|
+ f" --write-out '{format}'"
|
|
|
|
+ " " + endpoint
|
|
|
|
))
|
|
|
|
|
|
|
|
with subtest("access"):
|
2024-06-10 08:26:17 +02:00
|
|
|
response = curl(client, """{"code":%{response_code}}""", "${proto_fqdn}")
|
2024-03-05 05:36:47 +01:00
|
|
|
|
|
|
|
if response['code'] != 200:
|
|
|
|
raise Exception(f"Code is {response['code']}")
|
|
|
|
'';
|
2024-06-07 07:58:47 +02:00
|
|
|
|
|
|
|
base = {
|
|
|
|
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/services/grocy.nix
|
|
|
|
];
|
|
|
|
|
|
|
|
# Nginx port.
|
|
|
|
networking.firewall.allowedTCPPorts = [ 80 443 ];
|
|
|
|
};
|
|
|
|
|
|
|
|
certs = { config, ... }: {
|
|
|
|
imports = [
|
|
|
|
../../modules/blocks/ssl.nix
|
|
|
|
];
|
|
|
|
|
|
|
|
shb.certs = {
|
|
|
|
cas.selfsigned.myca = {
|
|
|
|
name = "My CA";
|
|
|
|
};
|
|
|
|
certs.selfsigned = {
|
|
|
|
n = {
|
|
|
|
ca = config.shb.certs.cas.selfsigned.myca;
|
|
|
|
domain = "*.${domain}";
|
|
|
|
group = "nginx";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.services.nginx.after = [ config.shb.certs.certs.selfsigned.n.systemdService ];
|
|
|
|
systemd.services.nginx.requires = [ config.shb.certs.certs.selfsigned.n.systemdService ];
|
|
|
|
};
|
|
|
|
|
|
|
|
basic = { config, ... }: {
|
|
|
|
shb.grocy = {
|
|
|
|
enable = true;
|
|
|
|
inherit domain subdomain;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
https = { config, ...}: {
|
|
|
|
shb.grocy = {
|
|
|
|
ssl = config.shb.certs.certs.selfsigned.n;
|
|
|
|
};
|
|
|
|
};
|
2024-03-05 05:36:47 +01:00
|
|
|
in
|
2024-03-04 02:25:26 +01:00
|
|
|
{
|
2024-03-20 06:50:41 +01:00
|
|
|
basic = pkgs.testers.runNixOSTest {
|
2024-03-04 02:25:26 +01:00
|
|
|
name = "grocy-basic";
|
|
|
|
|
2024-06-07 07:58:47 +02:00
|
|
|
nodes.server = lib.mkMerge [
|
|
|
|
base
|
|
|
|
basic
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
shb.authelia = lib.mkOption { type = lib.types.anything; };
|
|
|
|
};
|
|
|
|
}
|
|
|
|
];
|
2024-03-04 02:25:26 +01:00
|
|
|
|
|
|
|
nodes.client = {};
|
|
|
|
|
2024-03-05 05:36:47 +01:00
|
|
|
testScript = commonTestScript;
|
2024-03-04 02:25:26 +01:00
|
|
|
};
|
|
|
|
|
2024-06-07 07:58:47 +02:00
|
|
|
https = pkgs.testers.runNixOSTest {
|
|
|
|
name = "grocy-https";
|
|
|
|
|
|
|
|
nodes.server = lib.mkMerge [
|
|
|
|
base
|
|
|
|
certs
|
|
|
|
basic
|
|
|
|
https
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
shb.authelia = lib.mkOption { type = lib.types.anything; };
|
2024-03-04 02:25:26 +01:00
|
|
|
};
|
2024-06-07 07:58:47 +02:00
|
|
|
}
|
|
|
|
];
|
2024-03-04 02:25:26 +01:00
|
|
|
|
|
|
|
nodes.client = {};
|
|
|
|
|
2024-03-05 05:36:47 +01:00
|
|
|
testScript = commonTestScript;
|
2024-03-04 02:25:26 +01:00
|
|
|
};
|
|
|
|
}
|