9 with import ../../lib/testing-python.nix { inherit system pkgs; };
13 accessKey = "BKIKJAA5BMMU2RHO6IBB";
14 secretKey = "V7f1CwQqAcwo80UEIJEjc5gVQUSSx5ohQ9GSrr12";
16 rootCredentialsFile = pkgs.writeText "minio-credentials-full" ''
17 MINIO_ROOT_USER=${accessKey}
18 MINIO_ROOT_PASSWORD=${secretKey}
23 meta = with pkgs.lib.maintainers; {
30 imports = [ testBase ];
34 { config, pkgs, ... }:
36 networking.firewall.allowedTCPPorts = [ 9000 ];
37 environment.systemPackages = [ pkgs.minio-client ];
39 services.nextcloud.config.objectstore.s3 = {
44 secretFile = "${pkgs.writeText "secretKey" secretKey}";
45 hostname = "nextcloud";
54 listenAddress = "0.0.0.0:9000";
55 consoleAddress = "0.0.0.0:9001";
56 inherit rootCredentialsFile;
61 test-helpers.init = ''
62 nextcloud.wait_for_open_port(9000)
65 test-helpers.extraTests =
68 with subtest("File is not on the filesystem"):
69 nextcloud.succeed("test ! -e ${nodes.nextcloud.services.nextcloud.home}/data/root/files/test-shared-file")
71 with subtest("Check if file is in S3"):
73 "mc config host add minio http://localhost:9000 ${accessKey} ${secretKey} --api s3v4"
75 files = nextcloud.succeed('mc ls minio/nextcloud|sort').strip().split('\n')
77 # Cannot assert an exact number here, nc27 writes more stuff initially into S3.
78 # For now let's assume it's always the most recently added file.
79 assert len(files) > 0, f"""
80 Expected to have at least one object in minio/nextcloud. But `mc ls` gave output:
86 ptrn = re.compile("^\[[A-Z0-9 :-]+\] +(?P<details>[A-Za-z0-9 :]+)$")
87 match = ptrn.match(files[-1].strip())
88 assert match, "Cannot match mc client output!"
89 size, type_, file = tuple(match.group('details').split(' '))
91 assert size == "3B", f"""
92 Expected size of uploaded file to be 3 bytes, got {size}
95 assert type_ == 'STANDARD', f"""
96 Expected type of bucket entry to be a file, i.e. 'STANDARD'. Got {type_}
99 assert file.startswith('urn:oid'), """
100 Expected filename to start with 'urn:oid', instead got '{file}.
103 with subtest("Test download from S3"):
105 "env AWS_ACCESS_KEY_ID=${accessKey} AWS_SECRET_ACCESS_KEY=${secretKey} "
106 + f"${lib.getExe pkgs.awscli2} s3 cp s3://nextcloud/{file} test --endpoint-url http://nextcloud:9000 "
107 + "--region us-east-1"
110 client.succeed("test hi = $(cat test)")