From 826b0cf00027e905a151f458f74addf14cc9673f Mon Sep 17 00:00:00 2001 From: Andrew Waterman Date: Fri, 15 Oct 2021 10:23:38 -0700 Subject: [PATCH] @GH-215 -- Tests that document localhost behavior when set as domain. --- test/regression_test.js | 43 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/test/regression_test.js b/test/regression_test.js index 6bb4839b..450de5f0 100644 --- a/test/regression_test.js +++ b/test/regression_test.js @@ -188,4 +188,47 @@ vows } } }) + .addBatch({ + "setCookie with localhost (GH-215)": { + topic: function() { + const cookieJar = new CookieJar(); + return cookieJar.setCookieSync("a=b; Domain=localhost", "http://localhost") // when domain set to 'localhost', will throw 'Error: Cookie has domain set to a public suffix' + }, + works: function(err, c) { + // localhost as domain throws an error, cookie should not be defined + assert.instanceOf(err, Error) + assert.isUndefined(c) + } + }}, + { + "setCookie with localhost (GH-215) (null domain)": { + topic: function() { + const cookieJar = new CookieJar(); + return cookieJar.setCookieSync("a=b; Domain=", "http://localhost") // when domain set to 'localhost', will throw 'Error: Cookie has domain set to a public suffix' + }, + works: function(c) { + assert.instanceOf(c, Cookie) + } + }}, + { + "setCookie with localhost (localhost.local domain) (GH-215)": { + topic: function() { + const cookieJar = new CookieJar(); + return cookieJar.setCookieSync("a=b; Domain=localhost.local", "http://localhost") + }, + works: function(c) { + assert.instanceOf(c, Cookie) + } + }}, + { + "setCookie with localhost (.localhost domain), (GH-215)": { + topic: function() { + const cookieJar = new CookieJar(); + return cookieJar.setCookieSync("a=b; Domain=.localhost", "http://localhost") + }, + works: function(c) { + assert.instanceOf(c, Cookie) + } + } + }) .export(module);