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