2020-07-18 16:06:22 +00:00
|
|
|
{ system ? builtins.currentSystem,
|
|
|
|
config ? {},
|
2021-12-06 16:07:01 +00:00
|
|
|
pkgs ? import ../../.. { inherit system config; }
|
2020-07-18 16:06:22 +00:00
|
|
|
}:
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
let
|
2021-12-06 16:07:01 +00:00
|
|
|
inherit (import ../../lib/testing-python.nix { inherit system pkgs; }) makeTest;
|
2020-07-18 16:06:22 +00:00
|
|
|
f = backend: makeTest {
|
2020-04-24 23:36:52 +00:00
|
|
|
name = "ihatemoney-${backend}";
|
2022-04-03 18:54:34 +00:00
|
|
|
nodes.machine = { nodes, lib, ... }: {
|
2020-04-24 23:36:52 +00:00
|
|
|
services.ihatemoney = {
|
|
|
|
enable = true;
|
|
|
|
enablePublicProjectCreation = true;
|
2021-12-06 16:07:01 +00:00
|
|
|
secureCookie = false;
|
2020-04-24 23:36:52 +00:00
|
|
|
inherit backend;
|
|
|
|
uwsgiConfig = {
|
|
|
|
http = ":8000";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
boot.cleanTmpDir = true;
|
2021-12-06 16:07:01 +00:00
|
|
|
# for exchange rates
|
|
|
|
security.pki.certificateFiles = [ ./server.crt ];
|
|
|
|
networking.extraHosts = "127.0.0.1 api.exchangerate.host";
|
|
|
|
services.nginx = {
|
|
|
|
enable = true;
|
|
|
|
virtualHosts."api.exchangerate.host" = {
|
|
|
|
addSSL = true;
|
|
|
|
# openssl req -x509 -newkey rsa:4096 -keyout server.key -out server.crt -days 1000000 -nodes -subj '/CN=api.exchangerate.host'
|
|
|
|
sslCertificate = ./server.crt;
|
|
|
|
sslCertificateKey = ./server.key;
|
|
|
|
locations."/".return = "200 '${builtins.readFile ./rates.json}'";
|
|
|
|
};
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
# ihatemoney needs a local smtp server otherwise project creation just crashes
|
2022-06-16 17:23:12 +00:00
|
|
|
services.postfix.enable = true;
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
testScript = ''
|
|
|
|
machine.wait_for_open_port(8000)
|
|
|
|
machine.wait_for_unit("uwsgi.service")
|
2021-12-06 16:07:01 +00:00
|
|
|
machine.wait_until_succeeds("curl --fail https://api.exchangerate.host")
|
|
|
|
machine.wait_until_succeeds("curl --fail http://localhost:8000")
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2021-12-06 16:07:01 +00:00
|
|
|
result = machine.succeed(
|
|
|
|
"curl --fail -X POST http://localhost:8000/api/projects -d 'name=yay&id=yay&password=yay&contact_email=yay@example.com&default_currency=XXX'"
|
2020-04-24 23:36:52 +00:00
|
|
|
)
|
2021-12-06 16:07:01 +00:00
|
|
|
assert '"yay"' in result, repr(result)
|
2020-04-24 23:36:52 +00:00
|
|
|
owner, timestamp = machine.succeed(
|
|
|
|
"stat --printf %U:%G___%Y /var/lib/ihatemoney/secret_key"
|
|
|
|
).split("___")
|
|
|
|
assert "ihatemoney:ihatemoney" == owner
|
|
|
|
|
|
|
|
with subtest("Restart machine and service"):
|
|
|
|
machine.shutdown()
|
|
|
|
machine.start()
|
|
|
|
machine.wait_for_open_port(8000)
|
|
|
|
machine.wait_for_unit("uwsgi.service")
|
|
|
|
|
|
|
|
with subtest("check that the database is really persistent"):
|
2021-12-06 16:07:01 +00:00
|
|
|
machine.succeed("curl --fail --basic -u yay:yay http://localhost:8000/api/projects/yay")
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
with subtest("check that the secret key is really persistent"):
|
|
|
|
timestamp2 = machine.succeed("stat --printf %Y /var/lib/ihatemoney/secret_key")
|
|
|
|
assert timestamp == timestamp2
|
|
|
|
|
2021-12-06 16:07:01 +00:00
|
|
|
assert "ihatemoney" in machine.succeed("curl --fail http://localhost:8000")
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
2020-07-18 16:06:22 +00:00
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
in {
|
|
|
|
ihatemoney-sqlite = f "sqlite";
|
|
|
|
ihatemoney-postgresql = f "postgresql";
|
|
|
|
}
|