it('optionally adds a TTL', function () { const rawRes = {}; const res = new SyntheticResponse(rawRes, {}); res.cookie('hello', 'banana', {ttl: 22}); expect(rawRes.cookies).to.eql([ {name: 'hello', value: 'banana', lifeTime: 22} ]); });
it('treats options number as a TTL value', function () { const rawRes = {}; const res = new SyntheticResponse(rawRes, {}); res.cookie('hello', 'banana', 22); expect(rawRes.cookies).to.eql([ {name: 'hello', value: 'banana', lifeTime: 22} ]); });
it('adds a cookie', function () { const rawRes = {}; const res = new SyntheticResponse(rawRes, {}); res.cookie('hello', 'banana'); expect(rawRes.cookies).to.eql([ {name: 'hello', value: 'banana'} ]); });
it('treats options string as a secret', function () { const rawRes = {}; const res = new SyntheticResponse(rawRes, {}); res.cookie('hello', 'banana', 'potato'); expect(rawRes.cookies).to.eql([ {name: 'hello', value: 'banana'}, {name: 'hello.sig', value: crypto.hmac('potato', 'banana')} ]); });
it('supports signed cookies when a secret is provided', function () { const rawRes = {}; const res = new SyntheticResponse(rawRes, {}); res.cookie('hello', 'banana', {secret: 'potato'}); expect(rawRes.cookies).to.eql([ {name: 'hello', value: 'banana'}, {name: 'hello.sig', value: crypto.hmac('potato', 'banana')} ]); });
it('supports signed cookies with different algorithms', function () { const rawRes = {}; const res = new SyntheticResponse(rawRes, {}); res.cookie('hello', 'banana', { secret: 'potato', algorithm: 'sha512' }); expect(rawRes.cookies).to.eql([ {name: 'hello', value: 'banana'}, {name: 'hello.sig', value: crypto.hmac('potato', 'banana', 'sha512')} ]); });
it('optionally adds some metadata', function () { const rawRes = {}; const res = new SyntheticResponse(rawRes, {}); res.cookie('hello', 'banana', { path: '/path', domain: 'cats.example', secure: true, httpOnly: true }); expect(rawRes.cookies).to.eql([ { name: 'hello', value: 'banana', path: '/path', domain: 'cats.example', secure: true, httpOnly: true } ]); });