@@ -312,6 +312,48 @@ describe("cookie module", function()
312
312
assert .same (nil , s :get (" example.com" , " /" , " qux" ))
313
313
end )
314
314
end )
315
+ describe (" cookie order" , function ()
316
+ it (" returns in order for simple cookies" , function () -- used as assumed base case for future tests in this section
317
+ local s = http_cookie .new_store ()
318
+ assert (s :store (" example.com" , " /" , true , true , nil , http_cookie .parse_setcookie (" foo=basic" )))
319
+ assert (s :store (" example.com" , " /" , true , true , nil , http_cookie .parse_setcookie (" bar=basic" )))
320
+ assert .same (" bar=basic; foo=basic" , s :lookup (" example.com" , " /" , true , true ))
321
+ end )
322
+ it (" returns in order for domain differing cookies" , function () -- spec doesn't care about this case
323
+ local s = http_cookie .new_store ()
324
+ assert (s :store (" sub.example.com" , " /" , true , true , nil , http_cookie .parse_setcookie (" foo=domain; Domain=sub.example.com" )))
325
+ assert (s :store (" sub.example.com" , " /" , true , true , nil , http_cookie .parse_setcookie (" bar=domain; Domain=example.com" )))
326
+ assert .same (" bar=domain; foo=domain" , s :lookup (" sub.example.com" , " /" , true , true ))
327
+ end )
328
+ it (" returns in order for different length paths" , function ()
329
+ local s = http_cookie .new_store ()
330
+ assert (s :store (" example.com" , " /" , true , true , nil , http_cookie .parse_setcookie (" foo=path; Path=/path/longerpath" )))
331
+ assert (s :store (" example.com" , " /" , true , true , nil , http_cookie .parse_setcookie (" bar=path; Path=/path/" )))
332
+ assert .same (" foo=path; bar=path" , s :lookup (" example.com" , " /path/longerpath" , true , true ))
333
+ end )
334
+ it (" returns in order for different creation times" , function ()
335
+ local s = http_cookie .new_store ()
336
+ s .time = function () return 0 end
337
+ assert (s :store (" example.com" , " /" , true , true , nil , http_cookie .parse_setcookie (" foo=time" )))
338
+ s .time = function () return 50 end
339
+ assert (s :store (" example.com" , " /" , true , true , nil , http_cookie .parse_setcookie (" bar=time" )))
340
+ assert .same (" foo=time; bar=time" , s :lookup (" example.com" , " /path/longerpath" , true , true ))
341
+ end )
342
+ it (" returns in order when all together!" , function ()
343
+ local s = http_cookie .new_store ()
344
+ assert (s :store (" sub.example.com" , " /" , true , true , nil , http_cookie .parse_setcookie (" foo=basic" )))
345
+ assert (s :store (" sub.example.com" , " /" , true , true , nil , http_cookie .parse_setcookie (" bar=basic" )))
346
+ assert (s :store (" sub.example.com" , " /" , true , true , nil , http_cookie .parse_setcookie (" foo=path; Path=/path/longerpath" )))
347
+ assert (s :store (" sub.example.com" , " /" , true , true , nil , http_cookie .parse_setcookie (" bar=path; Path=/path/" )))
348
+ -- foo=domain case would get overridden below
349
+ assert (s :store (" sub.example.com" , " /" , true , true , nil , http_cookie .parse_setcookie (" bar=domain; Domain=example.com" )))
350
+ s .time = function () return 0 end
351
+ assert (s :store (" sub.example.com" , " /" , true , true , nil , http_cookie .parse_setcookie (" foo=time" )))
352
+ s .time = function () return 50 end
353
+ assert (s :store (" sub.example.com" , " /" , true , true , nil , http_cookie .parse_setcookie (" bar=time" )))
354
+ assert .same (" foo=path; bar=path; bar=domain; bar=time; foo=time" , s :lookup (" sub.example.com" , " /path/longerpath" , true , true ))
355
+ end )
356
+ end )
315
357
it (" can bake cookies" , function ()
316
358
assert .same (" foo=bar" , http_cookie .bake (" foo" , " bar" ))
317
359
assert .same (" foo=bar; Max-Age=0" , http_cookie .bake (" foo" , " bar" , - math.huge ))
0 commit comments