Skip to content

Commit

Permalink
Fix tests for old node
Browse files Browse the repository at this point in the history
  • Loading branch information
blakeembrey committed Oct 2, 2024
1 parent 6bb701f commit d6f39b0
Showing 1 changed file with 21 additions and 25 deletions.
46 changes: 21 additions & 25 deletions test/serialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ describe('cookie.serialize(name, value)', function () {
'foo7bar',
];

validNames.forEach((name) => {
assert.equal(cookie.serialize(name, 'baz'), `${name}=baz`, `Expected serialized value for name: "${name}"`);
validNames.forEach(function (name) {
assert.equal(cookie.serialize(name, 'baz'), name + '=baz');
});
});

Expand All @@ -52,19 +52,18 @@ describe('cookie.serialize(name, value)', function () {
'foo[foo]',
'foo?foo',
'foo:foo',
'foo!foo',
'foo{foo}',
'foo foo',
'foo\tfoo',
'foo"foo',
'foo<script>foo'
];

invalidNames.forEach((name) => {
invalidNames.forEach(function (name) {
assert.throws(
cookie.serialize.bind(cookie, name, 'bar'),
/argument name is invalid/,
`Expected an error for invalid name: "${name}"`
'Expected an error for invalid name: ' + name
);
});
});
Expand All @@ -74,24 +73,23 @@ describe('cookie.serialize(name, value, options)', function () {
describe('with "domain" option', function () {

it('should serialize valid domain', function () {
const validDomains = [
var validDomains = [
'example.com',
'sub.example.com',
'my-site.org',
'localhost'
];

validDomains.forEach((domain) => {
validDomains.forEach(function (domain) {
assert.equal(
cookie.serialize('foo', 'bar', { domain }),
`foo=bar; Domain=${domain}`,
`Expected serialized value for domain: "${domain}"`
cookie.serialize('foo', 'bar', { domain: domain }),
'foo=bar; Domain=' + domain
);
});
});

it('should throw for invalid domain', function () {
const invalidDomains = [
var invalidDomains = [
'example.com\n',
'sub.example.com\u0000',
'my site.org',
Expand All @@ -101,11 +99,11 @@ describe('cookie.serialize(name, value, options)', function () {
'example.com /* inject a comment */'
];

invalidDomains.forEach((domain) => {
invalidDomains.forEach(function (domain) {
assert.throws(
cookie.serialize.bind(cookie, 'foo', 'bar', { domain }),
cookie.serialize.bind(cookie, 'foo', 'bar', { domain: domain }),
/option domain is invalid/,
`Expected an error for invalid domain: "${domain}"`
'Expected an error for invalid domain: ' + domain
);
});
});
Expand Down Expand Up @@ -207,7 +205,7 @@ describe('cookie.serialize(name, value, options)', function () {

describe('with "path" option', function () {
it('should serialize path', function () {
const validPaths = [
var validPaths = [
'/',
'/login',
'/foo.bar/baz',
Expand All @@ -219,31 +217,29 @@ describe('cookie.serialize(name, value, options)', function () {
'./'
];

validPaths.forEach((path) => {
validPaths.forEach(function (path) {
assert.equal(
cookie.serialize('foo', 'bar', { path }),
`foo=bar; Path=${path}`,
`Expected serialized value for path: "${path}"`
cookie.serialize('foo', 'bar', { path: path }),
'foo=bar; Path=' + path,
'Expected serialized value for path: ' + path
);
});
});

it('should throw for invalid value', function () {
const invalidPaths = [
var invalidPaths = [
'/\n',
'/foo\u0000',
'/foo bar',
'/path/with\rnewline',
'/path\\with\\backslash',
'/; Path=/sensitive-data',
'/login"><script>alert(1)</script>'
];

invalidPaths.forEach((path) => {
invalidPaths.forEach(function (path) {
assert.throws(
cookie.serialize.bind(cookie, 'foo', 'bar', { path }),
cookie.serialize.bind(cookie, 'foo', 'bar', { path: path }),
/option path is invalid/,
`Expected an error for invalid path: "${path}"`
'Expected an error for invalid path: ' + path
);
});
});
Expand Down

0 comments on commit d6f39b0

Please sign in to comment.