Cookies apparently not preserved across agent requests
See original GitHub issueI have a typical login scenario which returns a session id. The second login test fails because another ‘set-cookie’ is in the header.
I can get this to work in supertest, which uses an older version of superagent, by calling res.jar.setCookie(res.headers['set-cookie'][0])
in the first request.
var login = require('./login2.js');
var chai = require('chai');
var should = chai.should();
var server = process.env.SERVER_UNDER_TEST;
process.env.NODE_TLS_REJECT_UNAUTHORIZED = 0;
var prefix = require('superagent-prefix')(server);
var request = require('superagent').agent();
describe("Cookie Test", () => {
it("login", done => {
login.login(request, prefix, (res) => {
should.exist(res.headers['set-cookie']);
done();
});
}));
it("login", done => {
login.login(request, prefix, (res) => {
should.not.exist(res.headers['set-cookie']);
done();
});
});
});
Issue Analytics
- State:
- Created 7 years ago
- Comments:11 (5 by maintainers)
Top Results From Across the Web
Cookies apparently not preserved across agent requests #1164
I have a typical login scenario which returns a session id. The second login test fails because another 'set-cookie' is in the header....
Read more >Why is this cookie not preserved across requests?
The cookie was created and sent but it is valid only for one request and it is not sent along all new requests....
Read more >RFC 6265 - HTTP State Management Mechanism
If a cookie has neither the Max-Age nor the Expires attribute, the user agent will retain the cookie until "the current session is...
Read more >Session/Cookie handling bug in soapUI 4.5.1 - Page 2 - SmartBear ...
In 4.5.1 however, the same session seems to be maintained across all test cases. Say I have two test cases, A and B....
Read more >HTTP State Management Mechanism
Most detail of request and response headers has been omitted. Assume the user agent has no stored cookies. 1. User Agent -> Server....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’m using superagent-prefix, which I assumed prefixed the server name to the get path. However, if I don’t use superagent-prefix and specify the full path (https://www.mavericklabel.com/reskin/xml/headers.php), then the test passes. Alright, good enough. Thanks.
I’ve checked. This is because superagent doesn’t know what the domain name is. You’re requesting
.get('/')
, so the domain isundefined
, but the cookie requires match on a specific domain.agent.get('https://www.mavericklabel.com/reskin/xml/headers.php')
works.I guess superagent-prefix is a leaky abstraction. You could report the problem there.