2020-04-20 19:27:53 +01:00
|
|
|
let
|
|
|
|
cert = pkgs: pkgs.runCommandNoCC "selfSignedCerts" { buildInputs = [ pkgs.openssl ]; } ''
|
2021-08-06 21:24:41 +01:00
|
|
|
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
|
2020-04-20 19:27:53 +01:00
|
|
|
mkdir -p $out
|
|
|
|
cp key.pem cert.pem $out
|
|
|
|
'';
|
|
|
|
createUsers = pkgs: pkgs.writeScriptBin "create-prosody-users" ''
|
|
|
|
#!${pkgs.bash}/bin/bash
|
|
|
|
set -e
|
|
|
|
|
|
|
|
# Creates and set password for the 2 xmpp test users.
|
|
|
|
#
|
|
|
|
# Doing that in a bash script instead of doing that in the test
|
|
|
|
# script allow us to easily provision the users when running that
|
|
|
|
# test interactively.
|
|
|
|
|
|
|
|
prosodyctl register cthon98 example.com nothunter2
|
|
|
|
prosodyctl register azurediamond example.com hunter2
|
|
|
|
'';
|
|
|
|
delUsers = pkgs: pkgs.writeScriptBin "delete-prosody-users" ''
|
|
|
|
#!${pkgs.bash}/bin/bash
|
|
|
|
set -e
|
|
|
|
|
|
|
|
# Deletes the test users.
|
|
|
|
#
|
|
|
|
# Doing that in a bash script instead of doing that in the test
|
|
|
|
# script allow us to easily provision the users when running that
|
|
|
|
# test interactively.
|
2018-03-21 13:27:20 +00:00
|
|
|
|
2020-04-20 19:27:53 +01:00
|
|
|
prosodyctl deluser cthon98@example.com
|
|
|
|
prosodyctl deluser azurediamond@example.com
|
|
|
|
'';
|
|
|
|
in import ../make-test-python.nix {
|
|
|
|
name = "prosody";
|
2019-06-15 10:41:50 +01:00
|
|
|
nodes = {
|
2020-04-20 19:27:53 +01:00
|
|
|
client = { nodes, pkgs, config, ... }: {
|
|
|
|
security.pki.certificateFiles = [ "${cert pkgs}/cert.pem" ];
|
|
|
|
console.keyMap = "fr-bepo";
|
|
|
|
networking.extraHosts = ''
|
|
|
|
${nodes.server.config.networking.primaryIPAddress} example.com
|
|
|
|
${nodes.server.config.networking.primaryIPAddress} conference.example.com
|
|
|
|
${nodes.server.config.networking.primaryIPAddress} uploads.example.com
|
|
|
|
'';
|
2019-06-15 10:41:50 +01:00
|
|
|
environment.systemPackages = [
|
|
|
|
(pkgs.callPackage ./xmpp-sendmessage.nix { connectTo = nodes.server.config.networking.primaryIPAddress; })
|
|
|
|
];
|
|
|
|
};
|
|
|
|
server = { config, pkgs, ... }: {
|
2020-04-20 19:27:53 +01:00
|
|
|
security.pki.certificateFiles = [ "${cert pkgs}/cert.pem" ];
|
|
|
|
console.keyMap = "fr-bepo";
|
2019-06-15 10:41:50 +01:00
|
|
|
networking.extraHosts = ''
|
|
|
|
${config.networking.primaryIPAddress} example.com
|
2020-04-20 19:27:53 +01:00
|
|
|
${config.networking.primaryIPAddress} conference.example.com
|
|
|
|
${config.networking.primaryIPAddress} uploads.example.com
|
2018-09-23 09:46:22 +01:00
|
|
|
'';
|
2019-06-15 10:41:50 +01:00
|
|
|
networking.firewall.enable = false;
|
2020-04-20 19:27:53 +01:00
|
|
|
environment.systemPackages = [
|
|
|
|
(createUsers pkgs)
|
|
|
|
(delUsers pkgs)
|
|
|
|
];
|
2019-06-15 10:41:50 +01:00
|
|
|
services.prosody = {
|
|
|
|
enable = true;
|
2020-04-20 19:27:53 +01:00
|
|
|
ssl.cert = "${cert pkgs}/cert.pem";
|
|
|
|
ssl.key = "${cert pkgs}/key.pem";
|
|
|
|
virtualHosts.example = {
|
2019-06-15 10:41:50 +01:00
|
|
|
domain = "example.com";
|
|
|
|
enabled = true;
|
2020-04-20 19:27:53 +01:00
|
|
|
ssl.cert = "${cert pkgs}/cert.pem";
|
|
|
|
ssl.key = "${cert pkgs}/key.pem";
|
|
|
|
};
|
|
|
|
muc = [
|
|
|
|
{
|
|
|
|
domain = "conference.example.com";
|
|
|
|
}
|
|
|
|
];
|
|
|
|
uploadHttp = {
|
|
|
|
domain = "uploads.example.com";
|
2019-06-15 10:41:50 +01:00
|
|
|
};
|
2019-04-17 22:36:07 +01:00
|
|
|
};
|
2018-03-21 13:27:20 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2019-06-15 10:41:50 +01:00
|
|
|
testScript = { nodes, ... }: ''
|
2019-11-24 12:04:11 +00:00
|
|
|
server.wait_for_unit("prosody.service")
|
|
|
|
server.succeed('prosodyctl status | grep "Prosody is running"')
|
2018-03-21 13:27:20 +00:00
|
|
|
|
2020-04-20 19:27:53 +01:00
|
|
|
server.succeed("create-prosody-users")
|
2021-02-11 17:46:07 +00:00
|
|
|
client.succeed("send-message")
|
2020-04-20 19:27:53 +01:00
|
|
|
server.succeed("delete-prosody-users")
|
2018-03-21 13:27:20 +00:00
|
|
|
'';
|
|
|
|
}
|