From f7cedc92badc42fb92a1849d1f3515a30c960eab Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Sat, 7 Nov 2026 14:24:07 -1000 Subject: 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. --- tests/extensions/test-auth.lua | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'tests/extensions/test-auth.lua') 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")) -- cgit 2.12.1