1import ./make-test-python.nix ({ pkgs, ... }:
2
3{
4 name = "wordpress";
5 meta = with pkgs.lib.maintainers; {
6 maintainers = [
7 flokli
8 grahamc # under duress!
9 mmilata
10 ];
11 };
12
13 nodes = {
14 wp_httpd = { ... }: {
15 services.httpd.adminAddr = "webmaster@site.local";
16 services.httpd.logPerVirtualHost = true;
17
18 services.wordpress = {
19 # Test support for old interface
20 "site1.local" = {
21 database.tablePrefix = "site1_";
22 };
23 sites = {
24 "site2.local" = {
25 database.tablePrefix = "site2_";
26 };
27 };
28 };
29
30 networking.firewall.allowedTCPPorts = [ 80 ];
31 networking.hosts."127.0.0.1" = [ "site1.local" "site2.local" ];
32 };
33
34 wp_nginx = { ... }: {
35 services.wordpress.webserver = "nginx";
36 services.wordpress.sites = {
37 "site1.local" = {
38 database.tablePrefix = "site1_";
39 };
40 "site2.local" = {
41 database.tablePrefix = "site2_";
42 };
43 };
44
45 networking.firewall.allowedTCPPorts = [ 80 ];
46 networking.hosts."127.0.0.1" = [ "site1.local" "site2.local" ];
47 };
48
49 wp_caddy = { ... }: {
50 services.wordpress.webserver = "caddy";
51 services.wordpress.sites = {
52 "site1.local" = {
53 database.tablePrefix = "site1_";
54 };
55 "site2.local" = {
56 database.tablePrefix = "site2_";
57 };
58 };
59
60 networking.firewall.allowedTCPPorts = [ 80 ];
61 networking.hosts."127.0.0.1" = [ "site1.local" "site2.local" ];
62 };
63 };
64
65 testScript = ''
66 import re
67
68 start_all()
69
70 wp_httpd.wait_for_unit("httpd")
71 wp_nginx.wait_for_unit("nginx")
72 wp_caddy.wait_for_unit("caddy")
73
74 site_names = ["site1.local", "site2.local"]
75
76 for machine in (wp_httpd, wp_nginx, wp_caddy):
77 for site_name in site_names:
78 machine.wait_for_unit(f"phpfpm-wordpress-{site_name}")
79
80 with subtest("website returns welcome screen"):
81 assert "Welcome to the famous" in machine.succeed(f"curl -L {site_name}")
82
83 with subtest("wordpress-init went through"):
84 info = machine.get_unit_info(f"wordpress-init-{site_name}")
85 assert info["Result"] == "success"
86
87 with subtest("secret keys are set"):
88 pattern = re.compile(r"^define.*NONCE_SALT.{64,};$", re.MULTILINE)
89 assert pattern.search(
90 machine.succeed(f"cat /var/lib/wordpress/{site_name}/secret-keys.php")
91 )
92 '';
93})