mirror of
https://github.com/NixOS/nixpkgs.git
synced 2026-12-06 12:49:59 +00:00
nixos/nextcloud: rework tests (#588299)
This commit is contained in:
@@ -1256,7 +1256,7 @@ in
|
||||
networking.scripted = handleTest ./networking/networkd-and-scripted.nix { networkd = false; };
|
||||
# TODO: put in networking.nix after the test becomes more complete
|
||||
networkingProxy = runTest ./networking-proxy.nix;
|
||||
nextcloud = handleTest ./nextcloud { };
|
||||
nextcloud = import ./nextcloud { inherit runTest lib; };
|
||||
nextflow = runTestOn [ "x86_64-linux" ] ./nextflow.nix;
|
||||
nextjs-ollama-llm-ui = runTest ./web-apps/nextjs-ollama-llm-ui.nix;
|
||||
nexus = runTest ./nexus.nix;
|
||||
|
||||
@@ -1,127 +1,138 @@
|
||||
{
|
||||
name,
|
||||
pkgs,
|
||||
testBase,
|
||||
system,
|
||||
package,
|
||||
flavor ? "nodes",
|
||||
...
|
||||
}:
|
||||
|
||||
with import ../../lib/testing-python.nix { inherit system pkgs; };
|
||||
runTest (
|
||||
{ config, lib, ... }:
|
||||
{
|
||||
inherit name;
|
||||
meta = {
|
||||
maintainers = lib.teams.nextcloud.members;
|
||||
};
|
||||
assert flavor == "nodes";
|
||||
|
||||
imports = [ testBase ];
|
||||
args@{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
nodes,
|
||||
containers,
|
||||
...
|
||||
}:
|
||||
{
|
||||
inherit name;
|
||||
meta = {
|
||||
maintainers = lib.teams.nextcloud.members;
|
||||
};
|
||||
|
||||
nodes = {
|
||||
# The only thing the client needs to do is download a file.
|
||||
client =
|
||||
{ ... }:
|
||||
{
|
||||
services.davfs2.enable = true;
|
||||
systemd.tmpfiles.settings.nextcloud = {
|
||||
"/tmp/davfs2-secrets"."f+" = {
|
||||
mode = "0600";
|
||||
argument = "http://nextcloud/remote.php/dav/files/${config.adminuser} ${config.adminuser} ${config.adminpass}";
|
||||
};
|
||||
};
|
||||
virtualisation.fileSystems = {
|
||||
"/mnt/dav" = {
|
||||
device = "http://nextcloud/remote.php/dav/files/${config.adminuser}";
|
||||
fsType = "davfs";
|
||||
options =
|
||||
let
|
||||
davfs2Conf = (pkgs.writeText "davfs2.conf" "secrets /tmp/davfs2-secrets");
|
||||
in
|
||||
[
|
||||
"conf=${davfs2Conf}"
|
||||
"x-systemd.automount"
|
||||
"noauto"
|
||||
];
|
||||
};
|
||||
imports = [ testBase ];
|
||||
|
||||
${flavor} = {
|
||||
# The only thing the client needs to do is download a file.
|
||||
client =
|
||||
{ pkgs, ... }:
|
||||
{
|
||||
services.davfs2.enable = true;
|
||||
systemd.tmpfiles.settings.nextcloud = {
|
||||
"/tmp/davfs2-secrets"."f+" = {
|
||||
mode = "0600";
|
||||
argument = "http://nextcloud/remote.php/dav/files/${config.adminuser} ${config.adminuser} ${config.adminpass}";
|
||||
};
|
||||
};
|
||||
|
||||
nextcloud =
|
||||
{ config, pkgs, ... }:
|
||||
{
|
||||
systemd.tmpfiles.rules = [
|
||||
"d /var/lib/nextcloud-data 0750 nextcloud nginx - -"
|
||||
];
|
||||
|
||||
services.nextcloud = {
|
||||
enable = true;
|
||||
config.dbtype = "sqlite";
|
||||
datadir = "/var/lib/nextcloud-data";
|
||||
autoUpdateApps = {
|
||||
enable = true;
|
||||
startAt = "20:00";
|
||||
};
|
||||
phpExtraExtensions = all: [ all.bz2 ];
|
||||
nginx.enableFastcgiRequestBuffering = true;
|
||||
secrets.mysecret = "/etc/nextcloud/mysecretfile";
|
||||
};
|
||||
|
||||
environment.etc."nextcloud/mysecretfile".text = "foobar";
|
||||
|
||||
specialisation.withoutMagick.configuration = {
|
||||
services.nextcloud.enableImagemagick = false;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
test-helpers.extraTests =
|
||||
{ nodes, ... }:
|
||||
let
|
||||
findInClosure =
|
||||
what: drv:
|
||||
pkgs.runCommand "find-in-closure"
|
||||
{
|
||||
exportReferencesGraph = [
|
||||
"graph"
|
||||
drv
|
||||
virtualisation.fileSystems = {
|
||||
"/mnt/dav" = {
|
||||
device = "http://nextcloud/remote.php/dav/files/${config.adminuser}";
|
||||
fsType = "davfs";
|
||||
options =
|
||||
let
|
||||
davfs2Conf = (pkgs.writeText "davfs2.conf" "secrets /tmp/davfs2-secrets");
|
||||
in
|
||||
[
|
||||
"conf=${davfs2Conf}"
|
||||
"x-systemd.automount"
|
||||
"noauto"
|
||||
];
|
||||
inherit what;
|
||||
}
|
||||
''
|
||||
test -e graph
|
||||
grep "$what" graph >$out || true
|
||||
'';
|
||||
nexcloudWithImagick = findInClosure "imagick" nodes.nextcloud.system.build.vm;
|
||||
nextcloudWithoutImagick = findInClosure "imagick" nodes.nextcloud.specialisation.withoutMagick.configuration.system.build.vm;
|
||||
in
|
||||
# python
|
||||
''
|
||||
with subtest("File is in proper nextcloud home"):
|
||||
nextcloud.succeed("test -f ${nodes.nextcloud.services.nextcloud.datadir}/data/root/files/test-shared-file")
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
with subtest("Closure checks"):
|
||||
assert open("${nexcloudWithImagick}").read() != ""
|
||||
assert open("${nextcloudWithoutImagick}").read() == ""
|
||||
nextcloud =
|
||||
{ config, pkgs, ... }:
|
||||
{
|
||||
systemd.tmpfiles.rules = [
|
||||
"d /var/lib/nextcloud-data 0750 nextcloud nginx - -"
|
||||
];
|
||||
|
||||
with subtest("Davfs2"):
|
||||
assert "hi" in client.succeed("cat /mnt/dav/test-shared-file")
|
||||
services.nextcloud = {
|
||||
enable = true;
|
||||
package = package pkgs;
|
||||
config.dbtype = "sqlite";
|
||||
datadir = "/var/lib/nextcloud-data";
|
||||
autoUpdateApps = {
|
||||
enable = true;
|
||||
startAt = "20:00";
|
||||
};
|
||||
phpExtraExtensions = all: [ all.bz2 ];
|
||||
nginx.enableFastcgiRequestBuffering = true;
|
||||
secrets.mysecret = "/etc/nextcloud/mysecretfile";
|
||||
};
|
||||
|
||||
with subtest("Ensure SSE is disabled by default"):
|
||||
nextcloud.succeed("grep -vE '^HBEGIN:oc_encryption_module' /var/lib/nextcloud-data/data/root/files/test-shared-file")
|
||||
environment.etc."nextcloud/mysecretfile".text = "foobar";
|
||||
|
||||
with subtest("Create non-empty files with Transfer-Encoding: chunked"):
|
||||
client.succeed(
|
||||
'dd if=/dev/urandom of=testfile.bin bs=1M count=10',
|
||||
'curl --fail -v -X PUT --header "Transfer-Encoding: chunked" --data-binary @testfile.bin "http://nextcloud/remote.php/webdav/testfile.bin" -u ${config.adminuser}:${config.adminpass}',
|
||||
)
|
||||
specialisation.withoutMagick.configuration = {
|
||||
services.nextcloud.enableImagemagick = false;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
# Verify the local and remote copies of the file are identical.
|
||||
client_hash = client.succeed("sha256sum <testfile.bin").strip()
|
||||
nextcloud_hash = nextcloud.succeed("sha256sum </var/lib/nextcloud-data/data/root/files/testfile.bin").strip()
|
||||
t.assertEqual(client_hash, nextcloud_hash)
|
||||
test-helpers.extraTests =
|
||||
{ ... }:
|
||||
let
|
||||
findInClosure =
|
||||
what: drv:
|
||||
pkgs.runCommand "find-in-closure"
|
||||
{
|
||||
exportReferencesGraph = [
|
||||
"graph"
|
||||
drv
|
||||
];
|
||||
inherit what;
|
||||
}
|
||||
''
|
||||
test -e graph
|
||||
grep "$what" graph >$out || true
|
||||
'';
|
||||
nexcloudWithImagick = findInClosure "imagick" args.${flavor}.nextcloud.system.build.vm;
|
||||
nextcloudWithoutImagick =
|
||||
findInClosure "imagick"
|
||||
args.${flavor}.nextcloud.specialisation.withoutMagick.configuration.system.build.vm;
|
||||
in
|
||||
# python
|
||||
''
|
||||
with subtest("File is in proper nextcloud home"):
|
||||
nextcloud.succeed("test -f ${
|
||||
args.${flavor}.nextcloud.services.nextcloud.datadir
|
||||
}/data/root/files/test-shared-file")
|
||||
|
||||
with subtest("secrets"):
|
||||
assert "foobar" == nextcloud.succeed("nextcloud-occ config:system:get mysecret").strip()
|
||||
'';
|
||||
}
|
||||
)
|
||||
with subtest("Closure checks"):
|
||||
assert open("${nexcloudWithImagick}").read() != ""
|
||||
assert open("${nextcloudWithoutImagick}").read() == ""
|
||||
|
||||
with subtest("Davfs2"):
|
||||
assert "hi" in client.succeed("cat /mnt/dav/test-shared-file")
|
||||
|
||||
with subtest("Ensure SSE is disabled by default"):
|
||||
nextcloud.succeed("grep -vE '^HBEGIN:oc_encryption_module' /var/lib/nextcloud-data/data/root/files/test-shared-file")
|
||||
|
||||
with subtest("Create non-empty files with Transfer-Encoding: chunked"):
|
||||
client.succeed(
|
||||
'dd if=/dev/urandom of=testfile.bin bs=1M count=10',
|
||||
'curl --fail -v -X PUT --header "Transfer-Encoding: chunked" --data-binary @testfile.bin "http://nextcloud/remote.php/webdav/testfile.bin" -u ${config.adminuser}:${config.adminpass}',
|
||||
)
|
||||
|
||||
# Verify the local and remote copies of the file are identical.
|
||||
client_hash = client.succeed("sha256sum <testfile.bin").strip()
|
||||
nextcloud_hash = nextcloud.succeed("sha256sum </var/lib/nextcloud-data/data/root/files/testfile.bin").strip()
|
||||
t.assertEqual(client_hash, nextcloud_hash)
|
||||
|
||||
with subtest("secrets"):
|
||||
assert "foobar" == nextcloud.succeed("nextcloud-occ config:system:get mysecret").strip()
|
||||
'';
|
||||
}
|
||||
|
||||
@@ -1,62 +1,40 @@
|
||||
{
|
||||
system ? builtins.currentSystem,
|
||||
config ? { },
|
||||
pkgs ? import ../../.. { inherit system config; },
|
||||
lib,
|
||||
runTest,
|
||||
...
|
||||
}:
|
||||
|
||||
with pkgs.lib;
|
||||
|
||||
let
|
||||
baseModule =
|
||||
{ config, ... }:
|
||||
mkTestBase =
|
||||
flavor:
|
||||
{ config, pkgs, ... }:
|
||||
{
|
||||
imports = [
|
||||
{
|
||||
options.test-helpers = {
|
||||
rclone = mkOption { type = types.str; };
|
||||
upload-sample = mkOption { type = types.str; };
|
||||
check-sample = mkOption { type = types.str; };
|
||||
init = mkOption {
|
||||
type = types.str;
|
||||
init = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "";
|
||||
};
|
||||
provision = mkOption {
|
||||
type = types.str;
|
||||
provision = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "";
|
||||
};
|
||||
extraTests = mkOption {
|
||||
type = types.either types.str (types.functionTo types.str);
|
||||
extraTests = lib.mkOption {
|
||||
type = lib.types.either lib.types.str (lib.types.functionTo lib.types.str);
|
||||
default = "";
|
||||
};
|
||||
};
|
||||
options.adminuser = mkOption { type = types.str; };
|
||||
options.adminpass = mkOption { type = types.str; };
|
||||
options.adminuser = lib.mkOption { type = lib.types.str; };
|
||||
options.adminpass = lib.mkOption { type = lib.types.str; };
|
||||
}
|
||||
];
|
||||
|
||||
adminuser = pkgs.lib.mkDefault "root";
|
||||
adminuser = lib.mkDefault "root";
|
||||
# This needs to be a "secure" password, since the password_policy app is enabled after installation and will forbid "simple" passwords.
|
||||
adminpass = pkgs.lib.mkDefault "+CVpTwaOEktxsFc6";
|
||||
adminpass = lib.mkDefault "+CVpTwaOEktxsFc6";
|
||||
|
||||
test-helpers.rclone = "${pkgs.writeShellScript "rclone" ''
|
||||
set -euo pipefail
|
||||
export PATH="${pkgs.rclone}/bin:$PATH"
|
||||
export RCLONE_CONFIG_NEXTCLOUD_TYPE=webdav
|
||||
export RCLONE_CONFIG_NEXTCLOUD_URL="http://nextcloud/remote.php/dav/files/${config.adminuser}"
|
||||
export RCLONE_CONFIG_NEXTCLOUD_VENDOR="nextcloud"
|
||||
export RCLONE_CONFIG_NEXTCLOUD_USER="${config.adminuser}"
|
||||
export RCLONE_CONFIG_NEXTCLOUD_PASS="$(rclone obscure ${config.adminpass})"
|
||||
exec "$@"
|
||||
''}";
|
||||
test-helpers.upload-sample = "${pkgs.writeShellScript "rclone-upload" ''
|
||||
<<<'hi' rclone rcat nextcloud:test-shared-file
|
||||
''}";
|
||||
test-helpers.check-sample = "${pkgs.writeShellScript "check-sample" ''
|
||||
set -e
|
||||
diff <(echo 'hi') <(rclone cat nextcloud:test-shared-file)
|
||||
''}";
|
||||
|
||||
nodes = {
|
||||
${flavor} = {
|
||||
client = { ... }: { };
|
||||
nextcloud =
|
||||
{ lib, ... }:
|
||||
@@ -72,11 +50,29 @@ let
|
||||
};
|
||||
|
||||
testScript =
|
||||
args@{ nodes, ... }:
|
||||
args@{ nodes, containers, ... }:
|
||||
let
|
||||
inherit (config) test-helpers;
|
||||
rclone = "${pkgs.writeShellScript "rclone" ''
|
||||
set -euo pipefail
|
||||
export PATH="${pkgs.rclone}/bin:$PATH"
|
||||
export RCLONE_CONFIG_NEXTCLOUD_TYPE=webdav
|
||||
export RCLONE_CONFIG_NEXTCLOUD_URL="http://nextcloud/remote.php/dav/files/${config.adminuser}"
|
||||
export RCLONE_CONFIG_NEXTCLOUD_VENDOR="nextcloud"
|
||||
export RCLONE_CONFIG_NEXTCLOUD_USER="${config.adminuser}"
|
||||
export RCLONE_CONFIG_NEXTCLOUD_PASS="$(rclone obscure ${config.adminpass})"
|
||||
exec "$@"
|
||||
''}";
|
||||
|
||||
upload-sample = "${pkgs.writeShellScript "rclone-upload" ''
|
||||
<<<'hi' rclone rcat nextcloud:test-shared-file
|
||||
''}";
|
||||
check-sample = "${pkgs.writeShellScript "check-sample" ''
|
||||
set -e
|
||||
diff <(echo 'hi') <(rclone cat nextcloud:test-shared-file)
|
||||
''}";
|
||||
in
|
||||
mkBefore ''
|
||||
lib.mkBefore ''
|
||||
${test-helpers.provision}
|
||||
start_all()
|
||||
nextcloud.wait_for_unit("multi-user.target")
|
||||
@@ -92,15 +88,15 @@ let
|
||||
|
||||
with subtest("Upload/Download test"):
|
||||
nextcloud.succeed(
|
||||
"${test-helpers.rclone} ${test-helpers.upload-sample}"
|
||||
"${rclone} ${upload-sample}"
|
||||
)
|
||||
client.wait_for_unit("multi-user.target")
|
||||
client.succeed(
|
||||
"${test-helpers.rclone} ${test-helpers.check-sample}"
|
||||
"${rclone} ${check-sample}"
|
||||
)
|
||||
|
||||
${
|
||||
if pkgs.lib.isFunction test-helpers.extraTests then
|
||||
if lib.isFunction test-helpers.extraTests then
|
||||
test-helpers.extraTests args
|
||||
else
|
||||
test-helpers.extraTests
|
||||
@@ -108,47 +104,73 @@ let
|
||||
'';
|
||||
};
|
||||
|
||||
genTests =
|
||||
version:
|
||||
let
|
||||
testBase.imports = [
|
||||
baseModule
|
||||
{
|
||||
nodes.nextcloud =
|
||||
{ pkgs, ... }:
|
||||
{
|
||||
services.nextcloud.package = pkgs.${"nextcloud${toString version}"};
|
||||
};
|
||||
}
|
||||
];
|
||||
|
||||
callNextcloudTest =
|
||||
path:
|
||||
packages = lib.listToAttrs (
|
||||
map
|
||||
(
|
||||
version:
|
||||
let
|
||||
name = "${removeSuffix ".nix" (baseNameOf path)}${toString version}";
|
||||
attr = "nextcloud${toString version}";
|
||||
in
|
||||
nameValuePair name (
|
||||
lib.nameValuePair attr (builtins.getAttr attr)
|
||||
)
|
||||
[
|
||||
33
|
||||
34
|
||||
35
|
||||
]
|
||||
);
|
||||
|
||||
genTests =
|
||||
attr: package:
|
||||
lib.mapAttrs
|
||||
(
|
||||
name:
|
||||
{
|
||||
path,
|
||||
flavor ? "nodes",
|
||||
}:
|
||||
runTest (
|
||||
import path {
|
||||
inherit system pkgs testBase;
|
||||
name = "nextcloud-${name}";
|
||||
inherit
|
||||
package
|
||||
runTest
|
||||
flavor
|
||||
;
|
||||
name = "${attr}-${name}";
|
||||
testBase = mkTestBase flavor;
|
||||
}
|
||||
);
|
||||
in
|
||||
map callNextcloudTest [
|
||||
./basic.nix
|
||||
./home-bindmount.nix
|
||||
./home-mount.nix
|
||||
./with-declarative-redis-and-secrets.nix
|
||||
./with-mysql-and-memcached.nix
|
||||
./with-postgresql-and-redis.nix
|
||||
./with-objectstore.nix
|
||||
./with-mail.nix
|
||||
];
|
||||
)
|
||||
)
|
||||
{
|
||||
basic = {
|
||||
path = ./basic.nix;
|
||||
};
|
||||
home-bindmout = {
|
||||
path = ./home-bindmount.nix;
|
||||
};
|
||||
home-mount = {
|
||||
path = ./home-mount.nix;
|
||||
};
|
||||
with-declarative-redis-and-secrets = {
|
||||
path = ./with-declarative-redis-and-secrets.nix;
|
||||
flavor = "containers";
|
||||
};
|
||||
with-mysql-and-memcached = {
|
||||
path = ./with-mysql-and-memcached.nix;
|
||||
flavor = "containers";
|
||||
};
|
||||
with-postgresql-and-redis = {
|
||||
path = ./with-postgresql-and-redis.nix;
|
||||
flavor = "containers";
|
||||
};
|
||||
with-objectstore = {
|
||||
path = ./with-objectstore.nix;
|
||||
flavor = "containers";
|
||||
};
|
||||
with-mail = {
|
||||
path = ./with-mail.nix;
|
||||
flavor = "containers";
|
||||
};
|
||||
};
|
||||
in
|
||||
listToAttrs (
|
||||
concatMap genTests [
|
||||
33
|
||||
34
|
||||
35
|
||||
]
|
||||
)
|
||||
lib.mapAttrs genTests packages
|
||||
|
||||
@@ -1,68 +1,68 @@
|
||||
{
|
||||
name,
|
||||
pkgs,
|
||||
testBase,
|
||||
system,
|
||||
package,
|
||||
flavor ? "nodes",
|
||||
...
|
||||
}:
|
||||
|
||||
with import ../../lib/testing-python.nix { inherit system pkgs; };
|
||||
runTest (
|
||||
{ lib, ... }:
|
||||
{
|
||||
inherit name;
|
||||
meta.maintainers = lib.teams.nextcloud.members;
|
||||
assert flavor == "nodes";
|
||||
|
||||
imports = [ testBase ];
|
||||
{ pkgs, lib, ... }:
|
||||
{
|
||||
inherit name;
|
||||
meta.maintainers = lib.teams.nextcloud.members;
|
||||
|
||||
nodes.nextcloud = { pkgs, ... }: {
|
||||
# Make sure that inside our tmpfs mount an actual directory for Nextcloud exists.
|
||||
boot.initrd.systemd.tmpfiles.settings."nextcloud"."/sysroot/mnt/nextcloud".d = { };
|
||||
imports = [ testBase ];
|
||||
|
||||
boot.initrd.systemd.mounts = [
|
||||
# Create a mocked /mnt/nextcloud. Only a tmpfs here, but in reality this could e.g.
|
||||
# be the mount of a larger disk.
|
||||
{
|
||||
unitConfig.DefaultDependencies = "no";
|
||||
conflicts = [ "umount.target" ];
|
||||
wantedBy = [ "initrd.target" ];
|
||||
before = [ "systemd-tmpfiles-setup-sysroot.service" ];
|
||||
options = "x-initrd.mount";
|
||||
where = "/sysroot/mnt";
|
||||
what = "tmpfs";
|
||||
type = "tmpfs";
|
||||
}
|
||||
# Bind some directory to /var/lib/nextcloud, the place that the Nextcloud module expects
|
||||
# by default.
|
||||
{
|
||||
conflicts = [ "umount.target" ];
|
||||
wantedBy = [ "initrd.target" ];
|
||||
before = [ "systemd-tmpfiles-setup-sysroot.service" ];
|
||||
options = "x-initrd.mount,bind";
|
||||
where = "/sysroot/var/lib/nextcloud";
|
||||
what = "/sysroot/mnt/nextcloud";
|
||||
type = "none";
|
||||
}
|
||||
];
|
||||
environment.systemPackages = [
|
||||
pkgs.util-linux
|
||||
];
|
||||
services.nextcloud = {
|
||||
config.dbtype = "sqlite";
|
||||
};
|
||||
${flavor}.nextcloud = { pkgs, ... }: {
|
||||
# Make sure that inside our tmpfs mount an actual directory for Nextcloud exists.
|
||||
boot.initrd.systemd.tmpfiles.settings."nextcloud"."/sysroot/mnt/nextcloud".d = { };
|
||||
|
||||
boot.initrd.systemd.mounts = [
|
||||
# Create a mocked /mnt/nextcloud. Only a tmpfs here, but in reality this could e.g.
|
||||
# be the mount of a larger disk.
|
||||
{
|
||||
unitConfig.DefaultDependencies = "no";
|
||||
conflicts = [ "umount.target" ];
|
||||
wantedBy = [ "initrd.target" ];
|
||||
before = [ "systemd-tmpfiles-setup-sysroot.service" ];
|
||||
options = "x-initrd.mount";
|
||||
where = "/sysroot/mnt";
|
||||
what = "tmpfs";
|
||||
type = "tmpfs";
|
||||
}
|
||||
# Bind some directory to /var/lib/nextcloud, the place that the Nextcloud module expects
|
||||
# by default.
|
||||
{
|
||||
conflicts = [ "umount.target" ];
|
||||
wantedBy = [ "initrd.target" ];
|
||||
before = [ "systemd-tmpfiles-setup-sysroot.service" ];
|
||||
options = "x-initrd.mount,bind";
|
||||
where = "/sysroot/var/lib/nextcloud";
|
||||
what = "/sysroot/mnt/nextcloud";
|
||||
type = "none";
|
||||
}
|
||||
];
|
||||
environment.systemPackages = [
|
||||
pkgs.util-linux
|
||||
];
|
||||
services.nextcloud = {
|
||||
package = package pkgs;
|
||||
config.dbtype = "sqlite";
|
||||
};
|
||||
};
|
||||
|
||||
test-helpers.init = ''
|
||||
import json
|
||||
mnts = json.loads(nextcloud.succeed("findmnt /var/lib/nextcloud -J"))["filesystems"]
|
||||
t.assertEqual(1, len(mnts))
|
||||
mnt = mnts[0]
|
||||
t.assertEqual("tmpfs[/nextcloud]", mnt["source"])
|
||||
t.assertEqual("/var/lib/nextcloud", mnt["target"])
|
||||
'';
|
||||
test-helpers.init = ''
|
||||
import json
|
||||
mnts = json.loads(nextcloud.succeed("findmnt /var/lib/nextcloud -J"))["filesystems"]
|
||||
t.assertEqual(1, len(mnts))
|
||||
mnt = mnts[0]
|
||||
t.assertEqual("tmpfs[/nextcloud]", mnt["source"])
|
||||
t.assertEqual("/var/lib/nextcloud", mnt["target"])
|
||||
'';
|
||||
|
||||
test-helpers.extraTests = ''
|
||||
nextcloud.succeed("test -d /mnt/nextcloud/data/root")
|
||||
'';
|
||||
}
|
||||
)
|
||||
test-helpers.extraTests = ''
|
||||
nextcloud.succeed("test -d /mnt/nextcloud/data/root")
|
||||
'';
|
||||
}
|
||||
|
||||
@@ -1,29 +1,29 @@
|
||||
{
|
||||
name,
|
||||
pkgs,
|
||||
testBase,
|
||||
system,
|
||||
package,
|
||||
flavor ? "nodes",
|
||||
...
|
||||
}:
|
||||
|
||||
with import ../../lib/testing-python.nix { inherit system pkgs; };
|
||||
runTest (
|
||||
{ config, lib, ... }:
|
||||
{
|
||||
inherit name;
|
||||
meta.maintainers = lib.teams.nextcloud.members;
|
||||
assert flavor == "nodes";
|
||||
|
||||
imports = [ testBase ];
|
||||
{ config, lib, ... }:
|
||||
{
|
||||
inherit name;
|
||||
meta.maintainers = lib.teams.nextcloud.members;
|
||||
|
||||
nodes.nextcloud = {
|
||||
fileSystems."/mnt" = {
|
||||
fsType = "tmpfs";
|
||||
device = "tmpfs";
|
||||
};
|
||||
services.nextcloud = {
|
||||
config.dbtype = "sqlite";
|
||||
home = "/mnt/nextcloud";
|
||||
};
|
||||
imports = [ testBase ];
|
||||
|
||||
${flavor}.nextcloud = { pkgs, ... }: {
|
||||
fileSystems."/mnt" = {
|
||||
fsType = "tmpfs";
|
||||
device = "tmpfs";
|
||||
};
|
||||
}
|
||||
)
|
||||
services.nextcloud = {
|
||||
config.dbtype = "sqlite";
|
||||
package = package pkgs;
|
||||
home = "/mnt/nextcloud";
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,107 +1,110 @@
|
||||
{
|
||||
name,
|
||||
pkgs,
|
||||
testBase,
|
||||
system,
|
||||
package,
|
||||
flavor ? "containers",
|
||||
...
|
||||
}:
|
||||
|
||||
with import ../../lib/testing-python.nix { inherit system pkgs; };
|
||||
runTest (
|
||||
{ config, lib, ... }:
|
||||
let
|
||||
inherit (config) adminuser;
|
||||
in
|
||||
{
|
||||
inherit name;
|
||||
meta.maintainers = lib.teams.nextcloud.members;
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
let
|
||||
inherit (config) adminuser;
|
||||
in
|
||||
{
|
||||
inherit name;
|
||||
meta.maintainers = lib.teams.nextcloud.members;
|
||||
|
||||
imports = [ testBase ];
|
||||
imports = [ testBase ];
|
||||
|
||||
nodes = {
|
||||
nextcloud =
|
||||
{ config, pkgs, ... }:
|
||||
{
|
||||
environment.systemPackages = [ pkgs.jq ];
|
||||
services.nextcloud = {
|
||||
caching = {
|
||||
apcu = false;
|
||||
redis = true;
|
||||
memcached = false;
|
||||
};
|
||||
notify_push = {
|
||||
enable = true;
|
||||
bendDomainToLocalhost = true;
|
||||
logLevel = "debug";
|
||||
};
|
||||
extraAppsEnable = true;
|
||||
# This test also validates that we can use an "external" database
|
||||
database.createLocally = false;
|
||||
config = {
|
||||
dbtype = "pgsql";
|
||||
dbname = "nextcloud";
|
||||
dbuser = adminuser;
|
||||
dbpassFile = "${pkgs.writeText "dbpass" "database-password"}"; # Don't try this at home!
|
||||
};
|
||||
|
||||
secretFile = "/etc/nextcloud-secrets.json";
|
||||
|
||||
settings = {
|
||||
allow_local_remote_servers = true;
|
||||
redis = {
|
||||
dbindex = 0;
|
||||
timeout = 1.5;
|
||||
# password handled via secretfile below
|
||||
};
|
||||
};
|
||||
configureRedis = true;
|
||||
${flavor} = {
|
||||
nextcloud =
|
||||
{ config, pkgs, ... }:
|
||||
{
|
||||
environment.systemPackages = [ pkgs.jq ];
|
||||
services.nextcloud = {
|
||||
package = package pkgs;
|
||||
caching = {
|
||||
apcu = false;
|
||||
redis = true;
|
||||
memcached = false;
|
||||
};
|
||||
|
||||
services.redis.servers."nextcloud" = {
|
||||
notify_push = {
|
||||
enable = true;
|
||||
port = 6379;
|
||||
requirePass = "secret";
|
||||
bendDomainToLocalhost = true;
|
||||
logLevel = "debug";
|
||||
};
|
||||
extraAppsEnable = true;
|
||||
# This test also validates that we can use an "external" database
|
||||
database.createLocally = false;
|
||||
config = {
|
||||
dbtype = "pgsql";
|
||||
dbname = "nextcloud";
|
||||
dbuser = adminuser;
|
||||
dbpassFile = "${pkgs.writeText "dbpass" "database-password"}"; # Don't try this at home!
|
||||
};
|
||||
|
||||
systemd.services.nextcloud-setup = {
|
||||
requires = [ "postgresql.target" ];
|
||||
after = [ "postgresql.target" ];
|
||||
};
|
||||
secretFile = "/etc/nextcloud-secrets.json";
|
||||
|
||||
services.postgresql = {
|
||||
enable = true;
|
||||
};
|
||||
systemd.services.postgresql-setup.postStart = ''
|
||||
password=$(cat ${config.services.nextcloud.config.dbpassFile})
|
||||
${config.services.postgresql.package}/bin/psql <<EOF
|
||||
CREATE ROLE ${adminuser} WITH LOGIN PASSWORD '$password' CREATEDB;
|
||||
CREATE DATABASE nextcloud;
|
||||
ALTER DATABASE nextcloud OWNER to ${adminuser};
|
||||
EOF
|
||||
'';
|
||||
|
||||
# This file is meant to contain secret options which should
|
||||
# not go into the nix store. Here it is just used to set the
|
||||
# redis password.
|
||||
environment.etc."nextcloud-secrets.json" = {
|
||||
mode = "0600";
|
||||
text = builtins.toJSON {
|
||||
redis.password = "secret";
|
||||
settings = {
|
||||
allow_local_remote_servers = true;
|
||||
redis = {
|
||||
dbindex = 0;
|
||||
timeout = 1.5;
|
||||
# password handled via secretfile below
|
||||
};
|
||||
};
|
||||
configureRedis = true;
|
||||
};
|
||||
|
||||
services.redis.servers."nextcloud" = {
|
||||
enable = true;
|
||||
port = 6379;
|
||||
requirePass = "secret";
|
||||
};
|
||||
|
||||
systemd.services.nextcloud-setup = {
|
||||
requires = [ "postgresql.target" ];
|
||||
after = [ "postgresql.target" ];
|
||||
};
|
||||
|
||||
services.postgresql = {
|
||||
enable = true;
|
||||
};
|
||||
systemd.services.postgresql-setup.postStart = ''
|
||||
password=$(cat ${config.services.nextcloud.config.dbpassFile})
|
||||
${config.services.postgresql.package}/bin/psql <<EOF
|
||||
CREATE ROLE ${adminuser} WITH LOGIN PASSWORD '$password' CREATEDB;
|
||||
CREATE DATABASE nextcloud;
|
||||
ALTER DATABASE nextcloud OWNER to ${adminuser};
|
||||
EOF
|
||||
'';
|
||||
|
||||
# This file is meant to contain secret options which should
|
||||
# not go into the nix store. Here it is just used to set the
|
||||
# redis password.
|
||||
environment.etc."nextcloud-secrets.json" = {
|
||||
mode = "0600";
|
||||
text = builtins.toJSON {
|
||||
redis.password = "secret";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
test-helpers.extraTests = ''
|
||||
with subtest("non-empty redis cache"):
|
||||
# redis cache should not be empty
|
||||
assert nextcloud.succeed('redis-cli --pass secret --json KEYS "*" | jq length').strip() != "0", """
|
||||
redis-cli for keys * returned 0 entries
|
||||
"""
|
||||
test-helpers.extraTests = ''
|
||||
with subtest("non-empty redis cache"):
|
||||
# redis cache should not be empty
|
||||
assert nextcloud.succeed('redis-cli --pass secret --json KEYS "*" | jq length').strip() != "0", """
|
||||
redis-cli for keys * returned 0 entries
|
||||
"""
|
||||
|
||||
with subtest("notify-push"):
|
||||
client.execute("${lib.getExe pkgs.nextcloud-notify_push.passthru.test_client} http://nextcloud ${config.adminuser} ${config.adminpass} >&2 &")
|
||||
nextcloud.wait_until_succeeds("journalctl -u nextcloud-notify_push | grep -q \"Sending ping to ${config.adminuser}\"")
|
||||
'';
|
||||
}
|
||||
)
|
||||
with subtest("notify-push"):
|
||||
client.execute("${lib.getExe pkgs.nextcloud-notify_push.passthru.test_client} http://nextcloud ${config.adminuser} ${config.adminpass} >&2 &")
|
||||
nextcloud.wait_until_succeeds("journalctl -u nextcloud-notify_push | grep -q \"Sending ping to ${config.adminuser}\"")
|
||||
'';
|
||||
}
|
||||
|
||||
@@ -1,100 +1,102 @@
|
||||
{
|
||||
name,
|
||||
pkgs,
|
||||
testBase,
|
||||
system,
|
||||
package,
|
||||
flavor ? "containers",
|
||||
...
|
||||
}:
|
||||
with import ../../lib/testing-python.nix { inherit system pkgs; };
|
||||
runTest (
|
||||
{ config, lib, ... }:
|
||||
let
|
||||
certs = import ../common/acme/server/snakeoil-certs.nix;
|
||||
domain = certs.domain;
|
||||
in
|
||||
{
|
||||
inherit name;
|
||||
args@{
|
||||
config,
|
||||
lib,
|
||||
containers,
|
||||
nodes,
|
||||
...
|
||||
}:
|
||||
let
|
||||
certs = import ../common/acme/server/snakeoil-certs.nix;
|
||||
domain = certs.domain;
|
||||
in
|
||||
{
|
||||
inherit name;
|
||||
|
||||
meta.maintainers = lib.teams.nextcloud.members;
|
||||
meta.maintainers = lib.teams.nextcloud.members;
|
||||
|
||||
imports = [ testBase ];
|
||||
imports = [ testBase ];
|
||||
|
||||
nodes = {
|
||||
nextcloud =
|
||||
{
|
||||
config,
|
||||
pkgs,
|
||||
nodes,
|
||||
...
|
||||
}:
|
||||
{
|
||||
security.pki.certificateFiles = [ certs.ca.cert ];
|
||||
${flavor} = {
|
||||
nextcloud =
|
||||
{
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
{
|
||||
security.pki.certificateFiles = [ certs.ca.cert ];
|
||||
|
||||
networking.extraHosts = ''
|
||||
${nodes.stalwart.networking.primaryIPAddress} ${domain}
|
||||
'';
|
||||
networking.extraHosts = ''
|
||||
${args.${flavor}.stalwart.networking.primaryIPAddress} ${domain}
|
||||
'';
|
||||
|
||||
environment.etc."nextcloud/mail_smtppassword".text = "foobar";
|
||||
environment.etc."nextcloud/mail_smtppassword".text = "foobar";
|
||||
|
||||
services.nextcloud = {
|
||||
config.dbtype = "sqlite";
|
||||
services.nextcloud = {
|
||||
package = package pkgs;
|
||||
config.dbtype = "sqlite";
|
||||
|
||||
settings = {
|
||||
mail_from_address = "alice";
|
||||
mail_domain = domain;
|
||||
mail_smtpmode = "smtp";
|
||||
mail_smtphost = domain;
|
||||
mail_smtpport = 587;
|
||||
mail_smtpauth = true;
|
||||
mail_smtpname = "alice";
|
||||
mail_send_plaintext_only = true;
|
||||
};
|
||||
|
||||
secrets.mail_smtppassword = "/etc/nextcloud/mail_smtppassword";
|
||||
settings = {
|
||||
mail_from_address = "alice";
|
||||
mail_domain = domain;
|
||||
mail_smtpmode = "smtp";
|
||||
mail_smtphost = domain;
|
||||
mail_smtpport = 587;
|
||||
mail_smtpauth = true;
|
||||
mail_smtpname = "alice";
|
||||
mail_send_plaintext_only = true;
|
||||
};
|
||||
|
||||
secrets.mail_smtppassword = "/etc/nextcloud/mail_smtppassword";
|
||||
};
|
||||
};
|
||||
|
||||
stalwart =
|
||||
{ pkgs, ... }:
|
||||
{
|
||||
imports = [ ../stalwart/stalwart-config.nix ];
|
||||
stalwart =
|
||||
{ pkgs, ... }:
|
||||
{
|
||||
imports = [ ../stalwart/stalwart-config.nix ];
|
||||
|
||||
networking.firewall.allowedTCPPorts = [ 587 ];
|
||||
networking.firewall.allowedTCPPorts = [ 587 ];
|
||||
|
||||
environment.systemPackages = [
|
||||
(pkgs.writers.writePython3Bin "test-imap-read" { } ''
|
||||
from imaplib import IMAP4
|
||||
environment.systemPackages = [
|
||||
(pkgs.writers.writePython3Bin "test-imap-read" { } ''
|
||||
from imaplib import IMAP4
|
||||
|
||||
with IMAP4('localhost') as imap:
|
||||
imap.starttls()
|
||||
status, [caps] = imap.login('bob', 'foobar')
|
||||
assert status == 'OK'
|
||||
imap.select()
|
||||
status, [ref] = imap.search(None, 'ALL')
|
||||
assert status == 'OK'
|
||||
[msgId] = ref.split()
|
||||
status, msg = imap.fetch(msgId, 'BODY[TEXT]')
|
||||
assert status == 'OK'
|
||||
assert (msg[0][1].strip()
|
||||
== (b'Well done, ${config.adminuser}!\r\n\r\n'
|
||||
b'If you received this email, the email configuration '
|
||||
b's=\r\neems to be correct.\r\n\r\n\r\n--=20\r\n'
|
||||
b'Nextcloud - a safe home for all your data=\r\n\r\n'
|
||||
b'This is an automatically sent email, please do not reply.'))
|
||||
'')
|
||||
];
|
||||
};
|
||||
};
|
||||
with IMAP4('localhost') as imap:
|
||||
imap.starttls()
|
||||
status, [caps] = imap.login('bob', 'foobar')
|
||||
assert status == 'OK'
|
||||
imap.select()
|
||||
status, [ref] = imap.search(None, 'ALL')
|
||||
assert status == 'OK'
|
||||
[msgId] = ref.split()
|
||||
status, msg = imap.fetch(msgId, 'BODY[TEXT]')
|
||||
assert status == 'OK'
|
||||
assert (msg[0][1].strip()
|
||||
== (b'Well done, ${config.adminuser}!\r\n\r\n'
|
||||
b'If you received this email, the email configuration '
|
||||
b's=\r\neems to be correct.\r\n\r\n\r\n--=20\r\n'
|
||||
b'Nextcloud - a safe home for all your data=\r\n\r\n'
|
||||
b'This is an automatically sent email, please do not reply.'))
|
||||
'')
|
||||
];
|
||||
};
|
||||
};
|
||||
|
||||
test-helpers.init = ''
|
||||
stalwart.wait_for_unit("multi-user.target")
|
||||
stalwart.wait_until_succeeds("nc -vzw 2 localhost 587")
|
||||
test-helpers.init = ''
|
||||
stalwart.wait_for_unit("multi-user.target")
|
||||
stalwart.wait_until_succeeds("nc -vzw 2 localhost 587")
|
||||
|
||||
nextcloud.succeed("nc -vzw 2 ${domain} 587")
|
||||
nextcloud.succeed("curl -sS --fail-with-body -u ${config.adminuser}:${config.adminpass} -H 'OCS-APIRequest: true' -X PUT http://nextcloud/ocs/v2.php/cloud/users/${config.adminuser} -H 'Content-Type: application/json' --data-raw '{\"key\":\"email\",\"value\":\"bob@${domain}\"}'")
|
||||
nextcloud.succeed("curl -sS --fail-with-body -u ${config.adminuser}:${config.adminpass} -H 'OCS-APIRequest: true' -X POST http://nextcloud/settings/admin/mailtest")
|
||||
nextcloud.succeed("nc -vzw 2 ${domain} 587")
|
||||
nextcloud.succeed("curl -sS --fail-with-body -u ${config.adminuser}:${config.adminpass} -H 'OCS-APIRequest: true' -X PUT http://nextcloud/ocs/v2.php/cloud/users/${config.adminuser} -H 'Content-Type: application/json' --data-raw '{\"key\":\"email\",\"value\":\"bob@${domain}\"}'")
|
||||
nextcloud.succeed("curl -sS --fail-with-body -u ${config.adminuser}:${config.adminpass} -H 'OCS-APIRequest: true' -X POST http://nextcloud/settings/admin/mailtest")
|
||||
|
||||
stalwart.succeed("test-imap-read")
|
||||
'';
|
||||
}
|
||||
)
|
||||
stalwart.succeed("test-imap-read")
|
||||
'';
|
||||
}
|
||||
|
||||
@@ -1,49 +1,52 @@
|
||||
{
|
||||
name,
|
||||
pkgs,
|
||||
testBase,
|
||||
system,
|
||||
package,
|
||||
flavor ? "containers",
|
||||
...
|
||||
}:
|
||||
|
||||
with import ../../lib/testing-python.nix { inherit system pkgs; };
|
||||
runTest (
|
||||
{ config, lib, ... }:
|
||||
{
|
||||
inherit name;
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
{
|
||||
inherit name;
|
||||
|
||||
meta.maintainers = lib.teams.nextcloud.members;
|
||||
meta.maintainers = lib.teams.nextcloud.members;
|
||||
|
||||
imports = [ testBase ];
|
||||
imports = [ testBase ];
|
||||
|
||||
nodes = {
|
||||
nextcloud =
|
||||
{ config, pkgs, ... }:
|
||||
{
|
||||
services.nextcloud = {
|
||||
caching = {
|
||||
apcu = true;
|
||||
memcached = true;
|
||||
};
|
||||
config.dbtype = "mysql";
|
||||
configureRedis = false;
|
||||
${flavor} = {
|
||||
nextcloud =
|
||||
{ config, pkgs, ... }:
|
||||
{
|
||||
services.nextcloud = {
|
||||
package = package pkgs;
|
||||
caching = {
|
||||
apcu = true;
|
||||
memcached = true;
|
||||
};
|
||||
|
||||
services.memcached.enable = true;
|
||||
config.dbtype = "mysql";
|
||||
configureRedis = false;
|
||||
};
|
||||
};
|
||||
|
||||
test-helpers.init =
|
||||
let
|
||||
configureMemcached = pkgs.writeScript "configure-memcached" ''
|
||||
nextcloud-occ config:system:set memcached_servers 0 0 --value 127.0.0.1 --type string
|
||||
nextcloud-occ config:system:set memcached_servers 0 1 --value 11211 --type integer
|
||||
nextcloud-occ config:system:set memcache.local --value '\OC\Memcache\APCu' --type string
|
||||
nextcloud-occ config:system:set memcache.distributed --value '\OC\Memcache\Memcached' --type string
|
||||
'';
|
||||
in
|
||||
''
|
||||
nextcloud.succeed("${configureMemcached}")
|
||||
services.memcached.enable = true;
|
||||
};
|
||||
};
|
||||
|
||||
test-helpers.init =
|
||||
let
|
||||
configureMemcached = pkgs.writeScript "configure-memcached" ''
|
||||
nextcloud-occ config:system:set memcached_servers 0 0 --value 127.0.0.1 --type string
|
||||
nextcloud-occ config:system:set memcached_servers 0 1 --value 11211 --type integer
|
||||
nextcloud-occ config:system:set memcache.local --value '\OC\Memcache\APCu' --type string
|
||||
nextcloud-occ config:system:set memcache.distributed --value '\OC\Memcache\Memcached' --type string
|
||||
'';
|
||||
}
|
||||
)
|
||||
in
|
||||
''
|
||||
nextcloud.succeed("${configureMemcached}")
|
||||
'';
|
||||
}
|
||||
|
||||
@@ -1,199 +1,200 @@
|
||||
{
|
||||
name,
|
||||
pkgs,
|
||||
testBase,
|
||||
system,
|
||||
package,
|
||||
flavor ? "containers",
|
||||
...
|
||||
}:
|
||||
|
||||
with import ../../lib/testing-python.nix { inherit system pkgs; };
|
||||
runTest (
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
let
|
||||
accessKey = "GK85bae09276df06d47a1ed2bf";
|
||||
secretKey = "eac031e3379beb05477a9c8381ade716c8f5860f1dffec915ae2a728a88c88c6";
|
||||
args@{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
nodes,
|
||||
containers,
|
||||
...
|
||||
}:
|
||||
let
|
||||
accessKey = "GK85bae09276df06d47a1ed2bf";
|
||||
secretKey = "eac031e3379beb05477a9c8381ade716c8f5860f1dffec915ae2a728a88c88c6";
|
||||
|
||||
awsCfg = "${pkgs.writeText "aws.cfg" ''
|
||||
[default]
|
||||
endpoint_url=https://acme.test
|
||||
aws_access_key_id=${accessKey}
|
||||
aws_secret_access_key=${secretKey}
|
||||
region=garage
|
||||
''}";
|
||||
in
|
||||
{
|
||||
inherit name;
|
||||
meta.maintainers = lib.teams.nextcloud.members;
|
||||
awsCfg = "${pkgs.writeText "aws.cfg" ''
|
||||
[default]
|
||||
endpoint_url=https://acme.test
|
||||
aws_access_key_id=${accessKey}
|
||||
aws_secret_access_key=${secretKey}
|
||||
region=garage
|
||||
''}";
|
||||
in
|
||||
{
|
||||
inherit name;
|
||||
meta.maintainers = lib.teams.nextcloud.members;
|
||||
|
||||
imports = [ testBase ];
|
||||
imports = [ testBase ];
|
||||
|
||||
nodes = {
|
||||
nextcloud =
|
||||
{
|
||||
pkgs,
|
||||
nodes,
|
||||
...
|
||||
}:
|
||||
{
|
||||
services.nextcloud.config.dbtype = "sqlite";
|
||||
${flavor} = {
|
||||
nextcloud =
|
||||
{
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
{
|
||||
services.nextcloud.package = package pkgs;
|
||||
services.nextcloud.config.dbtype = "sqlite";
|
||||
|
||||
environment.variables.AWS_CONFIG_FILE = awsCfg;
|
||||
environment.variables.AWS_CA_BUNDLE = "/etc/ssl/certs/ca-bundle.crt";
|
||||
environment.variables.AWS_CONFIG_FILE = awsCfg;
|
||||
environment.variables.AWS_CA_BUNDLE = "/etc/ssl/certs/ca-bundle.crt";
|
||||
|
||||
services.nextcloud.config.objectstore.s3 = {
|
||||
enable = true;
|
||||
bucket = "nextcloud";
|
||||
verify_bucket_exists = true;
|
||||
key = accessKey;
|
||||
secretFile = "${pkgs.writeText "secretKey" secretKey}";
|
||||
hostname = "acme.test";
|
||||
useSsl = true;
|
||||
port = 443;
|
||||
usePathStyle = true;
|
||||
region = "garage";
|
||||
};
|
||||
|
||||
security.pki.certificates = [
|
||||
(builtins.readFile ../common/acme/server/ca.cert.pem)
|
||||
];
|
||||
|
||||
environment.systemPackages = [ pkgs.awscli2 ];
|
||||
|
||||
# The dummy certs are for acme.test, so we pretend that's the FQDN
|
||||
# of the garage VM.
|
||||
networking.extraHosts = ''
|
||||
${nodes.garage.networking.primaryIPAddress} acme.test
|
||||
'';
|
||||
services.nextcloud.config.objectstore.s3 = {
|
||||
enable = true;
|
||||
bucket = "nextcloud";
|
||||
verify_bucket_exists = true;
|
||||
key = accessKey;
|
||||
secretFile = "${pkgs.writeText "secretKey" secretKey}";
|
||||
hostname = "acme.test";
|
||||
useSsl = true;
|
||||
port = 443;
|
||||
usePathStyle = true;
|
||||
region = "garage";
|
||||
};
|
||||
|
||||
client =
|
||||
{ pkgs, nodes, ... }:
|
||||
{
|
||||
environment.variables.AWS_CONFIG_FILE = awsCfg;
|
||||
environment.variables.AWS_CA_BUNDLE = "/etc/ssl/certs/ca-bundle.crt";
|
||||
environment.systemPackages = [ pkgs.awscli2 ];
|
||||
security.pki.certificates = [
|
||||
(builtins.readFile ../common/acme/server/ca.cert.pem)
|
||||
];
|
||||
|
||||
security.pki.certificates = [
|
||||
(builtins.readFile ../common/acme/server/ca.cert.pem)
|
||||
];
|
||||
networking.extraHosts = ''
|
||||
${nodes.garage.networking.primaryIPAddress} acme.test
|
||||
'';
|
||||
};
|
||||
environment.systemPackages = [ pkgs.awscli2 ];
|
||||
|
||||
garage =
|
||||
{ pkgs, ... }:
|
||||
{
|
||||
security.pki.certificates = [
|
||||
(builtins.readFile ../common/acme/server/ca.cert.pem)
|
||||
];
|
||||
# The dummy certs are for acme.test, so we pretend that's the FQDN
|
||||
# of the garage VM.
|
||||
networking.extraHosts = ''
|
||||
${args.${flavor}.garage.networking.primaryIPAddress} acme.test
|
||||
'';
|
||||
};
|
||||
|
||||
services.garage = {
|
||||
enable = true;
|
||||
package = pkgs.garage_2;
|
||||
settings = {
|
||||
rpc_bind_addr = "[::]:3901";
|
||||
rpc_public_addr = "[::]:3901";
|
||||
rpc_secret = "81e5ab61625a5097c5953a09a16a524479c290ca01921560704395b830ad248d";
|
||||
replication_factor = 1;
|
||||
client =
|
||||
{ pkgs, ... }:
|
||||
{
|
||||
environment.variables.AWS_CONFIG_FILE = awsCfg;
|
||||
environment.variables.AWS_CA_BUNDLE = "/etc/ssl/certs/ca-bundle.crt";
|
||||
environment.systemPackages = [ pkgs.awscli2 ];
|
||||
|
||||
s3_api = {
|
||||
s3_region = "garage";
|
||||
api_bind_addr = "[::]:3900";
|
||||
};
|
||||
security.pki.certificates = [
|
||||
(builtins.readFile ../common/acme/server/ca.cert.pem)
|
||||
];
|
||||
networking.extraHosts = ''
|
||||
${args.${flavor}.garage.networking.primaryIPAddress} acme.test
|
||||
'';
|
||||
};
|
||||
|
||||
garage =
|
||||
{ pkgs, ... }:
|
||||
{
|
||||
security.pki.certificates = [
|
||||
(builtins.readFile ../common/acme/server/ca.cert.pem)
|
||||
];
|
||||
|
||||
services.garage = {
|
||||
enable = true;
|
||||
package = pkgs.garage_2;
|
||||
settings = {
|
||||
rpc_bind_addr = "[::]:3901";
|
||||
rpc_public_addr = "[::]:3901";
|
||||
rpc_secret = "81e5ab61625a5097c5953a09a16a524479c290ca01921560704395b830ad248d";
|
||||
replication_factor = 1;
|
||||
|
||||
s3_api = {
|
||||
s3_region = "garage";
|
||||
api_bind_addr = "[::]:3900";
|
||||
};
|
||||
};
|
||||
|
||||
services.nginx = {
|
||||
enable = true;
|
||||
recommendedProxySettings = true;
|
||||
|
||||
virtualHosts."acme.test" = {
|
||||
onlySSL = true;
|
||||
sslCertificate = ../common/acme/server/acme.test.cert.pem;
|
||||
sslCertificateKey = ../common/acme/server/acme.test.key.pem;
|
||||
locations."/".proxyPass = "http://127.0.0.1:3900";
|
||||
};
|
||||
};
|
||||
|
||||
networking.extraHosts = ''
|
||||
127.0.0.1 acme.test
|
||||
'';
|
||||
|
||||
environment.systemPackages = [ pkgs.gawk ];
|
||||
|
||||
virtualisation.diskSize = 2 * 1024;
|
||||
|
||||
networking.firewall.allowedTCPPorts = [
|
||||
3900
|
||||
80
|
||||
443
|
||||
];
|
||||
};
|
||||
};
|
||||
|
||||
test-helpers.provision = ''
|
||||
garage.start()
|
||||
garage.wait_for_open_port(3900)
|
||||
garage.wait_for_unit("nginx.service")
|
||||
garage.wait_for_open_port(443)
|
||||
services.nginx = {
|
||||
enable = true;
|
||||
recommendedProxySettings = true;
|
||||
|
||||
node_id = garage.succeed("garage status | tail -n1 | awk '{ print $1 }'")
|
||||
garage.succeed(
|
||||
"garage status",
|
||||
f"garage layout assign -c 1GB -z garage {node_id}",
|
||||
"garage layout apply --version 1",
|
||||
"garage key import ${accessKey} ${secretKey} --yes",
|
||||
"garage bucket create nextcloud",
|
||||
"garage key list >&2",
|
||||
"garage bucket allow --read --write --owner nextcloud --key ${accessKey}"
|
||||
)
|
||||
virtualHosts."acme.test" = {
|
||||
onlySSL = true;
|
||||
sslCertificate = ../common/acme/server/acme.test.cert.pem;
|
||||
sslCertificateKey = ../common/acme/server/acme.test.key.pem;
|
||||
locations."/".proxyPass = "http://127.0.0.1:3900";
|
||||
};
|
||||
};
|
||||
|
||||
networking.extraHosts = ''
|
||||
127.0.0.1 acme.test
|
||||
'';
|
||||
|
||||
environment.systemPackages = [ pkgs.gawk ];
|
||||
|
||||
virtualisation.diskSize = 2 * 1024;
|
||||
|
||||
networking.firewall.allowedTCPPorts = [
|
||||
3900
|
||||
80
|
||||
443
|
||||
];
|
||||
};
|
||||
};
|
||||
|
||||
test-helpers.provision = ''
|
||||
garage.start()
|
||||
garage.wait_for_open_port(3900)
|
||||
garage.wait_for_unit("nginx.service")
|
||||
garage.wait_for_open_port(443)
|
||||
|
||||
node_id = garage.succeed("garage status | tail -n1 | awk '{ print $1 }'")
|
||||
garage.succeed(
|
||||
"garage status",
|
||||
f"garage layout assign -c 1GB -z garage {node_id}",
|
||||
"garage layout apply --version 1",
|
||||
"garage key import ${accessKey} ${secretKey} --yes",
|
||||
"garage bucket create nextcloud",
|
||||
"garage key list >&2",
|
||||
"garage bucket allow --read --write --owner nextcloud --key ${accessKey}"
|
||||
)
|
||||
'';
|
||||
|
||||
test-helpers.extraTests =
|
||||
{ ... }:
|
||||
''
|
||||
|
||||
with subtest("File is not on the filesystem"):
|
||||
nextcloud.succeed("test ! -e ${
|
||||
args.${flavor}.nextcloud.services.nextcloud.home
|
||||
}/data/root/files/test-shared-file")
|
||||
|
||||
with subtest("Check if file is in S3"):
|
||||
files = [
|
||||
f.rsplit(' ', 2)
|
||||
for f in nextcloud.succeed('aws s3 ls s3://nextcloud/|sort').strip().split('\n')
|
||||
]
|
||||
print(files)
|
||||
|
||||
# Cannot assert an exact number here, nc27 writes more stuff initially into S3.
|
||||
# For now let's assume it's always the most recently added file.
|
||||
assert len(files) > 0, f"""
|
||||
Expected to have at least one object in garage/nextcloud. But `aws s3 ls` gave output:
|
||||
|
||||
'{files}'
|
||||
"""
|
||||
|
||||
_, size, file = files[-1]
|
||||
|
||||
assert size == "3", f"""
|
||||
Expected size of uploaded file to be 3 bytes, got {size}
|
||||
"""
|
||||
|
||||
assert file.startswith('urn:oid'), """
|
||||
Expected filename to start with 'urn:oid', instead got '{file}.
|
||||
"""
|
||||
|
||||
with subtest("Test download from S3"):
|
||||
client.succeed(
|
||||
f"aws s3 cp s3://nextcloud/{file} test "
|
||||
+ "--ca-bundle /etc/ssl/certs/ca-bundle.crt"
|
||||
)
|
||||
|
||||
client.succeed("test hi = $(cat test)")
|
||||
'';
|
||||
|
||||
test-helpers.extraTests =
|
||||
{ nodes, ... }:
|
||||
''
|
||||
|
||||
with subtest("File is not on the filesystem"):
|
||||
nextcloud.succeed("test ! -e ${nodes.nextcloud.services.nextcloud.home}/data/root/files/test-shared-file")
|
||||
|
||||
with subtest("Check if file is in S3"):
|
||||
files = [
|
||||
f.rsplit(' ', 2)
|
||||
for f in nextcloud.succeed('aws s3 ls s3://nextcloud/|sort').strip().split('\n')
|
||||
]
|
||||
print(files)
|
||||
|
||||
# Cannot assert an exact number here, nc27 writes more stuff initially into S3.
|
||||
# For now let's assume it's always the most recently added file.
|
||||
assert len(files) > 0, f"""
|
||||
Expected to have at least one object in garage/nextcloud. But `aws s3 ls` gave output:
|
||||
|
||||
'{files}'
|
||||
"""
|
||||
|
||||
_, size, file = files[-1]
|
||||
|
||||
assert size == "3", f"""
|
||||
Expected size of uploaded file to be 3 bytes, got {size}
|
||||
"""
|
||||
|
||||
assert file.startswith('urn:oid'), """
|
||||
Expected filename to start with 'urn:oid', instead got '{file}.
|
||||
"""
|
||||
|
||||
with subtest("Test download from S3"):
|
||||
client.succeed(
|
||||
f"aws s3 cp s3://nextcloud/{file} test "
|
||||
+ "--ca-bundle /etc/ssl/certs/ca-bundle.crt"
|
||||
)
|
||||
|
||||
client.succeed("test hi = $(cat test)")
|
||||
'';
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,80 +1,83 @@
|
||||
{
|
||||
name,
|
||||
pkgs,
|
||||
testBase,
|
||||
system,
|
||||
package,
|
||||
flavor ? "containers",
|
||||
...
|
||||
}:
|
||||
|
||||
with import ../../lib/testing-python.nix { inherit system pkgs; };
|
||||
runTest (
|
||||
{ config, lib, ... }:
|
||||
{
|
||||
inherit name;
|
||||
meta.maintainers = lib.teams.nextcloud.members;
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
{
|
||||
inherit name;
|
||||
meta.maintainers = lib.teams.nextcloud.members;
|
||||
|
||||
imports = [ testBase ];
|
||||
imports = [ testBase ];
|
||||
|
||||
nodes = {
|
||||
nextcloud =
|
||||
{
|
||||
config,
|
||||
pkgs,
|
||||
lib,
|
||||
...
|
||||
}:
|
||||
{
|
||||
environment.systemPackages = [ pkgs.jq ];
|
||||
services.nextcloud = {
|
||||
caching = {
|
||||
apcu = false;
|
||||
redis = true;
|
||||
memcached = false;
|
||||
};
|
||||
config.dbtype = "pgsql";
|
||||
notify_push = {
|
||||
enable = true;
|
||||
bendDomainToLocalhost = true;
|
||||
logLevel = "debug";
|
||||
};
|
||||
extraAppsEnable = true;
|
||||
extraApps = with config.services.nextcloud.package.packages.apps; {
|
||||
inherit notes;
|
||||
};
|
||||
settings.trusted_proxies = [ "::1" ];
|
||||
${flavor} = {
|
||||
nextcloud =
|
||||
{
|
||||
config,
|
||||
pkgs,
|
||||
lib,
|
||||
...
|
||||
}:
|
||||
{
|
||||
environment.systemPackages = [ pkgs.jq ];
|
||||
services.nextcloud = {
|
||||
package = package pkgs;
|
||||
caching = {
|
||||
apcu = false;
|
||||
redis = true;
|
||||
memcached = false;
|
||||
};
|
||||
|
||||
services.redis.servers."nextcloud".enable = true;
|
||||
services.redis.servers."nextcloud".port = 6379;
|
||||
config.dbtype = "pgsql";
|
||||
notify_push = {
|
||||
enable = true;
|
||||
bendDomainToLocalhost = true;
|
||||
logLevel = "debug";
|
||||
};
|
||||
extraAppsEnable = true;
|
||||
extraApps = with config.services.nextcloud.package.packages.apps; {
|
||||
inherit notes;
|
||||
};
|
||||
settings.trusted_proxies = [ "::1" ];
|
||||
};
|
||||
};
|
||||
|
||||
test-helpers.init =
|
||||
let
|
||||
configureRedis = pkgs.writeScript "configure-redis" ''
|
||||
nextcloud-occ config:system:set redis 'host' --value 'localhost' --type string
|
||||
nextcloud-occ config:system:set redis 'port' --value 6379 --type integer
|
||||
nextcloud-occ config:system:set memcache.local --value '\OC\Memcache\Redis' --type string
|
||||
nextcloud-occ config:system:set memcache.locking --value '\OC\Memcache\Redis' --type string
|
||||
'';
|
||||
in
|
||||
''
|
||||
nextcloud.succeed("${configureRedis}")
|
||||
services.redis.servers."nextcloud".enable = true;
|
||||
services.redis.servers."nextcloud".port = 6379;
|
||||
};
|
||||
};
|
||||
|
||||
test-helpers.init =
|
||||
let
|
||||
configureRedis = pkgs.writeScript "configure-redis" ''
|
||||
nextcloud-occ config:system:set redis 'host' --value 'localhost' --type string
|
||||
nextcloud-occ config:system:set redis 'port' --value 6379 --type integer
|
||||
nextcloud-occ config:system:set memcache.local --value '\OC\Memcache\Redis' --type string
|
||||
nextcloud-occ config:system:set memcache.locking --value '\OC\Memcache\Redis' --type string
|
||||
'';
|
||||
|
||||
test-helpers.extraTests = ''
|
||||
with subtest("notify-push"):
|
||||
client.execute("${lib.getExe pkgs.nextcloud-notify_push.passthru.test_client} http://nextcloud ${config.adminuser} ${config.adminpass} >&2 &")
|
||||
nextcloud.wait_until_succeeds("journalctl -u nextcloud-notify_push | grep -q \"Sending ping to ${config.adminuser}\"")
|
||||
|
||||
with subtest("Redis is used for caching"):
|
||||
# redis cache should not be empty
|
||||
assert nextcloud.succeed('redis-cli --json KEYS "*" | jq length').strip() != "0", """
|
||||
redis-cli for keys * returned 0 entries
|
||||
"""
|
||||
|
||||
with subtest("No code is returned when requesting PHP files (regression test)"):
|
||||
nextcloud.fail("curl -f http://nextcloud/nix-apps/notes/lib/AppInfo/Application.php")
|
||||
in
|
||||
''
|
||||
nextcloud.succeed("${configureRedis}")
|
||||
'';
|
||||
}
|
||||
)
|
||||
|
||||
test-helpers.extraTests = ''
|
||||
with subtest("notify-push"):
|
||||
client.execute("${lib.getExe pkgs.nextcloud-notify_push.passthru.test_client} http://nextcloud ${config.adminuser} ${config.adminpass} >&2 &")
|
||||
nextcloud.wait_until_succeeds("journalctl -u nextcloud-notify_push | grep -q \"Sending ping to ${config.adminuser}\"")
|
||||
|
||||
with subtest("Redis is used for caching"):
|
||||
# redis cache should not be empty
|
||||
assert nextcloud.succeed('redis-cli --json KEYS "*" | jq length').strip() != "0", """
|
||||
redis-cli for keys * returned 0 entries
|
||||
"""
|
||||
|
||||
with subtest("No code is returned when requesting PHP files (regression test)"):
|
||||
nextcloud.fail("curl -f http://nextcloud/nix-apps/notes/lib/AppInfo/Application.php")
|
||||
'';
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
{ lib, ... }:
|
||||
{ pkgs, lib, ... }:
|
||||
|
||||
let
|
||||
certs = import ../common/acme/server/snakeoil-certs.nix;
|
||||
@@ -9,6 +9,7 @@ in
|
||||
|
||||
services.stalwart = {
|
||||
enable = true;
|
||||
package = pkgs.stalwart_0_15;
|
||||
|
||||
stateVersion = lib.trivial.release; # Only for the test; please don't do in production
|
||||
|
||||
|
||||
@@ -60,8 +60,8 @@ rustPlatform.buildRustPackage rec {
|
||||
};
|
||||
};
|
||||
tests =
|
||||
lib.filterAttrs (
|
||||
key: lib.const (lib.hasPrefix "with-postgresql-and-redis" key)
|
||||
lib.mapAttrs' (
|
||||
k: { with-postgresql-and-redis, ... }: lib.nameValuePair k with-postgresql-and-redis
|
||||
) nixosTests.nextcloud
|
||||
// {
|
||||
inherit test_client;
|
||||
|
||||
@@ -37,9 +37,7 @@ let
|
||||
'';
|
||||
|
||||
passthru = {
|
||||
tests = lib.filterAttrs (
|
||||
key: _: (lib.hasSuffix (lib.versions.major version) key)
|
||||
) nixosTests.nextcloud;
|
||||
tests = nixosTests.nextcloud."nextcloud${lib.versions.major version}";
|
||||
inherit packages;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user