rjz / supertest-session

Persistent sessions for supertest
Other
88 stars 21 forks source link

Add a way to configure the cookie jar CookieAccessInfo #26

Closed ctavan closed 7 years ago

ctavan commented 7 years ago

By default supertest-session will derive the CookieAccessInfo config of the cookie jar from the agent configuration. There might be cases where you want to override this, e.g. if you're testing an service which is configured to run behind a proxy but which sets secure cookies.


I'm a bit unsure whether this addition really fits the scope of this module.

An alternative workaround which works fine for me is to simply provide a small wrapper for supertest-session:

import request from 'supertest-session';

export default function supertest(app) {
  const client = request(app, {
    before: (req) => {
      client.cookieAccess.secure = true;
      req.set('X-Forwarded-Proto', 'https');
    },
  });
  return client;
}

Let me know how you feel about it. I'm equally happy to change the pull request and maybe just add the workaround to the README if you think this is valuable but don't wan to change anything about the functionality of supertest-session.

rjz commented 7 years ago

Thanks, @ctavan! Allowing this override seems like a very reasonable addition to me.

In terms of the interface, how would you feel about keeping cookieOptions inside the existing options list (instead of separating it out as an additional param)?

ctavan commented 7 years ago

@rjz good idea! I'll change that and update the PR.

ctavan commented 7 years ago

@rjz I've updated the PR. For the sake of completeness I have added the option to specify the 4th parameter script to CookieAccessInfo as well. It defaults to false.

The API-change is indeed much less intrusive now, so I'm now also convinced that this is a useful addition.

rjz commented 7 years ago

Awesome, thank you! It's published to npm as 3.1.0.

ctavan commented 7 years ago

Great, thanks for the quick merge!