@@ -15,10 +15,6 @@ describe('cookieParser()', function(){
1515 assert ( typeof cookieParser . JSONCookies , 'function' )
1616 } )
1717
18- it ( 'should export signedCookie function' , function ( ) {
19- assert ( typeof cookieParser . signedCookie , 'function' )
20- } )
21-
2218 it ( 'should export signedCookies function' , function ( ) {
2319 assert ( typeof cookieParser . signedCookies , 'function' )
2420 } )
@@ -142,6 +138,22 @@ describe('cookieParser.JSONCookie(str)', function () {
142138 } )
143139} )
144140
141+ describe ( 'cookieParser.signedCookie(str, secret)' , function ( ) {
142+ it ( 'should pass through non-signed string' , function ( ) {
143+ assert . strictEqual ( cookieParser . signedCookie ( '' , 'keyboard cat' ) , '' )
144+ assert . strictEqual ( cookieParser . signedCookie ( 'foo' , 'keyboard cat' ) , 'foo' )
145+ assert . strictEqual ( cookieParser . signedCookie ( 'j:{}' , 'keyboard cat' ) , 'j:{}' )
146+ } )
147+
148+ it ( 'should return false for tampered signed string' , function ( ) {
149+ assert . strictEqual ( cookieParser . signedCookie ( 's:foobaz.N5r0C3M8W+IPpzyAJaIddMWbTGfDSO+bfKlZErJ+MeE' , 'keyboard cat' ) , false )
150+ } )
151+
152+ it ( 'should return unsigned value for signed string' , function ( ) {
153+ assert . strictEqual ( cookieParser . signedCookie ( 's:foobar.N5r0C3M8W+IPpzyAJaIddMWbTGfDSO+bfKlZErJ+MeE' , 'keyboard cat' ) , 'foobar' )
154+ } )
155+ } )
156+
145157function createServer ( secret ) {
146158 var _parser = cookieParser ( secret )
147159 return http . createServer ( function ( req , res ) {
0 commit comments