Diff options
| author | Bryce Kwon <bryce@brycekwon.com> | |
|---|---|---|
| committer | Bryce Kwon <bryce@brycekwon.com> | |
| commit | ||
| parent | ||
| tree | ||
| download | ||
Make the cookie timing check hold on fast cores
The quadratic trim takes 0.58 seconds for the 20,000 spaces the check
used under LuaJIT on an M-series Mac, against a threshold of half a
second over two calls, so a regression could pass on a slightly faster
core. At 100,000 spaces it takes about fifteen seconds and the linear
one under a millisecond, and each call is now timed on its own.
Diffstat (limited to 'tests/extensions')
| -rw-r--r-- | tests/extensions/test-auth.lua | 14 |
1 file changed, 9 insertions, 5 deletions
diff --git a/tests/extensions/test-auth.lua b/tests/extensions/test-auth.lua index 17cb805..bd1f01c 100644 --- a/tests/extensions/test-auth.lua +++ b/tests/extensions/test-auth.lua @@ -247,12 +247,16 @@ h.equals("spaces around a pair are ignored", get_cookie(" foo=1 ; cgitauth=abc h.equals("a cookie value keeps its own equals signs", get_cookie("cgitauth=a=b", "cgitauth"), "a=b") -- The Cookie header is the visitor's to write, so a run of spaces in it --- must not cost the square of its length. +-- must not cost the square of its length. At this length a linear trim +-- takes about a millisecond and the square about fifteen seconds. +local spaces = string.rep(" ", 100000) local started = os.clock() -get_cookie("a=" .. string.rep(" ", 20000) .. "b", "cgitauth") -h.equals("a long run of spaces is read quickly", - get_cookie(string.rep(" ", 20000) .. "cgitauth=abc", "cgitauth"), "abc") -h.check("and in linear time", os.clock() - started < 0.5) +get_cookie("a=" .. spaces .. "b", "cgitauth") +h.check("a long run of spaces inside a cookie is read within half a second", os.clock() - started < 0.5) +started = os.clock() +local found = get_cookie(spaces .. "cgitauth=abc", "cgitauth") +h.check("and one ahead of it as well", os.clock() - started < 0.5) +h.equals("without losing the cookie behind it", found, "abc") h.check("equal strings compare equal", constant_equals("abc", "abc")) h.check("differing strings do not", not constant_equals("abc", "abd")) |
