1{ lib, ... }:
2
3let
4 movim = {
5 domain = "movim.local";
6 port = 8080;
7 info = "No ToS in tests";
8 description = "NixOS testing server";
9 };
10 prosody = {
11 domain = "prosody.local";
12 admin = rec {
13 JID = "${username}@${prosody.domain}";
14 username = "romeo";
15 password = "juliet";
16 };
17 };
18in
19{
20 name = "movim-prosody-nginx";
21
22 meta = {
23 maintainers = with lib.maintainers; [ toastal ];
24 };
25
26 nodes = {
27 server =
28 { pkgs, ... }:
29 {
30 environment.systemPackages = [
31 # For testing
32 pkgs.websocat
33 ];
34
35 services.movim = {
36 inherit (movim) domain port;
37 enable = true;
38 verbose = true;
39 podConfig = {
40 inherit (movim) description info;
41 xmppdomain = prosody.domain;
42 };
43 nginx = { };
44 };
45
46 services.prosody = {
47 enable = true;
48 xmppComplianceSuite = false;
49 disco_items = [
50 {
51 url = "upload.${prosody.domain}";
52 description = "File Uploads";
53 }
54 ];
55 virtualHosts."${prosody.domain}" = {
56 inherit (prosody) domain;
57 enabled = true;
58 extraConfig = ''
59 Component "pubsub.${prosody.domain}" "pubsub"
60 pubsub_max_items = 10000
61 expose_publisher = true
62
63 Component "upload.${prosody.domain}" "http_file_share"
64 http_external_url = "http://upload.${prosody.domain}"
65 http_file_share_expires_after = 300 * 24 * 60 * 60
66 http_file_share_size_limit = 1024 * 1024 * 1024
67 http_file_share_daily_quota = 4 * 1024 * 1024 * 1024
68 '';
69 };
70 extraConfig = ''
71 pep_max_items = 10000
72
73 http_paths = {
74 file_share = "/";
75 }
76 '';
77 };
78
79 networking.extraHosts = ''
80 127.0.0.1 ${movim.domain}
81 127.0.0.1 ${prosody.domain}
82 '';
83 };
84 };
85
86 testScript = # python
87 ''
88 server.wait_for_unit("phpfpm-movim.service")
89 server.wait_for_unit("nginx.service")
90 server.wait_for_open_port(${builtins.toString movim.port})
91 server.wait_for_open_port(80)
92
93 server.wait_for_unit("prosody.service")
94 server.succeed('prosodyctl status | grep "Prosody is running"')
95 server.succeed("prosodyctl register ${prosody.admin.username} ${prosody.domain} ${prosody.admin.password}")
96
97 server.wait_for_unit("movim.service")
98
99 # Test unauthenticated
100 server.fail("curl -L --fail-with-body --max-redirs 0 http://${movim.domain}/chat")
101
102 # Test basic Websocket
103 server.succeed("echo | websocat --origin 'http://${movim.domain}' 'ws://${movim.domain}/ws/?path=login&offset=0'")
104
105 # Test login + create cookiejar
106 login_html = server.succeed("curl --fail-with-body -c /tmp/cookies http://${movim.domain}/login")
107 assert "${movim.description}" in login_html
108 assert "${movim.info}" in login_html
109
110 # Test authentication POST
111 server.succeed("curl --fail-with-body -b /tmp/cookies -X POST --data-urlencode 'username=${prosody.admin.JID}' --data-urlencode 'password=${prosody.admin.password}' http://${movim.domain}/login")
112
113 server.succeed("curl -L --fail-with-body --max-redirs 1 -b /tmp/cookies http://${movim.domain}/chat")
114 '';
115}