1import ../make-test-python.nix ({ pkgs, ... }: {
2 name = "ejabberd";
3 meta = with pkgs.lib.maintainers; {
4 maintainers = [ ];
5 };
6 nodes = {
7 client = { nodes, pkgs, ... }: {
8 networking.extraHosts = ''
9 ${nodes.server.config.networking.primaryIPAddress} example.com
10 '';
11
12 environment.systemPackages = [
13 (pkgs.callPackage ./xmpp-sendmessage.nix { connectTo = nodes.server.config.networking.primaryIPAddress; })
14 ];
15 };
16 server = { config, pkgs, ... }: {
17 networking.extraHosts = ''
18 ${config.networking.primaryIPAddress} example.com
19 '';
20
21 services.ejabberd = {
22 enable = true;
23 configFile = "/etc/ejabberd.yml";
24 };
25
26 environment.etc."ejabberd.yml" = {
27 user = "ejabberd";
28 mode = "0600";
29 text = ''
30 loglevel: 3
31
32 hosts:
33 - "example.com"
34
35 listen:
36 -
37 port: 5222
38 module: ejabberd_c2s
39 zlib: false
40 max_stanza_size: 65536
41 shaper: c2s_shaper
42 access: c2s
43 -
44 port: 5269
45 ip: "::"
46 module: ejabberd_s2s_in
47 -
48 port: 5347
49 ip: "127.0.0.1"
50 module: ejabberd_service
51 access: local
52 shaper: fast
53 -
54 port: 5444
55 module: ejabberd_http
56 request_handlers:
57 "/upload": mod_http_upload
58
59 ## Disabling digest-md5 SASL authentication. digest-md5 requires plain-text
60 ## password storage (see auth_password_format option).
61 disable_sasl_mechanisms: "digest-md5"
62
63 ## Outgoing S2S options
64 ## Preferred address families (which to try first) and connect timeout
65 ## in seconds.
66 outgoing_s2s_families:
67 - ipv4
68 - ipv6
69
70 ## auth_method: Method used to authenticate the users.
71 ## The default method is the internal.
72 ## If you want to use a different method,
73 ## comment this line and enable the correct ones.
74 auth_method: internal
75
76 ## Store the plain passwords or hashed for SCRAM:
77 ## auth_password_format: plain
78 auth_password_format: scram
79
80 ###' TRAFFIC SHAPERS
81 shaper:
82 # in B/s
83 normal: 1000000
84 fast: 50000000
85
86 ## This option specifies the maximum number of elements in the queue
87 ## of the FSM. Refer to the documentation for details.
88 max_fsm_queue: 1000
89
90 ###' ACCESS CONTROL LISTS
91 acl:
92 ## The 'admin' ACL grants administrative privileges to XMPP accounts.
93 ## You can put here as many accounts as you want.
94 admin:
95 user:
96 - "root": "example.com"
97
98 ## Local users: don't modify this.
99 local:
100 user_regexp: ""
101
102 ## Loopback network
103 loopback:
104 ip:
105 - "127.0.0.0/8"
106 - "::1/128"
107 - "::FFFF:127.0.0.1/128"
108
109 ###' SHAPER RULES
110 shaper_rules:
111 ## Maximum number of simultaneous sessions allowed for a single user:
112 max_user_sessions: 10
113 ## Maximum number of offline messages that users can have:
114 max_user_offline_messages:
115 - 5000: admin
116 - 1024
117 ## For C2S connections, all users except admins use the "normal" shaper
118 c2s_shaper:
119 - none: admin
120 - normal
121 ## All S2S connections use the "fast" shaper
122 s2s_shaper: fast
123
124 ###' ACCESS RULES
125 access_rules:
126 ## This rule allows access only for local users:
127 local:
128 - allow: local
129 ## Only non-blocked users can use c2s connections:
130 c2s:
131 - deny: blocked
132 - allow
133 ## Only admins can send announcement messages:
134 announce:
135 - allow: admin
136 ## Only admins can use the configuration interface:
137 configure:
138 - allow: admin
139 ## Only accounts of the local ejabberd server can create rooms:
140 muc_create:
141 - allow: local
142 ## Only accounts on the local ejabberd server can create Pubsub nodes:
143 pubsub_createnode:
144 - allow: local
145 ## In-band registration allows registration of any possible username.
146 ## To disable in-band registration, replace 'allow' with 'deny'.
147 register:
148 - allow
149 ## Only allow to register from localhost
150 trusted_network:
151 - allow: loopback
152
153 ## ===============
154 ## API PERMISSIONS
155 ## ===============
156 ##
157 ## This section allows you to define who and using what method
158 ## can execute commands offered by ejabberd.
159 ##
160 ## By default "console commands" section allow executing all commands
161 ## issued using ejabberdctl command, and "admin access" section allows
162 ## users in admin acl that connect from 127.0.0.1 to execute all
163 ## commands except start and stop with any available access method
164 ## (ejabberdctl, http-api, xmlrpc depending what is enabled on server).
165 ##
166 ## If you remove "console commands" there will be one added by
167 ## default allowing executing all commands, but if you just change
168 ## permissions in it, version from config file will be used instead
169 ## of default one.
170 ##
171 api_permissions:
172 "console commands":
173 from:
174 - ejabberd_ctl
175 who: all
176 what: "*"
177
178 language: "en"
179
180 ###' MODULES
181 ## Modules enabled in all ejabberd virtual hosts.
182 modules:
183 mod_adhoc: {}
184 mod_announce: # recommends mod_adhoc
185 access: announce
186 mod_blocking: {} # requires mod_privacy
187 mod_caps: {}
188 mod_carboncopy: {}
189 mod_client_state: {}
190 mod_configure: {} # requires mod_adhoc
191 ## mod_delegation: {} # for xep0356
192 mod_disco: {}
193 #mod_irc:
194 # host: "irc.@HOST@"
195 # default_encoding: "utf-8"
196 ## mod_bosh: {}
197 ## mod_http_fileserver:
198 ## docroot: "/var/www"
199 ## accesslog: "/var/log/ejabberd/access.log"
200 mod_http_upload:
201 thumbnail: false # otherwise needs the identify command from ImageMagick installed
202 put_url: "http://@HOST@:5444/upload"
203 ## # docroot: "@HOME@/upload"
204 #mod_http_upload_quota:
205 # max_days: 14
206 mod_last: {}
207 ## XEP-0313: Message Archive Management
208 ## You might want to setup a SQL backend for MAM because the mnesia database is
209 ## limited to 2GB which might be exceeded on large servers
210 mod_mam: {}
211 mod_muc:
212 host: "muc.@HOST@"
213 access:
214 - allow
215 access_admin:
216 - allow: admin
217 access_create: muc_create
218 access_persistent: muc_create
219 mod_muc_admin: {}
220 mod_muc_log: {}
221 mod_offline:
222 access_max_user_messages: max_user_offline_messages
223 mod_ping: {}
224 ## mod_pres_counter:
225 ## count: 5
226 ## interval: 60
227 mod_privacy: {}
228 mod_private: {}
229 mod_roster:
230 versioning: true
231 mod_shared_roster: {}
232 mod_stats: {}
233 mod_time: {}
234 mod_vcard:
235 search: false
236 mod_vcard_xupdate: {}
237 ## Convert all avatars posted by Android clients from WebP to JPEG
238 mod_avatar: {}
239 # convert:
240 # webp: jpeg
241 mod_version: {}
242 mod_stream_mgmt: {}
243 ## The module for S2S dialback (XEP-0220). Please note that you cannot
244 ## rely solely on dialback if you want to federate with other servers,
245 ## because a lot of servers have dialback disabled and instead rely on
246 ## PKIX authentication. Make sure you have proper certificates installed
247 ## and check your accessibility at https://check.messaging.one/
248 mod_s2s_dialback: {}
249 mod_pubsub:
250 plugins:
251 - "pep"
252 mod_push: {}
253 '';
254 };
255
256 networking.firewall.enable = false;
257 };
258 };
259
260 testScript = { nodes, ... }: ''
261 ejabberd_prefix = "su ejabberd -s $(which ejabberdctl) "
262
263 server.wait_for_unit("ejabberd.service")
264
265 assert "status: started" in server.succeed(ejabberd_prefix + "status")
266
267 server.succeed(
268 ejabberd_prefix + "register azurediamond example.com hunter2",
269 ejabberd_prefix + "register cthon98 example.com nothunter2",
270 )
271 server.fail(ejabberd_prefix + "register asdf wrong.domain")
272 client.succeed("send-message")
273 server.succeed(
274 ejabberd_prefix + "unregister cthon98 example.com",
275 ejabberd_prefix + "unregister azurediamond example.com",
276 )
277 '';
278})