1 import ./make-test-python.nix ({ pkgs, lib, ... }:
6 password = "correcthorsebatterystaple";
8 defaultUsername = "admin";
9 defaultPassword = "password";
10 adminCredentialsFile = pkgs.writeText "admin-credentials" ''
11 ADMIN_USERNAME=${defaultUsername}
12 ADMIN_PASSWORD=${defaultPassword}
14 customAdminCredentialsFile = pkgs.writeText "admin-credentials" ''
15 ADMIN_USERNAME=${username}
16 ADMIN_PASSWORD=${password}
18 postgresPassword = "correcthorsebatterystaple";
19 postgresPasswordFile = pkgs.writeText "pgpass" ''
20 *:*:*:*:${postgresPassword}
26 meta.maintainers = [ ];
32 security.apparmor.enable = true;
35 inherit adminCredentialsFile;
42 security.apparmor.enable = true;
45 inherit adminCredentialsFile;
47 security.sudo.enable = false;
53 security.apparmor.enable = true;
57 CLEANUP_FREQUENCY = "48";
58 LISTEN_ADDR = "localhost:${toString port}";
60 adminCredentialsFile = customAdminCredentialsFile;
64 postgresTcp = { config, pkgs, lib, ... }: {
65 services.postgresql = {
67 initialScript = pkgs.writeText "init-postgres" ''
68 CREATE USER miniflux WITH PASSWORD '${postgresPassword}';
69 CREATE DATABASE miniflux WITH OWNER miniflux;
73 host sameuser miniflux samenet scram-sha-256
76 systemd.services.postgresql.postStart = lib.mkAfter ''
77 $PSQL -tAd miniflux -c 'CREATE EXTENSION hstore;'
79 networking.firewall.allowedTCPPorts = [ config.services.postgresql.settings.port ];
81 externalDb = { ... }: {
82 security.apparmor.enable = true;
85 createDatabaseLocally = false;
86 inherit adminCredentialsFile;
88 DATABASE_URL = "user=miniflux host=postgresTcp dbname=miniflux sslmode=disable";
89 PGPASSFILE = "/run/miniflux/pgpass";
92 systemd.services.miniflux.preStart = ''
93 cp ${postgresPasswordFile} /run/miniflux/pgpass
94 chmod 600 /run/miniflux/pgpass
99 def runTest(machine, port, user):
100 machine.wait_for_unit("miniflux.service")
101 machine.wait_for_open_port(port)
102 machine.succeed(f"curl --fail 'http://localhost:{port}/healthcheck' | grep OK")
104 f"curl 'http://localhost:{port}/v1/me' -u '{user}' -H Content-Type:application/json | grep '\"is_admin\":true'"
106 machine.fail('journalctl -b --no-pager --grep "^audit: .*apparmor=\\"DENIED\\""')
113 runTest(default, ${toString defaultPort}, "${defaultUsername}:${defaultPassword}")
114 runTest(withoutSudo, ${toString defaultPort}, "${defaultUsername}:${defaultPassword}")
115 runTest(customized, ${toString port}, "${username}:${password}")
117 postgresTcp.wait_for_unit("postgresql.service")
119 runTest(externalDb, ${toString defaultPort}, "${defaultUsername}:${defaultPassword}")