Merge branch 'staging-next' into staging
[NixPkgs.git] / nixos / tests / davis.nix
blob68958cee7a4309ac717ed0a1985e735b0a1ff485
1 import ./make-test-python.nix (
2   { lib, pkgs, ... }:
4   {
5     name = "davis";
7     meta.maintainers = pkgs.davis.meta.maintainers;
9     nodes.machine =
10       { config, ... }:
11       {
12         virtualisation = {
13           memorySize = 512;
14         };
16         services.davis = {
17           enable = true;
18           hostname = "davis.example.com";
19           database = {
20             driver = "postgresql";
21           };
22           mail = {
23             dsnFile = "${pkgs.writeText "davisMailDns" "smtp://username:password@example.com:25"}";
24             inviteFromAddress = "dav@example.com";
25           };
26           adminLogin = "admin";
27           appSecretFile = "${pkgs.writeText "davisAppSecret" "52882ef142066e09ab99ce816ba72522e789505caba224"}";
28           adminPasswordFile = "${pkgs.writeText "davisAdminPass" "nixos"}";
29           nginx = { };
30         };
31       };
33     testScript = ''
34       start_all()
35       machine.wait_for_unit("postgresql.service")
36       machine.wait_for_unit("davis-env-setup.service")
37       machine.wait_for_unit("davis-db-migrate.service")
38       machine.wait_for_unit("nginx.service")
39       machine.wait_for_unit("phpfpm-davis.service")
41       with subtest("welcome screen loads"):
42           machine.succeed(
43               "curl -sSfL --resolve davis.example.com:80:127.0.0.1 http://davis.example.com/ | grep '<title>Davis</title>'"
44           )
46       with subtest("login works"):
47           csrf_token = machine.succeed(
48               "curl -c /tmp/cookies -sSfL --resolve davis.example.com:80:127.0.0.1 http://davis.example.com/login | grep '_csrf_token' | sed -E 's,.*value=\"(.*)\".*,\\1,g'"
49           )
50           r = machine.succeed(
51               f"curl -b /tmp/cookies --resolve davis.example.com:80:127.0.0.1 http://davis.example.com/login -X POST -F username=admin -F password=nixos -F _csrf_token={csrf_token.strip()} -D headers"
52           )
53           print(r)
54           machine.succeed(
55             "[[ $(grep -i 'location: ' headers | cut -d: -f2- | xargs echo) == /dashboard* ]]"
56           )
57     '';
58   }