1let
2 cert = pkgs: pkgs.runCommand "selfSignedCerts" { buildInputs = [ pkgs.openssl ]; } ''
3 openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -nodes -subj '/CN=example.com/CN=uploads.example.com/CN=conference.example.com' -days 36500
4 mkdir -p $out
5 cp key.pem cert.pem $out
6 '';
7 createUsers = pkgs: pkgs.writeScriptBin "create-prosody-users" ''
8 #!${pkgs.bash}/bin/bash
9 set -e
10
11 # Creates and set password for the 2 xmpp test users.
12 #
13 # Doing that in a bash script instead of doing that in the test
14 # script allow us to easily provision the users when running that
15 # test interactively.
16
17 prosodyctl register cthon98 example.com nothunter2
18 prosodyctl register azurediamond example.com hunter2
19 '';
20 delUsers = pkgs: pkgs.writeScriptBin "delete-prosody-users" ''
21 #!${pkgs.bash}/bin/bash
22 set -e
23
24 # Deletes the test users.
25 #
26 # Doing that in a bash script instead of doing that in the test
27 # script allow us to easily provision the users when running that
28 # test interactively.
29
30 prosodyctl deluser cthon98@example.com
31 prosodyctl deluser azurediamond@example.com
32 '';
33in import ../make-test-python.nix {
34 name = "prosody-mysql";
35 nodes = {
36 client = { nodes, pkgs, config, ... }: {
37 security.pki.certificateFiles = [ "${cert pkgs}/cert.pem" ];
38 console.keyMap = "fr-bepo";
39 networking.extraHosts = ''
40 ${nodes.server.config.networking.primaryIPAddress} example.com
41 ${nodes.server.config.networking.primaryIPAddress} conference.example.com
42 ${nodes.server.config.networking.primaryIPAddress} uploads.example.com
43 '';
44 environment.systemPackages = [
45 (pkgs.callPackage ./xmpp-sendmessage.nix { connectTo = nodes.server.config.networking.primaryIPAddress; })
46 ];
47 };
48 server = { config, pkgs, ... }: {
49 nixpkgs.overlays = [
50 (self: super: {
51 prosody = super.prosody.override {
52 withExtraLuaPackages = p: [ p.luadbi-mysql ];
53 };
54 })
55 ];
56 security.pki.certificateFiles = [ "${cert pkgs}/cert.pem" ];
57 console.keyMap = "fr-bepo";
58 networking.extraHosts = ''
59 ${config.networking.primaryIPAddress} example.com
60 ${config.networking.primaryIPAddress} conference.example.com
61 ${config.networking.primaryIPAddress} uploads.example.com
62 '';
63 networking.firewall.enable = false;
64 environment.systemPackages = [
65 (createUsers pkgs)
66 (delUsers pkgs)
67 ];
68 services.prosody = {
69 enable = true;
70 ssl.cert = "${cert pkgs}/cert.pem";
71 ssl.key = "${cert pkgs}/key.pem";
72 virtualHosts.example = {
73 domain = "example.com";
74 enabled = true;
75 ssl.cert = "${cert pkgs}/cert.pem";
76 ssl.key = "${cert pkgs}/key.pem";
77 };
78 muc = [
79 {
80 domain = "conference.example.com";
81 }
82 ];
83 uploadHttp = {
84 domain = "uploads.example.com";
85 };
86 extraConfig = ''
87 storage = "sql"
88 sql = {
89 driver = "MySQL";
90 database = "prosody";
91 host = "mysql";
92 port = 3306;
93 username = "prosody";
94 password = "password123";
95 };
96 '';
97 };
98 };
99 mysql = { config, pkgs, ... }: {
100 networking.firewall.enable = false;
101 services.mysql = {
102 enable = true;
103 initialScript = pkgs.writeText "mysql_init.sql" ''
104 CREATE DATABASE prosody;
105 CREATE USER 'prosody'@'server' IDENTIFIED BY 'password123';
106 GRANT ALL PRIVILEGES ON prosody.* TO 'prosody'@'server';
107 FLUSH PRIVILEGES;
108 '';
109 package = pkgs.mariadb;
110 };
111 };
112 };
113
114 testScript = { nodes, ... }: ''
115 # Check with mysql storage
116 mysql.wait_for_unit("mysql.service")
117 server.wait_for_unit("prosody.service")
118 server.succeed('prosodyctl status | grep "Prosody is running"')
119
120 server.succeed("create-prosody-users")
121 client.succeed("send-message")
122 server.succeed("delete-prosody-users")
123 '';
124}