1 { name, pkgs, testBase, system, ... }:
3 with import ../../lib/testing-python.nix { inherit system pkgs; };
4 runTest ({ config, lib, ... }: let
5 accessKey = "BKIKJAA5BMMU2RHO6IBB";
6 secretKey = "V7f1CwQqAcwo80UEIJEjc5gVQUSSx5ohQ9GSrr12";
8 rootCredentialsFile = pkgs.writeText "minio-credentials-full" ''
9 MINIO_ROOT_USER=${accessKey}
10 MINIO_ROOT_PASSWORD=${secretKey}
14 meta = with pkgs.lib.maintainers; {
15 maintainers = [ onny ma27 ];
18 imports = [ testBase ];
21 nextcloud = { config, pkgs, ... }: {
22 networking.firewall.allowedTCPPorts = [ 9000 ];
23 environment.systemPackages = [ pkgs.minio-client ];
25 services.nextcloud.config.objectstore.s3 = {
30 secretFile = "${pkgs.writeText "secretKey" secretKey}";
31 hostname = "nextcloud";
40 listenAddress = "0.0.0.0:9000";
41 consoleAddress = "0.0.0.0:9001";
42 inherit rootCredentialsFile;
47 test-helpers.init = ''
48 nextcloud.wait_for_open_port(9000)
51 test-helpers.extraTests = { nodes, ... }: ''
52 with subtest("File is not on the filesystem"):
53 nextcloud.succeed("test ! -e ${nodes.nextcloud.services.nextcloud.home}/data/root/files/test-shared-file")
55 with subtest("Check if file is in S3"):
57 "mc config host add minio http://localhost:9000 ${accessKey} ${secretKey} --api s3v4"
59 files = nextcloud.succeed('mc ls minio/nextcloud|sort').strip().split('\n')
61 # Cannot assert an exact number here, nc27 writes more stuff initially into S3.
62 # For now let's assume it's always the most recently added file.
63 assert len(files) > 0, f"""
64 Expected to have at least one object in minio/nextcloud. But `mc ls` gave output:
70 ptrn = re.compile("^\[[A-Z0-9 :-]+\] +(?P<details>[A-Za-z0-9 :]+)$")
71 match = ptrn.match(files[-1].strip())
72 assert match, "Cannot match mc client output!"
73 size, type_, file = tuple(match.group('details').split(' '))
75 assert size == "3B", f"""
76 Expected size of uploaded file to be 3 bytes, got {size}
79 assert type_ == 'STANDARD', f"""
80 Expected type of bucket entry to be a file, i.e. 'STANDARD'. Got {type_}
83 assert file.startswith('urn:oid'), """
84 Expected filename to start with 'urn:oid', instead got '{file}.
87 with subtest("Test download from S3"):
89 "env AWS_ACCESS_KEY_ID=${accessKey} AWS_SECRET_ACCESS_KEY=${secretKey} "
90 + f"${lib.getExe pkgs.awscli2} s3 cp s3://nextcloud/{file} test --endpoint-url http://nextcloud:9000 "
91 + "--region us-east-1"
94 client.succeed("test hi = $(cat test)")