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