summaryrefslogtreecommitdiffstats
path: root/nixos/tests/invoiceplane.nix
blob: 991293c9c415b130900bc012876a90fd92ffbd71 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
{ pkgs, ... }:

{
  name = "invoiceplane";
  meta = with pkgs.lib.maintainers; {
    maintainers = [
      onny
    ];
  };

  nodes = {
    invoiceplane_caddy =
      { ... }:
      {
        services.invoiceplane.webserver = "caddy";
        services.invoiceplane.sites = {
          "site1.local" = {
            database.name = "invoiceplane1";
            database.createLocally = true;
            enable = true;
          };
          "site2.local" = {
            database.name = "invoiceplane2";
            database.createLocally = true;
            enable = true;
          };
        };

        services.caddy.virtualHosts."site1.local".extraConfig = ''
          tls internal
        '';
        services.caddy.virtualHosts."site2.local".extraConfig = ''
          tls internal
        '';

        networking.firewall.allowedTCPPorts = [
          80
          443
        ];
        networking.hosts."127.0.0.1" = [
          "site1.local"
          "site2.local"
        ];
      };

    invoiceplane_nginx =
      { ... }:
      {
        services.invoiceplane.webserver = "nginx";
        services.invoiceplane.sites = {
          "site1.local" = {
            database.name = "invoiceplane1";
            database.createLocally = true;
            enable = true;
          };
          "site2.local" = {
            database.name = "invoiceplane2";
            database.createLocally = true;
            enable = true;
          };
        };

        networking.firewall.allowedTCPPorts = [ 80 ];
        networking.hosts."127.0.0.1" = [
          "site1.local"
          "site2.local"
        ];
      };
  };

  testScript = ''
    start_all()

    invoiceplane_caddy.wait_for_unit("caddy")
    invoiceplane_nginx.wait_for_unit("nginx")

    site_names = ["site1.local", "site2.local"]

    machines = [invoiceplane_caddy, invoiceplane_nginx]

    for machine in machines:
      machine.wait_for_open_port(80)
      machine.wait_for_open_port(3306)

      for site_name in site_names:
          machine.wait_for_unit(f"phpfpm-invoiceplane-{site_name}")

          with subtest("Website returns welcome screen"):
              assert "Please install InvoicePlane" in machine.succeed(f"curl -sSfkL {site_name}")

          with subtest("Finish InvoicePlane setup"):
            machine.succeed(
              f"curl -sSfkL --cookie-jar cjar {site_name}/setup/language"
            )
            csrf_token = machine.succeed(
              "grep ip_csrf_cookie cjar | cut -f 7 | tr -d '\n'"
            )
            machine.succeed(
              f"curl -sSfkL --cookie cjar --cookie-jar cjar -d '_ip_csrf={csrf_token}&ip_lang=english&btn_continue=Continue' {site_name}/setup/language"
            )
            csrf_token = machine.succeed(
              "grep ip_csrf_cookie cjar | cut -f 7 | tr -d '\n'"
            )
            machine.succeed(
              f"curl -sSfkL --cookie cjar --cookie-jar cjar -d '_ip_csrf={csrf_token}&btn_continue=Continue' {site_name}/setup/prerequisites"
            )
            csrf_token = machine.succeed(
              "grep ip_csrf_cookie cjar | cut -f 7 | tr -d '\n'"
            )
            machine.succeed(
              f"curl -sSfkL --cookie cjar --cookie-jar cjar -d '_ip_csrf={csrf_token}&btn_continue=Continue' {site_name}/setup/configure_database"
            )
            csrf_token = machine.succeed(
              "grep ip_csrf_cookie cjar | cut -f 7 | tr -d '\n'"
            )
            machine.succeed(
              f"curl -sSfkl --cookie cjar --cookie-jar cjar -d '_ip_csrf={csrf_token}&btn_continue=Continue' {site_name}/setup/install_tables"
            )
            csrf_token = machine.succeed(
              "grep ip_csrf_cookie cjar | cut -f 7 | tr -d '\n'"
            )
            machine.succeed(
              f"curl -sSfkl --cookie cjar --cookie-jar cjar -d '_ip_csrf={csrf_token}&btn_continue=Continue' {site_name}/setup/upgrade_tables"
          )
  '';
}