Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
3 changes: 2 additions & 1 deletion 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 : rawKey.toLowerCase();
// only assign once
if (typeof cookie[key] !== 'undefined') return;

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 () {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about this version of code to make it clearer:

describe('Cookie Case Sensitivity', function () {

it('should respect capital letters in cookie names', async function () {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed to respects case of cookie name and moved up with the rest of the tests for .set.

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'] }))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dmurvihill could you share more details about this code, please?
As I can see cookies.set and cookies is not a standard global object in Supertest.

In standard Supertest, you cannot pass an object like { name: 'Alpha' } directly into .expect(). Instead, you have to parse the Set-Cookie header string.
Here you can find some details:
#665

@dmurvihill dmurvihill Feb 27, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cookies was added in supertest 7.2 (#855). See cookies.set.

.end(function(err, res) {
if (err) {
throw err;
}
});
});
});
});
Loading