1import ./make-test-python.nix (
2 { pkgs, ... }:
3 {
4 name = "uwsgi";
5 meta = with pkgs.lib.maintainers; {
6 maintainers = [ lnl7 ];
7 };
8
9 nodes.machine =
10 { pkgs, ... }:
11 {
12 users.users.hello = {
13 isSystemUser = true;
14 group = "hello";
15 };
16 users.groups.hello = { };
17
18 services.uwsgi = {
19 enable = true;
20 plugins = [
21 "python3"
22 "php"
23 ];
24 capabilities = [ "CAP_NET_BIND_SERVICE" ];
25 instance.type = "emperor";
26
27 instance.vassals.hello = {
28 type = "normal";
29 immediate-uid = "hello";
30 immediate-gid = "hello";
31 module = "wsgi:application";
32 http = ":80";
33 cap = "net_bind_service";
34 pythonPackages = self: [ self.flask ];
35 chdir = pkgs.writeTextDir "wsgi.py" ''
36 from flask import Flask
37 import subprocess
38 application = Flask(__name__)
39
40 @application.route("/")
41 def hello():
42 return "Hello, World!"
43
44 @application.route("/whoami")
45 def whoami():
46 whoami = "${pkgs.coreutils}/bin/whoami"
47 proc = subprocess.run(whoami, capture_output=True)
48 return proc.stdout.decode().strip()
49 '';
50 };
51
52 instance.vassals.php = {
53 type = "normal";
54 master = true;
55 workers = 2;
56 http-socket = ":8000";
57 http-socket-modifier1 = 14;
58 php-index = "index.php";
59 php-docroot = pkgs.writeTextDir "index.php" ''
60 <?php echo "Hello World\n"; ?>
61 '';
62 };
63 };
64 };
65
66 testScript = ''
67 machine.wait_for_unit("multi-user.target")
68 machine.wait_for_unit("uwsgi.service")
69
70 with subtest("uWSGI has started"):
71 machine.wait_for_unit("uwsgi.service")
72
73 with subtest("Vassal can bind on port <1024"):
74 machine.wait_for_open_port(80)
75 hello = machine.succeed("curl -f http://machine").strip()
76 assert "Hello, World!" in hello, f"Excepted 'Hello, World!', got '{hello}'"
77
78 with subtest("Vassal is running as dedicated user"):
79 username = machine.succeed("curl -f http://machine/whoami").strip()
80 assert username == "hello", f"Excepted 'hello', got '{username}'"
81
82 with subtest("PHP plugin is working"):
83 machine.wait_for_open_port(8000)
84 assert "Hello World" in machine.succeed("curl -fv http://machine:8000")
85 '';
86 }
87)