@@ -15,10 +15,6 @@ describe('cookieParser()', function(){
1515 assert ( typeof cookieParser . JSONCookies , 'function' )
1616 } )
1717
18- it ( 'should export signedCookies function' , function ( ) {
19- assert ( typeof cookieParser . signedCookies , 'function' )
20- } )
21-
2218 describe ( 'when no cookies are sent' , function ( ) {
2319 it ( 'should default req.cookies to {}' , function ( done ) {
2420 request ( server )
@@ -163,6 +159,53 @@ describe('cookieParser.signedCookie(str, secret)', function () {
163159 } )
164160} )
165161
162+ describe ( 'cookieParser.signedCookies(obj, secret)' , function ( ) {
163+ it ( 'should ignore non-signed strings' , function ( ) {
164+ assert . deepEqual ( cookieParser . signedCookies ( { } , 'keyboard cat' ) , { } )
165+ assert . deepEqual ( cookieParser . signedCookies ( { foo : 'bar' } , 'keyboard cat' ) , { } )
166+ } )
167+
168+ it ( 'should include tampered strings as false' , function ( ) {
169+ assert . deepEqual ( cookieParser . signedCookies ( { foo : 's:foobaz.N5r0C3M8W+IPpzyAJaIddMWbTGfDSO+bfKlZErJ+MeE' } , 'keyboard cat' ) , {
170+ foo : false
171+ } )
172+ } )
173+
174+ it ( 'should include unsigned strings' , function ( ) {
175+ assert . deepEqual ( cookieParser . signedCookies ( { foo : 's:foobar.N5r0C3M8W+IPpzyAJaIddMWbTGfDSO+bfKlZErJ+MeE' } , 'keyboard cat' ) , {
176+ foo : 'foobar'
177+ } )
178+ } )
179+
180+ it ( 'should remove signed strings from original object' , function ( ) {
181+ var obj = {
182+ foo : 's:foobar.N5r0C3M8W+IPpzyAJaIddMWbTGfDSO+bfKlZErJ+MeE'
183+ }
184+
185+ assert . deepEqual ( cookieParser . signedCookies ( obj , 'keyboard cat' ) , { foo : 'foobar' } )
186+ assert . deepEqual ( obj , { } )
187+ } )
188+
189+ it ( 'should remove tampered strings from original object' , function ( ) {
190+ var obj = {
191+ foo : 's:foobaz.N5r0C3M8W+IPpzyAJaIddMWbTGfDSO+bfKlZErJ+MeE'
192+ }
193+
194+ assert . deepEqual ( cookieParser . signedCookies ( obj , 'keyboard cat' ) , { foo : false } )
195+ assert . deepEqual ( obj , { } )
196+ } )
197+
198+ it ( 'should leave unsigned string in original object' , function ( ) {
199+ var obj = {
200+ fizz : 'buzz' ,
201+ foo : 's:foobar.N5r0C3M8W+IPpzyAJaIddMWbTGfDSO+bfKlZErJ+MeE'
202+ }
203+
204+ assert . deepEqual ( cookieParser . signedCookies ( obj , 'keyboard cat' ) , { foo : 'foobar' } )
205+ assert . deepEqual ( obj , { fizz : 'buzz' } )
206+ } )
207+ } )
208+
166209function createServer ( secret ) {
167210 var _parser = cookieParser ( secret )
168211 return http . createServer ( function ( req , res ) {
0 commit comments