@@ -48,6 +48,60 @@ describe('language detector', () => {
4848 expect ( res . headers [ 'Set-Cookie' ] ) . to . match ( / m y = c o o k i e / )
4949 expect ( res . headers [ 'Set-Cookie' ] ) . to . match ( / S a m e S i t e = N o n e / )
5050 } )
51+
52+ it ( 'does not set httpOnly flag by default' , ( ) => {
53+ const ld = new LanguageDetector ( i18next . services , { order : [ 'cookie' , 'header' ] } )
54+ const req = { }
55+ const res = {
56+ headers : {
57+ 'Set-Cookie' : 'my=cookie'
58+ }
59+ }
60+ res . header = ( name , value ) => { res . headers [ name ] = value }
61+ ld . cacheUserLanguage ( req , res , 'it' , [ 'cookie' ] )
62+ expect ( req ) . to . eql ( { } )
63+ expect ( res ) . to . have . property ( 'headers' )
64+ expect ( res . headers ) . to . have . property ( 'Set-Cookie' )
65+ expect ( res . headers [ 'Set-Cookie' ] ) . to . match ( / P a t h = \/ / )
66+ expect ( res . headers [ 'Set-Cookie' ] ) . to . match ( / m y = c o o k i e / )
67+ expect ( res . headers [ 'Set-Cookie' ] ) . not . to . match ( / H t t p O n l y / )
68+ } )
69+
70+ it ( 'does not set httpOnly flag when cookieHttpOnly is false' , ( ) => {
71+ const ld = new LanguageDetector ( i18next . services , { order : [ 'cookie' , 'header' ] , cookieHttpOnly : false } )
72+ const req = { }
73+ const res = {
74+ headers : {
75+ 'Set-Cookie' : 'my=cookie'
76+ }
77+ }
78+ res . header = ( name , value ) => { res . headers [ name ] = value }
79+ ld . cacheUserLanguage ( req , res , 'it' , [ 'cookie' ] )
80+ expect ( req ) . to . eql ( { } )
81+ expect ( res ) . to . have . property ( 'headers' )
82+ expect ( res . headers ) . to . have . property ( 'Set-Cookie' )
83+ expect ( res . headers [ 'Set-Cookie' ] ) . to . match ( / P a t h = \/ / )
84+ expect ( res . headers [ 'Set-Cookie' ] ) . to . match ( / m y = c o o k i e / )
85+ expect ( res . headers [ 'Set-Cookie' ] ) . not . to . match ( / H t t p O n l y / )
86+ } )
87+
88+ it ( 'sets httpOnly flag when cookieHttpOnly is true' , ( ) => {
89+ const ld = new LanguageDetector ( i18next . services , { order : [ 'cookie' , 'header' ] , cookieHttpOnly : true } )
90+ const req = { }
91+ const res = {
92+ headers : {
93+ 'Set-Cookie' : 'my=cookie'
94+ }
95+ }
96+ res . header = ( name , value ) => { res . headers [ name ] = value }
97+ ld . cacheUserLanguage ( req , res , 'it' , [ 'cookie' ] )
98+ expect ( req ) . to . eql ( { } )
99+ expect ( res ) . to . have . property ( 'headers' )
100+ expect ( res . headers ) . to . have . property ( 'Set-Cookie' )
101+ expect ( res . headers [ 'Set-Cookie' ] ) . to . match ( / P a t h = \/ / )
102+ expect ( res . headers [ 'Set-Cookie' ] ) . to . match ( / m y = c o o k i e / )
103+ expect ( res . headers [ 'Set-Cookie' ] ) . to . match ( / H t t p O n l y / )
104+ } )
51105 } )
52106
53107 describe ( 'header' , ( ) => {
0 commit comments