diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index 3909334e0f78..86b72c45f57a 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -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; diff --git a/nixos/tests/nextcloud/basic.nix b/nixos/tests/nextcloud/basic.nix index 523678971643..1177fd292ac2 100644 --- a/nixos/tests/nextcloud/basic.nix +++ b/nixos/tests/nextcloud/basic.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 $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 &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}\"") + ''; +} diff --git a/nixos/tests/nextcloud/with-mail.nix b/nixos/tests/nextcloud/with-mail.nix index 0a193ce76076..c783710d5f09 100644 --- a/nixos/tests/nextcloud/with-mail.nix +++ b/nixos/tests/nextcloud/with-mail.nix @@ -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") + ''; +} diff --git a/nixos/tests/nextcloud/with-mysql-and-memcached.nix b/nixos/tests/nextcloud/with-mysql-and-memcached.nix index f05dcd0a9835..a2cbd8dffcdb 100644 --- a/nixos/tests/nextcloud/with-mysql-and-memcached.nix +++ b/nixos/tests/nextcloud/with-mysql-and-memcached.nix @@ -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}") + ''; +} diff --git a/nixos/tests/nextcloud/with-objectstore.nix b/nixos/tests/nextcloud/with-objectstore.nix index 39235d4f1fc9..532d2c1a9377 100644 --- a/nixos/tests/nextcloud/with-objectstore.nix +++ b/nixos/tests/nextcloud/with-objectstore.nix @@ -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)") - ''; - } -) +} diff --git a/nixos/tests/nextcloud/with-postgresql-and-redis.nix b/nixos/tests/nextcloud/with-postgresql-and-redis.nix index ed4eea689fd0..7b9b66981d35 100644 --- a/nixos/tests/nextcloud/with-postgresql-and-redis.nix +++ b/nixos/tests/nextcloud/with-postgresql-and-redis.nix @@ -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") + ''; +} diff --git a/nixos/tests/stalwart/stalwart-config.nix b/nixos/tests/stalwart/stalwart-config.nix index 399b527ea1d4..c3c64f4a6876 100644 --- a/nixos/tests/stalwart/stalwart-config.nix +++ b/nixos/tests/stalwart/stalwart-config.nix @@ -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 diff --git a/pkgs/by-name/ne/nextcloud-notify_push/package.nix b/pkgs/by-name/ne/nextcloud-notify_push/package.nix index 48ce67865531..18ae85789e93 100644 --- a/pkgs/by-name/ne/nextcloud-notify_push/package.nix +++ b/pkgs/by-name/ne/nextcloud-notify_push/package.nix @@ -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; diff --git a/pkgs/servers/nextcloud/default.nix b/pkgs/servers/nextcloud/default.nix index 27ef2606cfba..6711bc2ab97c 100644 --- a/pkgs/servers/nextcloud/default.nix +++ b/pkgs/servers/nextcloud/default.nix @@ -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; };