Diff options
| author | Bryce Kwon <bryce@brycekwon.com> | |
|---|---|---|
| committer | Bryce Kwon <bryce@brycekwon.com> | |
| commit | ||
| parent | ||
| tree | ||
| download | ||
Say when logins are unavailable
The way back was signed part way through the form, so while the secret's
directory did not exist, or a library was missing, cgit's error landed
inside the hidden input and the page broke off there with no fields.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/extensions/harness.lua | 21 | |
| -rw-r--r-- | tests/extensions/test-auth.lua | 17 | |
| -rwxr-xr-x | tests/t0505-auth.sh | 5 |
3 files changed, 40 insertions, 3 deletions
diff --git a/tests/extensions/harness.lua b/tests/extensions/harness.lua index 2fe722f..8c1ba6c 100644 --- a/tests/extensions/harness.lua +++ b/tests/extensions/harness.lua @@ -54,14 +54,30 @@ html_url_path = sink(function(s) end)) end) +-- What a script writes to standard error goes to the web server's error log +-- under cgit, so it is kept here for a check to read instead. +local logged = {} + +io.stderr = { + write = function(self, ...) + logged[#logged + 1] = table.concat({ ... }) + return self + end, +} + function harness.reset() pieces = {} + logged = {} end function harness.output() return table.concat(pieces) end +function harness.error_log() + return table.concat(logged) +end + function harness.load(script) dofile(script) end @@ -182,6 +198,11 @@ function harness.stub_auth_modules() preload("posix.unistd", { crypt = fake_crypt, }) + preload("posix.sys.stat", { + umask = function() + return 18 + end, + }) preload("openssl.rand", { bytes = function(count) local out = {} diff --git a/tests/extensions/test-auth.lua b/tests/extensions/test-auth.lua index 974544d..3a4fabf 100644 --- a/tests/extensions/test-auth.lua +++ b/tests/extensions/test-auth.lua @@ -302,6 +302,18 @@ h.contains("a failed login says so", out, "<p class='login-error' role='alert'>Wrong username or password.</p>") h.equals("and leaves the flag out of the way back", way_back_in(out), "/repo/log/?q=x") +-- The real get_secret, pointed at a directory nobody made, cannot sign the +-- way back, so the page says so whole rather than breaking off in the form. +h.load_with(script, { { "local secret_filename = \"/var/lib/cgit/auth-secret\"", + "local secret_filename = \"no-such-directory/auth-secret\"" } }) +out = run_action("body", {}) +h.contains("a secret that cannot be made leaves a page saying so", out, + "<p class='login-error' role='alert'>Logins are unavailable. The server's error log says why.</p>") +h.excludes("with no form to fill in", out, "<form") +h.contains("and the error log names the directory", h.error_log(), + "as no-such-directory is missing or not writable by cgit\n") +load_script() + local way_back = secure_value("redirect", "/repo/", 0) out = login("Alice", password, way_back) @@ -373,6 +385,9 @@ for _, name in ipairs({ "openssl.rand", "openssl.hmac", "posix.sys.stat", "posix end h.equals("without the libraries a public repository is served", visit("unlisted"), 1) h.check("while a protected one fails closed", not pcall(visit, "secret-repo", session)) -h.check("and so does its login form", not pcall(run_action, "body", {})) +out = run_action("body", {}) +h.contains("and its login page says logins are unavailable", out, "Logins are unavailable.") +h.excludes("and no form to fill in", out, "<form") +h.contains("while the error log names the missing library", h.error_log(), "openssl.rand") h.finish() diff --git a/tests/t0505-auth.sh b/tests/t0505-auth.sh index e9349d4..3b49c7e 100755 --- a/tests/t0505-auth.sh +++ b/tests/t0505-auth.sh @@ -69,9 +69,10 @@ test_expect_success CGIT_LUA_NOAUTH 'without the modules a protected repository repo.url=authy repo.path=$PWD/repos/authy/.git EOF - cgit_rc guardedrc "url=authy/log/" >tmp && + cgit_rc guardedrc "url=authy/log/" >tmp 2>err && ! grep "guarded commit" tmp && - grep "Unable to complete the request" tmp + grep "<p class=.login-error. role=.alert.>Logins are unavailable" tmp && + grep "^\[cgit\] " err ' # A filter of the test's own turns every visitor away, which needs no Lua. |
