@@ -38,7 +38,82 @@ describe("Cookie based apiKey persistence in document.cookie", () => {
38
38
authorize ( jest . fn ( ) , system ) ( payload )
39
39
40
40
expect ( document . cookie ) . toEqual (
41
- "apiKeyCookie=test; SameSite=None; Secure"
41
+ "apiKeyCookie=test;samesite=None;path=/"
42
+ )
43
+ } )
44
+
45
+ it ( "should persist secure cookie in document.cookie for non-SSL targets" , ( ) => {
46
+ const system = {
47
+ getConfigs : ( ) => ( {
48
+ persistAuthorization : true ,
49
+ url : "http://example.org"
50
+ } ) ,
51
+ }
52
+ const payload = {
53
+ api_key : {
54
+ schema : fromJS ( {
55
+ type : "apiKey" ,
56
+ name : "apiKeyCookie" ,
57
+ in : "cookie" ,
58
+ } ) ,
59
+ value : "test" ,
60
+ } ,
61
+ }
62
+
63
+ authorize ( jest . fn ( ) , system ) ( payload )
64
+
65
+ expect ( document . cookie ) . toEqual (
66
+ "apiKeyCookie=test;samesite=None;path=/"
67
+ )
68
+ } )
69
+
70
+ it ( "should persist secure cookie in document.cookie for SSL targets" , ( ) => {
71
+ const system = {
72
+ getConfigs : ( ) => ( {
73
+ persistAuthorization : true ,
74
+ url : "https://example.org"
75
+ } ) ,
76
+ }
77
+ const payload = {
78
+ api_key : {
79
+ schema : fromJS ( {
80
+ type : "apiKey" ,
81
+ name : "apiKeyCookie" ,
82
+ in : "cookie" ,
83
+ } ) ,
84
+ value : "test" ,
85
+ } ,
86
+ }
87
+
88
+ authorize ( jest . fn ( ) , system ) ( payload )
89
+
90
+ expect ( document . cookie ) . toEqual (
91
+ "apiKeyCookie=test;samesite=None;secure;path=/"
92
+ )
93
+ } )
94
+
95
+ it ( "should persist secure cookie in document.cookie for non-root SSL targets" , ( ) => {
96
+ const system = {
97
+ getConfigs : ( ) => ( {
98
+ persistAuthorization : true ,
99
+ url : "https://example.org/api"
100
+ } ) ,
101
+ }
102
+ const payload = {
103
+ api_key : {
104
+ schema : fromJS ( {
105
+ type : "apiKey" ,
106
+ name : "apiKeyCookie" ,
107
+ in : "cookie" ,
108
+ } ) ,
109
+ value : "test" ,
110
+ } ,
111
+ }
112
+
113
+ authorize ( jest . fn ( ) , system ) ( payload )
114
+
115
+ expect ( document . cookie ) . toEqual (
116
+ "apiKeyCookie=test;samesite=None;secure;path=/api"
42
117
)
43
118
} )
44
119
@@ -64,7 +139,7 @@ describe("Cookie based apiKey persistence in document.cookie", () => {
64
139
65
140
logout ( jest . fn ( ) , system ) ( [ "api_key" ] )
66
141
67
- expect ( document . cookie ) . toEqual ( "apiKeyCookie=; Max-Age =-99999999" )
142
+ expect ( document . cookie ) . toEqual ( "apiKeyCookie=;max-age =-99999999;path=/ " )
68
143
} )
69
144
} )
70
145
0 commit comments