question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cookies apparently not preserved across agent requests

See original GitHub issue

I 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:closed
  • Created 7 years ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
JeffMLcommented, Jan 28, 2017

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.

0reactions
kornelskicommented, Jan 27, 2017

I’ve checked. This is because superagent doesn’t know what the domain name is. You’re requesting .get('/'), so the domain is undefined, 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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found