about summary refs log tree commit diff
path: root/nixpkgs/nixos/tests/nginx-sandbox.nix
diff options
context:
space:
mode:
authorAlyssa Ross <hi@alyssa.is>2020-05-18 14:34:25 +0000
committerAlyssa Ross <hi@alyssa.is>2020-05-18 16:21:12 +0000
commit93e90ca356baed5941e1cccf8c0d8e3e2c460e29 (patch)
treef6c26f06a2f830a3f1bab00fdc029b76be8805c6 /nixpkgs/nixos/tests/nginx-sandbox.nix
parentd2753504ef2bd591ade35851dad31d3aac117e19 (diff)
parentb47873026c7e356a340d0e1de7789d4e8428ac66 (diff)
downloadnixlib-93e90ca356baed5941e1cccf8c0d8e3e2c460e29.tar
nixlib-93e90ca356baed5941e1cccf8c0d8e3e2c460e29.tar.gz
nixlib-93e90ca356baed5941e1cccf8c0d8e3e2c460e29.tar.bz2
nixlib-93e90ca356baed5941e1cccf8c0d8e3e2c460e29.tar.lz
nixlib-93e90ca356baed5941e1cccf8c0d8e3e2c460e29.tar.xz
nixlib-93e90ca356baed5941e1cccf8c0d8e3e2c460e29.tar.zst
nixlib-93e90ca356baed5941e1cccf8c0d8e3e2c460e29.zip
Merge commit 'b47873026c7e356a340d0e1de7789d4e8428ac66'
Diffstat (limited to 'nixpkgs/nixos/tests/nginx-sandbox.nix')
-rw-r--r--nixpkgs/nixos/tests/nginx-sandbox.nix66
1 files changed, 66 insertions, 0 deletions
diff --git a/nixpkgs/nixos/tests/nginx-sandbox.nix b/nixpkgs/nixos/tests/nginx-sandbox.nix
new file mode 100644
index 000000000000..bc9d3ba8add7
--- /dev/null
+++ b/nixpkgs/nixos/tests/nginx-sandbox.nix
@@ -0,0 +1,66 @@
+import ./make-test-python.nix ({ pkgs, ... }: {
+  name = "nginx-sandbox";
+  meta = with pkgs.stdenv.lib.maintainers; {
+    maintainers = [ izorkin ];
+  };
+
+  # This test checks the creation and reading of a file in sandbox mode. Used simple lua script.
+
+  machine = { pkgs, ... }: {
+    nixpkgs.overlays = [
+      (self: super: {
+        nginx-lua = super.nginx.override {
+          modules = [
+            pkgs.nginxModules.lua
+          ];
+        };
+      })
+    ];
+    services.nginx.enable = true;
+    services.nginx.package = pkgs.nginx-lua;
+    services.nginx.enableSandbox = true;
+    services.nginx.virtualHosts.localhost = {
+      extraConfig = ''
+        location /test1-write {
+          content_by_lua_block {
+            local create = os.execute('${pkgs.coreutils}/bin/mkdir /tmp/test1-read')
+            local create = os.execute('${pkgs.coreutils}/bin/touch /tmp/test1-read/foo.txt')
+            local echo = os.execute('${pkgs.coreutils}/bin/echo worked > /tmp/test1-read/foo.txt')
+          }
+        }
+        location /test1-read {
+          root /tmp;
+        }
+        location /test2-write {
+          content_by_lua_block {
+            local create = os.execute('${pkgs.coreutils}/bin/mkdir /var/web/test2-read')
+            local create = os.execute('${pkgs.coreutils}/bin/touch /var/web/test2-read/bar.txt')
+            local echo = os.execute('${pkgs.coreutils}/bin/echo error-worked > /var/web/test2-read/bar.txt')
+          }
+        }
+        location /test2-read {
+          root /var/web;
+        }
+      '';
+    };
+    users.users.foo.isNormalUser = true;
+  };
+
+  testScript = ''
+    machine.wait_for_unit("nginx")
+    machine.wait_for_open_port(80)
+
+    # Checking write in temporary folder
+    machine.succeed("$(curl -vvv http://localhost/test1-write)")
+    machine.succeed('test "$(curl -fvvv http://localhost/test1-read/foo.txt)" = worked')
+
+    # Checking write in protected folder. In sandbox mode for the nginx service, the folder /var/web is mounted
+    # in read-only mode.
+    machine.succeed("mkdir -p /var/web")
+    machine.succeed("chown nginx:nginx /var/web")
+    machine.succeed("$(curl -vvv http://localhost/test2-write)")
+    assert "404 Not Found" in machine.succeed(
+        "curl -vvv -s http://localhost/test2-read/bar.txt"
+    )
+  '';
+})