at 25.11-pre 3.8 kB view raw
1import ../make-test-python.nix ( 2 { pkgs, lib, ... }: 3 { 4 name = "immich-public-proxy"; 5 6 nodes.machine = 7 { pkgs, ... }@args: 8 { 9 environment.systemPackages = [ 10 pkgs.imagemagick 11 pkgs.immich-cli 12 ]; 13 services.immich = { 14 enable = true; 15 port = 2283; 16 # disable a lot of features that aren't needed for this test 17 machine-learning.enable = false; 18 settings = { 19 backup.database.enabled = false; 20 machineLearning.enabled = false; 21 map.enabled = false; 22 reverseGeocoding.enabled = false; 23 metadata.faces.import = false; 24 newVersionCheck.enabled = false; 25 notifications.smtp.enabled = false; 26 }; 27 }; 28 services.immich-public-proxy = { 29 enable = true; 30 immichUrl = "http://localhost:2283"; 31 port = 8002; 32 settings.ipp.responseHeaders."X-NixOS" = "Rules"; 33 }; 34 }; 35 36 testScript = '' 37 import json 38 39 machine.wait_for_unit("immich-server.service") 40 machine.wait_for_unit("immich-public-proxy.service") 41 machine.wait_for_open_port(2283) 42 machine.wait_for_open_port(8002) 43 44 # The proxy should be up 45 machine.succeed("curl -sf http://localhost:8002") 46 47 # Verify the static assets are served 48 machine.succeed("curl -sf http://localhost:8002/robots.txt") 49 machine.succeed("curl -sf http://localhost:8002/share/static/style.css") 50 51 # Check that the response header in the settings is sent 52 res = machine.succeed(""" 53 curl -sD - http://localhost:8002 -o /dev/null 54 """) 55 assert "x-nixos: rules" in res.lower(), res 56 57 # Log in to Immich and create an access key 58 machine.succeed(""" 59 curl -sf --json '{ "email": "test@example.com", "name": "Admin", "password": "admin" }' http://localhost:2283/api/auth/admin-sign-up 60 """) 61 res = machine.succeed(""" 62 curl -sf --json '{ "email": "test@example.com", "password": "admin" }' http://localhost:2283/api/auth/login 63 """) 64 token = json.loads(res)['accessToken'] 65 res = machine.succeed(""" 66 curl -sf -H 'Cookie: immich_access_token=%s' --json '{ "name": "API Key", "permissions": ["all"] }' http://localhost:2283/api/api-keys 67 """ % token) 68 key = json.loads(res)['secret'] 69 machine.succeed(f"immich login http://localhost:2283/api {key}") 70 res = machine.succeed("immich server-info") 71 print(res) 72 73 # Upload some blank images to a new album 74 # If there's only one image, the proxy serves the image directly 75 machine.succeed("magick -size 800x600 canvas:white /tmp/white.png") 76 machine.succeed("immich upload -A ' Reproducible Moments ' /tmp/white.png") 77 machine.succeed("magick -size 800x600 canvas:black /tmp/black.png") 78 machine.succeed("immich upload -A ' Reproducible Moments ' /tmp/black.png") 79 res = machine.succeed("immich server-info") 80 print(res) 81 82 # Get the new album id 83 res = machine.succeed(""" 84 curl -sf -H 'Cookie: immich_access_token=%s' http://localhost:2283/api/albums 85 """ % token) 86 album_id = json.loads(res)[0]['id'] 87 88 # Create a shared link 89 res = machine.succeed(""" 90 curl -sf -H 'Cookie: immich_access_token=%s' --json '{ "albumId": "%s", "type": "ALBUM" }' http://localhost:2283/api/shared-links 91 """ % (token, album_id)) 92 share_key = json.loads(res)['key'] 93 94 # Access the share 95 machine.succeed(""" 96 curl -sf http://localhost:2283/share/%s 97 """ % share_key) 98 99 # Access the share through the proxy 100 machine.succeed(""" 101 curl -sf http://localhost:8002/share/%s 102 """ % share_key) 103 ''; 104 } 105)