@@ -124,6 +124,35 @@ describe("http", () => {
124124 } )
125125 } )
126126
127+ describe ( "getCookieDomain" , ( ) => {
128+ it ( "should use the proxy domain for the cookie" , ( ) => {
129+ const proxyDomains = [ "{{port}}.example.com" , "code-{{port}}.test.com" ]
130+ expect ( http . getCookieDomain ( "example.com" , proxyDomains ) ) . toBe ( "example.com" )
131+ expect ( http . getCookieDomain ( "8080.example.com" , proxyDomains ) ) . toBe ( "example.com" )
132+ expect ( http . getCookieDomain ( "8080.example.com:443" , proxyDomains ) ) . toBe ( "example.com" )
133+ expect ( http . getCookieDomain ( "code-8080.test.com" , proxyDomains ) ) . toBe ( "test.com" )
134+ } )
135+
136+ it ( "should use the highest level proxy domain" , ( ) => {
137+ const proxyDomains = [ "{{port}}.test.example.com" , "{{port}}.example.com" ]
138+ expect ( http . getCookieDomain ( "test.example.com" , proxyDomains ) ) . toBe ( "example.com" )
139+ expect ( http . getCookieDomain ( "8080.test.example.com" , proxyDomains ) ) . toBe ( "example.com" )
140+ } )
141+
142+ it ( "should use the host when no proxy domain matches" , ( ) => {
143+ expect ( http . getCookieDomain ( "code.other.com" , [ "{{port}}.example.com" ] ) ) . toBe ( "code.other.com" )
144+ expect ( http . getCookieDomain ( "8080.example.com" , [ "{{port}}.{{host}}" ] ) ) . toBe ( "8080.example.com" )
145+ expect ( http . getCookieDomain ( "8080.example.com" , [ ] ) ) . toBe ( "8080.example.com" )
146+ } )
147+
148+ it ( "should not set a domain for localhost or IP addresses" , ( ) => {
149+ const proxyDomains = [ "{{port}}.example.com" ]
150+ expect ( http . getCookieDomain ( "localhost:8080" , proxyDomains ) ) . toBe ( undefined )
151+ expect ( http . getCookieDomain ( "127.0.0.1:8080" , proxyDomains ) ) . toBe ( undefined )
152+ expect ( http . getCookieDomain ( "8080.dev.localhost" , proxyDomains ) ) . toBe ( undefined )
153+ } )
154+ } )
155+
127156 describe ( "constructRedirectPath" , ( ) => {
128157 it ( "should preserve slashes in queryString so they are human-readable" , ( ) => {
129158 const mockReq = getMockReq ( {
0 commit comments