git.iko.soy/typeable/nixpkgs
on master help sign in
nixos/tests/prosody: return prosody-mysql test
commit7629826b0307980765c50d4f661399d236cb6c26 authorIzorkin <izorkin@elven.pw> dateFri 18 Feb 2022, 22:19 (5 years ago) parentbc3994e
4 files changed+127−3
nixos/tests/all-tests.nix+1 nixos/tests/xmpp/prosody-mysql.nix+124 nixos/tests/xmpp/prosody.nix+1 pkgs/servers/xmpp/prosody/default.nix+1−3
nixos/tests/all-tests.nix+1
@@ -428,6 +428,7 @@ in
428428 prometheus = handleTest ./prometheus.nix {};
429429 prometheus-exporters = handleTest ./prometheus-exporters.nix {};
430430 prosody = handleTest ./xmpp/prosody.nix {};
431+ prosody-mysql = handleTest ./xmpp/prosody-mysql.nix {};
431432 proxy = handleTest ./proxy.nix {};
432433 prowlarr = handleTest ./prowlarr.nix {};
433434 pt2-clone = handleTest ./pt2-clone.nix {};
nixos/tests/xmpp/prosody-mysql.nixnew file+124
@@ -0,0 +1,124 @@
1+let
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+ '';
33+in 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+}
nixos/tests/xmpp/prosody.nix+1
@@ -81,6 +81,7 @@ in import ../make-test-python.nix {
8181 };
8282
8383 testScript = { nodes, ... }: ''
84+ # Check with sqlite storage
8485 server.wait_for_unit("prosody.service")
8586 server.succeed('prosodyctl status | grep "Prosody is running"')
8687
pkgs/servers/xmpp/prosody/default.nix+1−3
@@ -87,9 +87,7 @@ stdenv.mkDerivation rec {
8787
8888 passthru = {
8989 communityModules = withCommunityModules;
90− tests = {
91− main = nixosTests.prosody;
92− };
90+ tests = { inherit (nixosTests) prosody prosody-mysql; };
9391 };
9492
9593 meta = {