@@ -0,0 +1,69 @@
1+import ../make-test.nix {
2+ name = "prosody-mysql";
3+
4+ nodes = {
5+ client = { nodes, pkgs, ... }: {
6+ environment.systemPackages = [
7+ (pkgs.callPackage ./xmpp-sendmessage.nix { connectTo = nodes.server.config.networking.primaryIPAddress; })
8+ ];
9+ };
10+ server = { config, pkgs, ... }: {
11+ networking.extraHosts = ''
12+ ${config.networking.primaryIPAddress} example.com
13+ '';
14+ networking.firewall.enable = false;
15+ services.prosody = {
16+ enable = true;
17+ # TODO: use a self-signed certificate
18+ c2sRequireEncryption = false;
19+ extraConfig = ''
20+ storage = "sql"
21+ sql = {
22+ driver = "MySQL";
23+ database = "prosody";
24+ host = "mysql";
25+ port = 3306;
26+ username = "prosody";
27+ password = "password123";
28+ };
29+ '';
30+ virtualHosts.test = {
31+ domain = "example.com";
32+ enabled = true;
33+ };
34+ };
35+ };
36+ mysql = { config, pkgs, ... }: {
37+ networking.firewall.enable = false;
38+ services.mysql = {
39+ enable = true;
40+ initialScript = pkgs.writeText "mysql_init.sql" ''
41+ CREATE DATABASE prosody;
42+ CREATE USER 'prosody'@'server' IDENTIFIED BY 'password123';
43+ GRANT ALL PRIVILEGES ON prosody.* TO 'prosody'@'server';
44+ FLUSH PRIVILEGES;
45+ '';
46+ package = pkgs.mariadb;
47+ };
48+ };
49+ };
50+
51+ testScript = { nodes, ... }: ''
52+ $mysql->waitForUnit('mysql.service');
53+ $server->waitForUnit('prosody.service');
54+ $server->succeed('prosodyctl status') =~ /Prosody is running/;
55+
56+ # set password to 'nothunter2' (it's asked twice)
57+ $server->succeed('yes nothunter2 | prosodyctl adduser cthon98@example.com');
58+ # set password to 'y'
59+ $server->succeed('yes | prosodyctl adduser azurediamond@example.com');
60+ # correct password to 'hunter2'
61+ $server->succeed('yes hunter2 | prosodyctl passwd azurediamond@example.com');
62+
63+ $client->succeed("send-message");
64+
65+ $server->succeed('prosodyctl deluser cthon98@example.com');
66+ $server->succeed('prosodyctl deluser azurediamond@example.com');
67+ '';
68+}
69+