summary refs log tree commit diff
path: root/nixos/tests/xmpp/prosody-mysql.nix
blob: 0507227021b227c6e890dbfcdc26096037eecbfd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import ../make-test-python.nix {
  name = "prosody-mysql";

  nodes = {
    client = { nodes, pkgs, ... }: {
      environment.systemPackages = [
        (pkgs.callPackage ./xmpp-sendmessage.nix { connectTo = nodes.server.config.networking.primaryIPAddress; })
      ];
    };
    server = { config, pkgs, ... }: {
      nixpkgs.overlays = [
        (self: super: {
          prosody = super.prosody.override {
            withDBI = true;
            withExtraLibs = [ pkgs.luaPackages.luadbi-mysql ];
          };
        })
      ];
      networking.extraHosts = ''
        ${config.networking.primaryIPAddress} example.com
      '';
      networking.firewall.enable = false;
      services.prosody = {
        enable = true;
        # TODO: use a self-signed certificate
        c2sRequireEncryption = false;
        extraConfig = ''
          storage = "sql"
          sql = {
            driver = "MySQL";
            database = "prosody";
            host = "mysql";
            port = 3306;
            username = "prosody";
            password = "password123";
          };
        '';
        virtualHosts.test = {
          domain = "example.com";
          enabled = true;
        };
      };
    };
    mysql = { config, pkgs, ... }: {
      networking.firewall.enable = false;
      services.mysql = {
        enable = true;
        initialScript = pkgs.writeText "mysql_init.sql" ''
          CREATE DATABASE prosody;
          CREATE USER 'prosody'@'server' IDENTIFIED BY 'password123';
          GRANT ALL PRIVILEGES ON prosody.* TO 'prosody'@'server';
          FLUSH PRIVILEGES;
        '';
        package = pkgs.mariadb;
      };
    };
  };

  testScript = { nodes, ... }: ''
    mysql.wait_for_unit("mysql.service")
    server.wait_for_unit("prosody.service")
    server.succeed('prosodyctl status | grep "Prosody is running"')

    # set password to 'nothunter2' (it's asked twice)
    server.succeed("yes nothunter2 | prosodyctl adduser cthon98@example.com")
    # set password to 'y'
    server.succeed("yes | prosodyctl adduser azurediamond@example.com")
    # correct password to 'hunter2'
    server.succeed("yes hunter2 | prosodyctl passwd azurediamond@example.com")

    client.succeed("send-message")

    server.succeed("prosodyctl deluser cthon98@example.com")
    server.succeed("prosodyctl deluser azurediamond@example.com")
  '';
}