1 import ./make-test-python.nix ({ pkgs, lib, ... }:
7 getLuaPath = lib: "${lib}/share/lua/${pkgs.lua.luaversion}/?.lua";
8 luaPath = lib.concatStringsSep ";" (map getLuaPath luaLibs);
11 name = "openresty-lua";
12 meta = with pkgs.lib.maintainers; {
13 maintainers = [ bbigras ];
17 webserver = { pkgs, lib, ... }: {
20 127.0.0.1 default.test
21 127.0.0.1 sandbox.test
26 package = pkgs.openresty;
29 lua_package_path '${luaPath};;';
32 virtualHosts."default.test" = {
36 default_type text/html;
38 local markdown = require "markdown"
45 virtualHosts."sandbox.test" = {
46 locations."/test1-write" = {
48 content_by_lua_block {
49 local create = os.execute('${pkgs.coreutils}/bin/mkdir /tmp/test1-read')
50 local create = os.execute('${pkgs.coreutils}/bin/touch /tmp/test1-read/foo.txt')
51 local echo = os.execute('${pkgs.coreutils}/bin/echo worked > /tmp/test1-read/foo.txt')
55 locations."/test1-read" = {
58 locations."/test2-write" = {
60 content_by_lua_block {
61 local create = os.execute('${pkgs.coreutils}/bin/mkdir /var/web/test2-read')
62 local create = os.execute('${pkgs.coreutils}/bin/touch /var/web/test2-read/bar.txt')
63 local echo = os.execute('${pkgs.coreutils}/bin/echo error-worked > /var/web/test2-read/bar.txt')
67 locations."/test2-read" = {
75 testScript = { nodes, ... }:
77 url = "http://localhost"
79 webserver.wait_for_unit("nginx")
80 webserver.wait_for_open_port(80)
82 http_code = webserver.succeed(
83 f"curl -w '%{{http_code}}' --head --fail {url}"
85 assert http_code.split("\n")[-1] == "200"
87 # This test checks the creation and reading of a file in sandbox mode.
88 # Checking write in temporary folder
89 webserver.succeed("$(curl -vvv http://sandbox.test/test1-write)")
90 webserver.succeed('test "$(curl -fvvv http://sandbox.test/test1-read/foo.txt)" = worked')
91 # Checking write in protected folder. In sandbox mode for the nginx service, the folder /var/web is mounted
93 webserver.succeed("mkdir -p /var/web")
94 webserver.succeed("chown nginx:nginx /var/web")
95 webserver.succeed("$(curl -vvv http://sandbox.test/test2-write)")
96 assert "404 Not Found" in machine.succeed(
97 "curl -vvv -s http://sandbox.test/test2-read/bar.txt"