diff options
context:
space:
mode:
-rw-r--r--MANUAL.txt3
-rw-r--r--Makefile11
-rw-r--r--README.txt5
-rw-r--r--source/filter.c6
-rwxr-xr-xtests/t0006-nolua.sh58
5 files changed, 81 insertions, 2 deletions
diff --git a/MANUAL.txt b/MANUAL.txt
index 10487a3..053bb5f 100644
--- a/MANUAL.txt
+++ b/MANUAL.txt
@@ -755,7 +755,8 @@ specification with one of these strings.
Executes the script using a built-in Lua interpreter. The script is
loaded once per execution of cgit, and may be called multiple times
during cgit's lifetime, making it a good choice for repeated filters
- such as the 'email filter'. It responds to three functions:
+ such as the 'email filter'. A cgit built with NO_LUA has no interpreter
+ and refuses a filter with this prefix. It responds to three functions:
'filter_open(argument1, argument2, argument3, ...)'::
This is called upon activation of the filter for a particular
diff --git a/Makefile b/Makefile
index 29489b0..53580f3 100644
--- a/Makefile
+++ b/Makefile
@@ -76,10 +76,19 @@ cgit:
+@$(MAKE) -C $(GITDIR) -f $(CGIT_ROOT)/$(SRCDIR)/cgit.mk \
$(CGIT_ROOT)/$(BUILDDIR)/cgit $(EXTRA_GIT_TARGETS) $(GIT_BUILD_FLAGS)
+# The same program without Lua, built beside the full one so a change cannot
+# break that configuration unnoticed. The suite runs both.
+cgit-nolua:
+ +@$(MAKE) -C $(GITDIR) -f $(CGIT_ROOT)/$(SRCDIR)/cgit.mk \
+ $(CGIT_ROOT)/$(BUILDDIR)/nolua/cgit NO_LUA=1 BUILDDIR=$(BUILDDIR)/nolua $(GIT_BUILD_FLAGS)
+
sparse:
+@$(MAKE) -C $(GITDIR) -f $(CGIT_ROOT)/$(SRCDIR)/cgit.mk $(GIT_BUILD_FLAGS) cgit-sparse
+# The two builds share the Git tree, so they are made one after the other
+# even under -j.
test: cgit-with-git
+ +@$(MAKE) cgit-nolua
+@$(MAKE) -C tests all
# The test helpers link against a fully built Git tree, so this asks the sub
@@ -119,6 +128,6 @@ tags:
@mkdir -p $(BUILDDIR)
find $(SRCDIR) -name '*.[ch]' | xargs ctags -f $(BUILDDIR)/tags
-.PHONY: all cgit cgit-with-git sparse test
+.PHONY: all cgit cgit-with-git cgit-nolua sparse test
.PHONY: install uninstall
.PHONY: clean cleanall get-git tags
diff --git a/README.txt b/README.txt
index 844b6d0..5582164 100644
--- a/README.txt
+++ b/README.txt
@@ -46,6 +46,11 @@ runtime, turn it off.
$ make NO_LUA=1
+A binary built this way still runs every exec: filter, but a filter named with
+the lua: prefix has no interpreter to run in, so it is refused with an error on
+every page until the setting is taken out of cgitrc. make test builds this
+variant as well, into build/nolua, and checks it the same way.
+
Setup
-----
diff --git a/source/filter.c b/source/filter.c
index f5fb2d5..dd1eaf0 100644
--- a/source/filter.c
+++ b/source/filter.c
@@ -444,8 +444,10 @@ void cgit_abort_filters(void)
close(running_exec->old_stdout);
running_exec = NULL;
}
+#ifndef NO_LUA
if (filter_write)
unhook_write();
+#endif
}
static const struct {
@@ -503,5 +505,9 @@ struct cgit_filter *cgit_new_filter(const char *cmd, filter_type filtertype)
return filter_specs[i].create(colon + 1, argument_count);
}
+#ifdef NO_LUA
+ if (len == 3 && !strncmp("lua", cmd, len))
+ die("Built without Lua, cannot run filter %s", cmd);
+#endif
die("Invalid filter type: %.*s", (int)len, cmd);
}
diff --git a/tests/t0006-nolua.sh b/tests/t0006-nolua.sh
new file mode 100755
index 0000000..c315e41
--- /dev/null
+++ b/tests/t0006-nolua.sh
@@ -0,0 +1,58 @@
+#!/bin/sh
+
+# The build without Lua has to serve pages like the full one and run the exec
+# filters, and a filter written with the lua: prefix has to be refused with a
+# message naming the cause. make test builds it into build/nolua beside the
+# ordinary binary. The shared cgitrc may itself name lua filters, so every
+# request here carries a config of its own.
+
+test_description='Check the build without Lua'
+. ./setup.sh
+
+nolua="$TEST_OUTPUT_DIRECTORY/../build/nolua/cgit"
+test -x "$nolua" || {
+ skip_all='Skipping the Lua-less checks: build/nolua/cgit is missing, run make test'
+ test_done
+ exit
+}
+
+nolua_query() { CGIT_CONFIG="$PWD/$1" QUERY_STRING="$2" "$nolua"; }
+
+test_expect_success 'the binary reports no Lua' '
+ "$nolua" --version >tmp &&
+ grep -F "[-] Lua scripting" tmp
+'
+
+test_expect_success 'it serves a page' '
+ {
+ echo "virtual-root=/" &&
+ echo "cache-size=0" &&
+ echo "repo.url=foo" &&
+ echo "repo.path=$PWD/repos/foo/.git"
+ } >plainrc &&
+ nolua_query plainrc "url=foo/log/" >tmp &&
+ grep "^Status: 200" tmp &&
+ grep ">commit 5</a>" tmp
+'
+
+test_expect_success 'an exec filter still runs' '
+ {
+ cat plainrc &&
+ echo "repo.commit-filter=exec:$FILTER_DIRECTORY/dump.sh"
+ } >execrc &&
+ nolua_query execrc "url=foo/commit/" >tmp &&
+ grep "COMMIT 5" tmp
+'
+
+test_expect_success 'a lua filter is refused with one error page' '
+ {
+ cat plainrc &&
+ echo "repo.commit-filter=lua:$FILTER_DIRECTORY/dump.lua"
+ } >luarc &&
+ nolua_query luarc "url=foo/commit/" >tmp 2>err &&
+ grep "^Status: 500" tmp &&
+ test $(grep -c "^Status:" tmp) = 1 &&
+ grep "Built without Lua" err
+'
+
+test_done