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

315 lines
8 KiB
Nix
Raw Normal View History

2023-12-30 18:51:55 +01:00
{ pkgs, lib, ... }:
let
2024-03-20 06:50:41 +01:00
pkgs' = pkgs;
2023-12-30 18:51:55 +01:00
adminUser = "root";
adminPass = "rootpw";
2024-06-07 06:08:30 +02:00
subdomain = "n";
domain = "example.com";
fqdn = "${subdomain}.${domain}";
2024-07-12 13:01:26 +02:00
testLib = pkgs.callPackage ../common.nix {};
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.nextcloud.ssl);
waitForServices = { ... }: [
"phpfpm-nextcloud.service"
"nginx.service"
];
waitForUnixSocket = { node, ... }: [
node.config.services.phpfpm.pools.nextcloud.socket
];
extraScript = { node, proto_fqdn, ... }: ''
import time
2023-12-30 18:51:55 +01:00
def find_in_logs(unit, text):
return server.systemctl("status {}".format(unit))[1].find(text) != -1
with subtest("cron job succeeds"):
# This calls blocks until the service is done.
server.systemctl("start nextcloud-cron.service")
# If the service failed, then we're not happy.
status = "active"
while status == "active":
status = server.get_unit_info("nextcloud-cron")["ActiveState"]
time.sleep(5)
if status != "inactive":
raise Exception("Cron job did not finish correctly")
2023-12-30 18:51:55 +01:00
if not find_in_logs("nextcloud-cron", "nextcloud-cron.service: Deactivated successfully."):
raise Exception("Nextcloud cron job did not finish successfully.")
with subtest("fails with incorrect authentication"):
client.fail(
2024-03-04 08:01:05 +01:00
"curl -f -s --location -X PROPFIND"
2023-12-30 18:51:55 +01:00
+ """ -H "Depth: 1" """
+ """ -u ${adminUser}:other """
2024-06-07 06:08:30 +02:00
+ " --connect-to ${fqdn}:443:server:443"
+ " --connect-to ${fqdn}:80:server:80"
+ " ${proto_fqdn}/remote.php/dav/files/${adminUser}/"
2024-03-04 08:01:05 +01:00
)
client.fail(
"curl -f -s --location -X PROPFIND"
+ """ -H "Depth: 1" """
+ """ -u root:rootpw """
2024-06-07 06:08:30 +02:00
+ " --connect-to ${fqdn}:443:server:443"
+ " --connect-to ${fqdn}:80:server:80"
+ " ${proto_fqdn}/remote.php/dav/files/other/"
2023-12-30 18:51:55 +01:00
)
with subtest("fails with incorrect path"):
client.fail(
2024-03-04 08:01:05 +01:00
"curl -f -s --location -X PROPFIND"
2023-12-30 18:51:55 +01:00
+ """ -H "Depth: 1" """
+ """ -u ${adminUser}:${adminPass} """
2024-06-07 06:08:30 +02:00
+ " --connect-to ${fqdn}:443:server:443"
+ " --connect-to ${fqdn}:80:server:80"
+ " ${proto_fqdn}/remote.php/dav/files/other/"
2023-12-30 18:51:55 +01:00
)
with subtest("can access webdav"):
client.succeed(
2024-03-04 08:01:05 +01:00
"curl -f -s --location -X PROPFIND"
2023-12-30 18:51:55 +01:00
+ """ -H "Depth: 1" """
+ """ -u ${adminUser}:${adminPass} """
2024-06-07 06:08:30 +02:00
+ " --connect-to ${fqdn}:443:server:443"
+ " --connect-to ${fqdn}:80:server:80"
+ " ${proto_fqdn}/remote.php/dav/files/${adminUser}/"
2023-12-30 18:51:55 +01:00
)
with subtest("can create and retrieve file"):
client.fail(
2024-03-04 08:01:05 +01:00
"curl -f -s --location -X GET"
2023-12-30 18:51:55 +01:00
+ """ -H "Depth: 1" """
+ """ -u ${adminUser}:${adminPass} """
2024-06-07 06:08:30 +02:00
+ " --connect-to ${fqdn}:443:server:443"
+ " --connect-to ${fqdn}:80:server:80"
2023-12-30 18:51:55 +01:00
+ """ -T file """
2024-06-07 06:08:30 +02:00
+ " ${proto_fqdn}/remote.php/dav/files/${adminUser}/file"
2023-12-30 18:51:55 +01:00
)
client.succeed("echo 'hello' > file")
client.succeed(
2024-03-04 08:01:05 +01:00
"curl -f -s --location -X PUT"
2023-12-30 18:51:55 +01:00
+ """ -H "Depth: 1" """
+ """ -u ${adminUser}:${adminPass} """
2024-06-07 06:08:30 +02:00
+ " --connect-to ${fqdn}:443:server:443"
+ " --connect-to ${fqdn}:80:server:80"
2023-12-30 18:51:55 +01:00
+ """ -T file """
2024-06-07 06:08:30 +02:00
+ " ${proto_fqdn}/remote.php/dav/files/${adminUser}/"
2023-12-30 18:51:55 +01:00
)
content = client.succeed(
2024-03-04 08:01:05 +01:00
"curl -f -s --location -X GET"
2023-12-30 18:51:55 +01:00
+ """ -H "Depth: 1" """
+ """ -u ${adminUser}:${adminPass} """
2024-06-07 06:08:30 +02:00
+ " --connect-to ${fqdn}:443:server:443"
+ " --connect-to ${fqdn}:80:server:80"
2023-12-30 18:51:55 +01:00
+ """ -T file """
2024-06-07 06:08:30 +02:00
+ " ${proto_fqdn}/remote.php/dav/files/${adminUser}/file"
2023-12-30 18:51:55 +01:00
)
if content != "hello\n":
raise Exception("Got incorrect content for file, expected 'hello\n' but got:\n{}".format(content))
'';
2024-07-12 13:01:26 +02:00
};
2024-03-04 08:01:05 +01:00
2024-07-16 10:38:26 +02:00
base = testLib.base pkgs' [
../../modules/services/nextcloud-server.nix
];
2024-03-04 08:01:05 +01:00
2024-06-07 06:08:30 +02:00
basic = { config, ... }: {
shb.nextcloud = {
enable = true;
inherit domain subdomain;
2024-07-16 10:38:26 +02:00
2024-06-07 06:08:30 +02:00
dataDir = "/var/lib/nextcloud";
tracing = null;
defaultPhoneRegion = "US";
# This option is only needed because we do not access Nextcloud at the default port in the VM.
externalFqdn = "${fqdn}:8080";
adminUser = adminUser;
adminPassFile = pkgs.writeText "adminPassFile" adminPass;
debug = true;
};
2024-03-04 08:01:05 +01:00
};
2024-06-07 06:08:30 +02:00
https = { config, ...}: {
shb.nextcloud = {
ssl = config.shb.certs.certs.selfsigned.n;
2024-03-04 08:01:05 +01:00
2024-06-07 06:08:30 +02:00
externalFqdn = lib.mkForce null;
};
};
2024-03-04 08:01:05 +01:00
2024-07-16 10:38:26 +02:00
ldap = { config, ... }: {
shb.nextcloud = {
apps.ldap = {
enable = true;
host = "127.0.0.1";
port = config.shb.ldap.ldapPort;
dcdomain = config.shb.ldap.dcdomain;
adminName = "admin";
adminPasswordFile = config.shb.ldap.ldapUserPassword.result.path;
2024-07-16 10:38:26 +02:00
userGroup = "nextcloud_user";
};
};
};
sso = { config, ... }:
let
authSecret = pkgs.writeText "authSecret" "authSecret";
in
{
shb.nextcloud = {
apps.sso = {
enable = true;
endpoint = "https://${config.shb.authelia.subdomain}.${config.shb.authelia.domain}";
clientID = "nextcloud";
# adminUserGroup = "nextcloud_admin";
secretFile = authSecret;
secretFileForAuthelia = authSecret;
fallbackDefaultAuth = false;
};
};
};
2024-06-07 06:08:30 +02:00
previewgenerator = { config, ...}: {
systemd.tmpfiles.rules = [
"d '/srv/nextcloud' 0750 nextcloud nextcloud - -"
];
2024-03-04 08:01:05 +01:00
2024-06-07 06:08:30 +02:00
shb.nextcloud = {
apps.previewgenerator.enable = true;
};
};
2024-03-04 08:01:05 +01:00
2024-06-07 06:08:30 +02:00
externalstorage = {
systemd.tmpfiles.rules = [
"d '/srv/nextcloud' 0750 nextcloud nextcloud - -"
];
2024-03-04 08:01:05 +01:00
2024-06-07 06:08:30 +02:00
shb.nextcloud = {
apps.externalStorage = {
enable = true;
userLocalMount.directory = "/srv/nextcloud/$user";
userLocalMount.mountName = "home";
2024-03-04 08:01:05 +01:00
};
};
2024-06-07 06:08:30 +02:00
};
in
{
basic = pkgs.testers.runNixOSTest {
2024-07-16 10:38:26 +02:00
name = "nextcloud_basic";
2024-06-07 06:08:30 +02:00
2024-07-16 10:38:26 +02:00
nodes.server = {
imports = [
base
basic
];
};
2024-03-04 08:01:05 +01:00
nodes.client = {};
testScript = commonTestScript;
2023-12-30 18:51:55 +01:00
};
2024-06-07 06:08:30 +02:00
https = pkgs.testers.runNixOSTest {
2024-07-16 10:38:26 +02:00
name = "nextcloud_https";
nodes.server = {
imports = [
base
(testLib.certs domain)
basic
https
];
};
2024-06-07 06:08:30 +02:00
nodes.client = {};
2024-06-07 06:08:30 +02:00
# TODO: Test login
testScript = commonTestScript;
};
2024-06-07 06:08:30 +02:00
previewGenerator = pkgs.testers.runNixOSTest {
2024-07-16 10:38:26 +02:00
name = "nextcloud_previewGenerator";
nodes.server = {
imports = [
base
(testLib.certs domain)
basic
https
previewgenerator
];
};
nodes.client = {};
2024-06-07 06:08:30 +02:00
testScript = commonTestScript;
};
externalStorage = pkgs.testers.runNixOSTest {
2024-07-16 10:38:26 +02:00
name = "nextcloud_externalStorage";
nodes.server = {
imports = [
base
(testLib.certs domain)
basic
https
externalstorage
];
};
nodes.client = {};
2024-06-07 06:08:30 +02:00
testScript = commonTestScript;
};
2024-07-16 10:38:26 +02:00
ldap = pkgs.testers.runNixOSTest {
name = "nextcloud_ldap";
nodes.server = { config, ... }: {
imports = [
base
(testLib.certs domain)
basic
https
(testLib.ldap domain pkgs')
ldap
];
};
nodes.client = {};
testScript = commonTestScript;
};
sso = pkgs.testers.runNixOSTest {
name = "nextcloud_sso";
nodes.server = { config, ... }: {
imports = [
base
(testLib.certs domain)
basic
https
(testLib.ldap domain pkgs')
ldap
(testLib.sso domain pkgs' config.shb.certs.certs.selfsigned.n)
sso
];
};
nodes.client = {};
testScript = commonTestScript;
};
2023-12-30 18:51:55 +01:00
}