You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.5 KiB

  1. // builtin
  2. var assert = require('assert');
  3. var cookie = require('..');
  4. suite('serialize');
  5. test('basic', function() {
  6. assert.equal('foo=bar', cookie.serialize('foo', 'bar'));
  7. assert.equal('foo=bar%20baz', cookie.serialize('foo', 'bar baz'));
  8. });
  9. test('path', function() {
  10. assert.equal('foo=bar; Path=/', cookie.serialize('foo', 'bar', {
  11. path: '/'
  12. }));
  13. });
  14. test('secure', function() {
  15. assert.equal('foo=bar; Secure', cookie.serialize('foo', 'bar', {
  16. secure: true
  17. }));
  18. assert.equal('foo=bar', cookie.serialize('foo', 'bar', {
  19. secure: false
  20. }));
  21. });
  22. test('domain', function() {
  23. assert.equal('foo=bar; Domain=example.com', cookie.serialize('foo', 'bar', {
  24. domain: 'example.com'
  25. }));
  26. });
  27. test('httpOnly', function() {
  28. assert.equal('foo=bar; HttpOnly', cookie.serialize('foo', 'bar', {
  29. httpOnly: true
  30. }));
  31. });
  32. test('maxAge', function() {
  33. assert.equal('foo=bar; Max-Age=1000', cookie.serialize('foo', 'bar', {
  34. maxAge: 1000
  35. }));
  36. });
  37. test('escaping', function() {
  38. assert.deepEqual('cat=%2B%20', cookie.serialize('cat', '+ '));
  39. });
  40. test('parse->serialize', function() {
  41. assert.deepEqual({ cat: 'foo=123&name=baz five' }, cookie.parse(
  42. cookie.serialize('cat', 'foo=123&name=baz five')));
  43. assert.deepEqual({ cat: ' ";/' }, cookie.parse(
  44. cookie.serialize('cat', ' ";/')));
  45. });
  46. test('unencoded', function() {
  47. assert.deepEqual('cat=+ ', cookie.serialize('cat', '+ ', {
  48. encode: function(value) { return value; }
  49. }));
  50. })