Skip to content

Commit

Permalink
Add failing test for ladjs#1807
Browse files Browse the repository at this point in the history
  • Loading branch information
robaca committed Jun 20, 2024
1 parent 3317168 commit 22f6632
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
20 changes: 20 additions & 0 deletions test/agent-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,24 @@ describe('Agent', () => {
assert.deepEqual({ hello: 'world' }, res.body);
});
});

it('should assign cookies without domains correctly when following redirects', () => {
const agent = request.agent();

const firstUrl = new URL(base)
firstUrl.hostname = 'first.local'
const first = firstUrl.toString().slice(0, -1)

const secondUrl = new URL(base)
secondUrl.hostname = "second.local"
const second = secondUrl.toString().slice(0, -1)

return agent
.get(`${first}/cookie-cross-domain-redirect`)
.query({ first, second })
.connect('127.0.0.1')
.then((res) => {
assert.equal(res.text, 'currentdomain=first.local')
})
})
});
24 changes: 24 additions & 0 deletions test/support/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,30 @@ app.put('/redirect-308', (request, res) => {
res.redirect(308, '/reply-method');
});

app.get('/cookie-cross-domain-redirect', (request, res) => {
const { first, second } = request.query
res.cookie('currentdomain', request.hostname, {
path: '/',
sameSite: 'lax',
secure: false,
maxAge: 1000
});

res.redirect(303, `${second}/cookie-cross-domain-second-redirect?first=${encodeURIComponent(first)}`);
});

app.get('/cookie-cross-domain-second-redirect', (request, res) => {
const first = request.query.first

res.cookie('currentdomain', request.hostname, {
path: '/',
sameSite: 'lax',
secure: false,
maxAge: 1000
});
res.redirect(303, `${first}/show-cookies`);
});

app.all('/reply-method', (request, res) => {
res.send(`method=${request.method.toLowerCase()}`);
});
Expand Down

0 comments on commit 22f6632

Please sign in to comment.