
var express = require('../')
  , request = require('./support/http');

describe('req', function(){
  describe('.signedCookies', function(){
    it('should unsign cookies', function(done){
      var app = express();

      app.use(express.cookieParser('foo bar baz'));

      app.use(function(req, res){
        req.cookies.should.not.have.property('name');
        res.end(req.signedCookies.name);
      });

      request(app)
      .get('/')
      .set('Cookie', 'name=tobi.2HDdGQqJ6jQU1S9dagggYDPaxGE')
      .end(function(res){
        res.body.should.equal('tobi');
        done();
      })
    })
    
    it('should parse JSON cookies', function(done){
      var app = express();

      app.use(express.cookieParser('foo bar baz'));

      app.use(function(req, res){
        req.cookies.should.not.have.property('user');
        res.end(req.signedCookies.user.name);
      });

      request(app)
      .get('/')
      .set('Cookie', 'user=j%3A%7B%22name%22%3A%22tobi%22%7D.aEbp4PGZo63zMX%2FcIMSn2M9pvms')
      .end(function(res){
        res.body.should.equal('tobi');
        done();
      })
    })
  })
})

@@ -1104,16 +1104,597 @@
 )%0A    %7D)
+%0A%0A    describe('when signature is invalid', function()%7B%0A      it('should unsign cookies', function(done)%7B%0A        var app = express();%0A%0A        app.use(express.cookieParser('foo bar baz'));%0A%0A        app.use(function(req, res)%7B%0A          req.signedCookies.should.not.have.property('name');%0A          res.end(req.cookies.name);%0A        %7D);%0A%0A        request(app)%0A        .get('/')%0A        .set('Cookie', 'name=tobi.2HDdGQqJ6jQU1S9dagasdfasdf')%0A        .end(function(res)%7B%0A          res.body.should.equal('tobi.2HDdGQqJ6jQU1S9dagasdfasdf');%0A          done();%0A        %7D)%0A      %7D)%0A    %7D)
 %0A  %7D)%0A%7D)

test for invalid cookie signature