2020-05-03 17:38:23 +00:00
|
|
|
let
|
|
|
|
cert = pkgs: pkgs.runCommandNoCC "selfSignedCerts" { buildInputs = [ pkgs.openssl ]; } ''
|
2021-08-08 23:34:03 +00: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-05-03 17:38:23 +00: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.
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2020-05-03 17:38:23 +00:00
|
|
|
prosodyctl deluser cthon98@example.com
|
|
|
|
prosodyctl deluser azurediamond@example.com
|
|
|
|
'';
|
|
|
|
in import ../make-test-python.nix {
|
|
|
|
name = "prosody";
|
2020-04-24 23:36:52 +00:00
|
|
|
nodes = {
|
2020-05-03 17:38:23 +00: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
|
|
|
|
'';
|
2020-04-24 23:36:52 +00:00
|
|
|
environment.systemPackages = [
|
|
|
|
(pkgs.callPackage ./xmpp-sendmessage.nix { connectTo = nodes.server.config.networking.primaryIPAddress; })
|
|
|
|
];
|
|
|
|
};
|
|
|
|
server = { config, pkgs, ... }: {
|
2020-05-03 17:38:23 +00:00
|
|
|
security.pki.certificateFiles = [ "${cert pkgs}/cert.pem" ];
|
|
|
|
console.keyMap = "fr-bepo";
|
2020-04-24 23:36:52 +00:00
|
|
|
networking.extraHosts = ''
|
|
|
|
${config.networking.primaryIPAddress} example.com
|
2020-05-03 17:38:23 +00:00
|
|
|
${config.networking.primaryIPAddress} conference.example.com
|
|
|
|
${config.networking.primaryIPAddress} uploads.example.com
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
networking.firewall.enable = false;
|
2020-05-03 17:38:23 +00:00
|
|
|
environment.systemPackages = [
|
|
|
|
(createUsers pkgs)
|
|
|
|
(delUsers pkgs)
|
|
|
|
];
|
2020-04-24 23:36:52 +00:00
|
|
|
services.prosody = {
|
|
|
|
enable = true;
|
2020-05-03 17:38:23 +00:00
|
|
|
ssl.cert = "${cert pkgs}/cert.pem";
|
|
|
|
ssl.key = "${cert pkgs}/key.pem";
|
|
|
|
virtualHosts.example = {
|
2020-04-24 23:36:52 +00:00
|
|
|
domain = "example.com";
|
|
|
|
enabled = true;
|
2020-05-03 17:38:23 +00:00
|
|
|
ssl.cert = "${cert pkgs}/cert.pem";
|
|
|
|
ssl.key = "${cert pkgs}/key.pem";
|
|
|
|
};
|
|
|
|
muc = [
|
|
|
|
{
|
|
|
|
domain = "conference.example.com";
|
|
|
|
}
|
|
|
|
];
|
|
|
|
uploadHttp = {
|
|
|
|
domain = "uploads.example.com";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
testScript = { nodes, ... }: ''
|
|
|
|
server.wait_for_unit("prosody.service")
|
|
|
|
server.succeed('prosodyctl status | grep "Prosody is running"')
|
|
|
|
|
2020-05-03 17:38:23 +00:00
|
|
|
server.succeed("create-prosody-users")
|
2021-02-13 14:23:35 +00:00
|
|
|
client.succeed("send-message")
|
2020-05-03 17:38:23 +00:00
|
|
|
server.succeed("delete-prosody-users")
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
}
|