Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/cookies/assertion.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,8 @@ module.exports = function (secret, asserts) {
return;
}

const key = part.substr(0, equalsIndex).trim().toLowerCase();
const rawKey = part.substr(0, equalsIndex).trim();
const key = i > 0 ? rawKey.toLowerCase() : rawKey;
// only assign once
if (typeof cookie[key] !== 'undefined') return;

Expand Down Expand Up @@ -286,7 +287,6 @@ module.exports = function (secret, asserts) {
assertions.push(function (req, res) {
// get expectation cookie
const cookie = Assertion.find(expect.name, res.cookies);

if (assert && !cookie) throw new Error('expected: ' + expect.name + ' cookie to be set');

if (assert) assertHasProperties(cookie.options, expect.options);
Expand Down
22 changes: 22 additions & 0 deletions test/cookies.js
Original file line number Diff line number Diff line change
Expand Up @@ -1281,4 +1281,26 @@ describe('cookie', function () {
});
});
});

describe('Cookie name case is respected', function () {
it('asserts true if cookie name contains capital letters', function () {
const app = express();
app.get('/users', function(req, res) {
res.cookie('Alpha', 'one', { domain: 'domain.com', path: '/', httpOnly: true });
res.send(200, { name: 'tobi' });
});
request(app)
.get('/users')
.expect('Content-Type', /json/)
.expect('Content-Length', '15')
.expect(200)
// assert 'Alpha' cookie is set with domain, path, and httpOnly options
.expect(cookies.set({ name: 'Alpha', options: ['domain', 'path', 'httponly'] }))
.end(function(err, res) {
if (err) {
throw err;
}
});
});
});
});