Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: MemoryCookieStore methods should exist on the prototype, not on the class. #226

Merged
merged 2 commits into from Dec 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/memstore.js
Expand Up @@ -184,7 +184,9 @@ class MemoryCookieStore extends Store {
"removeAllCookies",
"getAllCookies"
].forEach(name => {
MemoryCookieStore[name] = fromCallback(MemoryCookieStore.prototype[name]);
MemoryCookieStore.prototype[name] = fromCallback(
MemoryCookieStore.prototype[name]
);
});

exports.MemoryCookieStore = MemoryCookieStore;
98 changes: 67 additions & 31 deletions test/regression_test.js
Expand Up @@ -36,6 +36,7 @@ const async = require("async");
const tough = require("../lib/cookie");
const Cookie = tough.Cookie;
const CookieJar = tough.CookieJar;
const MemoryCookieStore = tough.MemoryCookieStore;

const atNow = Date.now();

Expand Down Expand Up @@ -188,46 +189,81 @@ 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)
.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 (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)
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")
const cookieJar = new CookieJar();
return cookieJar.setCookieSync(
"a=b; Domain=.localhost",
"http://localhost"
);
},
works: function(c) {
assert.instanceOf(c, Cookie);
}
}
}
)
.addBatch({
MemoryCookieStore: {
topic: new MemoryCookieStore(),
"has no static methods": function() {
assert.deepEqual(Object.keys(MemoryCookieStore), []);
},
works: function(c) {
assert.instanceOf(c, Cookie)
"has instance methods that return promises": function(store) {
assert.instanceOf(store.findCookie("example.com", "/", "key"), Promise);
assert.instanceOf(store.findCookies("example.com", "/"), Promise);
assert.instanceOf(store.putCookie({}), Promise);
assert.instanceOf(store.updateCookie({}, {}), Promise);
assert.instanceOf(
store.removeCookie("example.com", "/", "key"),
Promise
);
assert.instanceOf(store.removeCookies("example.com", "/"), Promise);
assert.instanceOf(store.removeAllCookies(), Promise);
assert.instanceOf(store.getAllCookies(), Promise);
}
}
})
Expand Down