about summary refs log tree commit diff
path: root/nixos/tests/dokuwiki.nix
blob: 15ccea23cf55436850f696ba4c0561509fb4896e (plain) (blame)
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
import ./make-test-python.nix ({ pkgs, ... }:

let
  template-bootstrap3 = pkgs.stdenv.mkDerivation {
    name = "bootstrap3";
    # Download the theme from the dokuwiki site
    src = pkgs.fetchurl {
      url = "https://github.com/giterlizzi/dokuwiki-template-bootstrap3/archive/v2019-05-22.zip";
      sha256 = "4de5ff31d54dd61bbccaf092c9e74c1af3a4c53e07aa59f60457a8f00cfb23a6";
    };
    # We need unzip to build this package
    nativeBuildInputs = [ pkgs.unzip ];
    # Installing simply means copying all files to the output directory
    installPhase = "mkdir -p $out; cp -R * $out/";
  };


  # Let's package the icalevents plugin
  plugin-icalevents = pkgs.stdenv.mkDerivation {
    name = "icalevents";
    # Download the plugin from the dokuwiki site
    src = pkgs.fetchurl {
      url = "https://github.com/real-or-random/dokuwiki-plugin-icalevents/releases/download/2017-06-16/dokuwiki-plugin-icalevents-2017-06-16.zip";
      sha256 = "e40ed7dd6bbe7fe3363bbbecb4de481d5e42385b5a0f62f6a6ce6bf3a1f9dfa8";
    };
    # We need unzip to build this package
    nativeBuildInputs = [ pkgs.unzip ];
    sourceRoot = ".";
    # Installing simply means copying all files to the output directory
    installPhase = "mkdir -p $out; cp -R * $out/";
  };

  acronymsFile = pkgs.writeText "acronyms.local.conf" ''
    r13y  reproducibility
  '';

  dwWithAcronyms = pkgs.dokuwiki.overrideAttrs (prev: {
    installPhase = prev.installPhase or "" + ''
      ln -sf ${acronymsFile} $out/share/dokuwiki/conf/acronyms.local.conf
    '';
  });

  mkNode = webserver: { ... }: {
    services.dokuwiki = {
      inherit webserver;

      sites = {
        "site1.local" = {
          aclUse = false;
          superUser = "admin";
        };
        "site2.local" = {
          package = dwWithAcronyms;
          usersFile = "/var/lib/dokuwiki/site2.local/users.auth.php";
          superUser = "admin";
          templates = [ template-bootstrap3 ];
          plugins = [ plugin-icalevents ];
        };
      };
    };

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

in {
  name = "dokuwiki";
  meta = with pkgs.lib; {
    maintainers = with maintainers; [
      _1000101
      onny
    ];
  };

  nodes = {
    dokuwiki_nginx = mkNode "nginx";
    dokuwiki_caddy = mkNode "caddy";
  };

  testScript = ''

    start_all()

    dokuwiki_nginx.wait_for_unit("nginx")
    dokuwiki_caddy.wait_for_unit("caddy")

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

    for machine in (dokuwiki_nginx, dokuwiki_caddy):
      for site_name in site_names:
        machine.wait_for_unit(f"phpfpm-dokuwiki-{site_name}")

        machine.succeed("curl -sSfL http://site1.local/ | grep 'DokuWiki'")
        machine.fail("curl -sSfL 'http://site1.local/doku.php?do=login' | grep 'Login'")

        machine.succeed("curl -sSfL http://site2.local/ | grep 'DokuWiki'")
        machine.succeed("curl -sSfL 'http://site2.local/doku.php?do=login' | grep 'Login'")

        with subtest("ACL Operations"):
          machine.succeed(
            "echo 'admin:$2y$10$ijdBQMzSVV20SrKtCna8gue36vnsbVm2wItAXvdm876sshI4uwy6S:Admin:admin@example.test:user' >> /var/lib/dokuwiki/site2.local/users.auth.php",
            "curl -sSfL -d 'u=admin&p=password' --cookie-jar cjar 'http://site2.local/doku.php?do=login'",
            "curl -sSfL --cookie cjar --cookie-jar cjar 'http://site2.local/doku.php?do=login' | grep 'Logged in as: <bdi>Admin</bdi>'",
          )

        with subtest("Customizing Dokuwiki"):
          machine.succeed(
            "echo 'r13y is awesome!' >> /var/lib/dokuwiki/site2.local/data/pages/acronyms-test.txt",
            "curl -sSfL 'http://site2.local/doku.php?id=acronyms-test' | grep '<abbr title=\"reproducibility\">r13y</abbr>'",
          )

        # Just to ensure both Webserver configurations are consistent in allowing that
        with subtest("Rewriting"):
          machine.succeed(
            "echo 'Hello, NixOS!' >> /var/lib/dokuwiki/site1.local/data/pages/rewrite-test.txt",
            "curl -sSfL http://site1.local/rewrite-test | grep 'Hello, NixOS!'",
          )
  '';
})