1 import ./make-test-python.nix ({ pkgs, ... }:
4 meta = with pkgs.lib.maintainers; {
5 maintainers = [ lnl7 ];
8 nodes.machine = { pkgs, ... }: {
10 { isSystemUser = true;
13 users.groups.hello = { };
17 plugins = [ "python3" "php" ];
18 capabilities = [ "CAP_NET_BIND_SERVICE" ];
19 instance.type = "emperor";
21 instance.vassals.hello = {
23 immediate-uid = "hello";
24 immediate-gid = "hello";
25 module = "wsgi:application";
27 cap = "net_bind_service";
28 pythonPackages = self: [ self.flask ];
29 chdir = pkgs.writeTextDir "wsgi.py" ''
30 from flask import Flask
32 application = Flask(__name__)
34 @application.route("/")
36 return "Hello, World!"
38 @application.route("/whoami")
40 whoami = "${pkgs.coreutils}/bin/whoami"
41 proc = subprocess.run(whoami, capture_output=True)
42 return proc.stdout.decode().strip()
46 instance.vassals.php = {
50 http-socket = ":8000";
51 http-socket-modifier1 = 14;
52 php-index = "index.php";
53 php-docroot = pkgs.writeTextDir "index.php" ''
54 <?php echo "Hello World\n"; ?>
62 machine.wait_for_unit("multi-user.target")
63 machine.wait_for_unit("uwsgi.service")
65 with subtest("uWSGI has started"):
66 machine.wait_for_unit("uwsgi.service")
68 with subtest("Vassal can bind on port <1024"):
69 machine.wait_for_open_port(80)
70 hello = machine.succeed("curl -f http://machine").strip()
71 assert "Hello, World!" in hello, f"Excepted 'Hello, World!', got '{hello}'"
73 with subtest("Vassal is running as dedicated user"):
74 username = machine.succeed("curl -f http://machine/whoami").strip()
75 assert username == "hello", f"Excepted 'hello', got '{username}'"
77 with subtest("PHP plugin is working"):
78 machine.wait_for_open_port(8000)
79 assert "Hello World" in machine.succeed("curl -fv http://machine:8000")