1 import ./make-test-python.nix ({ pkgs, ... }: {
2 name = "nginx-sandbox";
3 meta = with pkgs.lib.maintainers; {
4 maintainers = [ izorkin ];
7 # This test checks the creation and reading of a file in sandbox mode. Used simple lua script.
9 nodes.machine = { pkgs, ... }: {
12 nginx-lua = super.nginx.override {
19 services.nginx.enable = true;
20 services.nginx.package = pkgs.nginx-lua;
21 services.nginx.virtualHosts.localhost = {
23 location /test1-write {
24 content_by_lua_block {
25 local create = os.execute('${pkgs.coreutils}/bin/mkdir /tmp/test1-read')
26 local create = os.execute('${pkgs.coreutils}/bin/touch /tmp/test1-read/foo.txt')
27 local echo = os.execute('${pkgs.coreutils}/bin/echo worked > /tmp/test1-read/foo.txt')
30 location /test1-read {
33 location /test2-write {
34 content_by_lua_block {
35 local create = os.execute('${pkgs.coreutils}/bin/mkdir /var/web/test2-read')
36 local create = os.execute('${pkgs.coreutils}/bin/touch /var/web/test2-read/bar.txt')
37 local echo = os.execute('${pkgs.coreutils}/bin/echo error-worked > /var/web/test2-read/bar.txt')
40 location /test2-read {
45 users.users.foo.isNormalUser = true;
49 machine.wait_for_unit("nginx")
50 machine.wait_for_open_port(80)
52 # Checking write in temporary folder
53 machine.succeed("$(curl -vvv http://localhost/test1-write)")
54 machine.succeed('test "$(curl -fvvv http://localhost/test1-read/foo.txt)" = worked')
56 # Checking write in protected folder. In sandbox mode for the nginx service, the folder /var/web is mounted
58 machine.succeed("mkdir -p /var/web")
59 machine.succeed("chown nginx:nginx /var/web")
60 machine.succeed("$(curl -vvv http://localhost/test2-write)")
61 assert "404 Not Found" in machine.succeed(
62 "curl -vvv -s http://localhost/test2-read/bar.txt"