Skip to content

Commit

Permalink
test: add test
Browse files Browse the repository at this point in the history
  • Loading branch information
BlackHole1 committed Feb 9, 2023
1 parent 19aed1f commit c954841
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions spec/api-net-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,54 @@ describe('net module', () => {
expect(response.headers['x-cookie']).to.equal('undefined');
});

it('should be able correctly filter out cookies that are secure', async () => {
const serverUrl = await respondOnce.toSingleURL((request, response) => {
response.statusCode = 200;
response.statusMessage = 'OK';
response.setHeader('set-cookie', ['cookie1=1', 'cookie2=2; secure']);
response.end();
});
net.request({
url: serverUrl,
origin: serverUrl
});

const sess = session.fromPartition(`cookie-tests-${Math.random()}`);
const secureCookies = await sess.cookies.get({
secure: true
});
expect(secureCookies).to.have.lengthOf(1);

const cookies = await sess.cookies.get({
secure: false
});
expect(cookies).to.have.lengthOf(1);
});

it('should be able correctly filter out cookies that are session', async () => {
const serverUrl = await respondOnce.toSingleURL((request, response) => {
response.statusCode = 200;
response.statusMessage = 'OK';
response.setHeader('set-cookie', ['cookie1=1', 'cookie2=2; expires=Wed, 21 Oct 3023 07:28:00 GMT']);
response.end();
});
net.request({
url: serverUrl,
origin: serverUrl
});

const sess = session.fromPartition(`cookie-tests-${Math.random()}`);
const sessionCookies = await sess.cookies.get({
session: true
});
expect(sessionCookies).to.have.lengthOf(1);

const cookies = await sess.cookies.get({
session: false
});
expect(cookies).to.have.lengthOf(1);
});

for (const extraOptions of [{ useSessionCookies: true }, { credentials: 'include' }] as ClientRequestConstructorOptions[]) {
describe(`when ${JSON.stringify(extraOptions)}`, () => {
it('should be able to use the sessions cookie store', async () => {
Expand Down

0 comments on commit c954841

Please sign in to comment.