1 { system ? builtins.currentSystem,
3 pkgs ? import ../../.. { inherit system config; }
7 inherit (import ../../lib/testing-python.nix { inherit system pkgs; }) makeTest;
8 f = backend: makeTest {
9 name = "ihatemoney-${backend}";
10 nodes.machine = { nodes, lib, ... }: {
11 services.ihatemoney = {
13 enablePublicProjectCreation = true;
20 boot.cleanTmpDir = true;
22 security.pki.certificateFiles = [ ./server.crt ];
23 networking.extraHosts = "127.0.0.1 api.exchangerate.host";
26 virtualHosts."api.exchangerate.host" = {
28 # openssl req -x509 -newkey rsa:4096 -keyout server.key -out server.crt -days 1000000 -nodes -subj '/CN=api.exchangerate.host'
29 sslCertificate = ./server.crt;
30 sslCertificateKey = ./server.key;
31 locations."/".return = "200 '${builtins.readFile ./rates.json}'";
34 # ihatemoney needs a local smtp server otherwise project creation just crashes
35 services.postfix.enable = true;
38 machine.wait_for_open_port(8000)
39 machine.wait_for_unit("uwsgi.service")
40 machine.wait_until_succeeds("curl --fail https://api.exchangerate.host")
41 machine.wait_until_succeeds("curl --fail http://localhost:8000")
43 result = machine.succeed(
44 "curl --fail -X POST http://localhost:8000/api/projects -d 'name=yay&id=yay&password=yay&contact_email=yay@example.com&default_currency=XXX'"
46 assert '"yay"' in result, repr(result)
47 owner, timestamp = machine.succeed(
48 "stat --printf %U:%G___%Y /var/lib/ihatemoney/secret_key"
50 assert "ihatemoney:ihatemoney" == owner
52 with subtest("Restart machine and service"):
55 machine.wait_for_open_port(8000)
56 machine.wait_for_unit("uwsgi.service")
58 with subtest("check that the database is really persistent"):
59 machine.succeed("curl --fail --basic -u yay:yay http://localhost:8000/api/projects/yay")
61 with subtest("check that the secret key is really persistent"):
62 timestamp2 = machine.succeed("stat --printf %Y /var/lib/ihatemoney/secret_key")
63 assert timestamp == timestamp2
65 assert "ihatemoney" in machine.succeed("curl --fail http://localhost:8000")
69 ihatemoney-sqlite = f "sqlite";
70 ihatemoney-postgresql = f "postgresql";