split-set-cookie-header.test.ts 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. import { describe, expect, it } from "vitest";
  2. import { splitSetCookieHeader } from "../../e2e/_helpers/auth";
  3. describe("splitSetCookieHeader", () => {
  4. it("returns empty array for empty input", () => {
  5. expect(splitSetCookieHeader("")).toEqual([]);
  6. expect(splitSetCookieHeader(" ")).toEqual([]);
  7. });
  8. it("splits cookies on comma separators", () => {
  9. expect(splitSetCookieHeader("a=1; Path=/, b=2; Path=/")).toEqual([
  10. "a=1; Path=/",
  11. "b=2; Path=/",
  12. ]);
  13. });
  14. it("does not split RFC 1123 Expires commas", () => {
  15. expect(
  16. splitSetCookieHeader("a=1; Expires=Wed, 21 Oct 2015 07:28:00 GMT; Path=/, b=2; Path=/")
  17. ).toEqual(["a=1; Expires=Wed, 21 Oct 2015 07:28:00 GMT; Path=/", "b=2; Path=/"]);
  18. });
  19. it("splits when Expires is the last attribute", () => {
  20. expect(splitSetCookieHeader("a=1; Expires=Wed, 21 Oct 2015 07:28:00 GMT, b=2; Path=/")).toEqual(
  21. ["a=1; Expires=Wed, 21 Oct 2015 07:28:00 GMT", "b=2; Path=/"]
  22. );
  23. });
  24. it("does not split commas inside quoted cookie values", () => {
  25. expect(splitSetCookieHeader('a="x, y=z"; Path=/, b=2; Path=/')).toEqual([
  26. 'a="x, y=z"; Path=/',
  27. "b=2; Path=/",
  28. ]);
  29. });
  30. });