@@ -230,6 +230,35 @@ describe("http", () => {
230230 } )
231231 } )
232232
233+ describe ( "getCookieDomain" , ( ) => {
234+ it ( "should use the proxy domain for the cookie" , ( ) => {
235+ const proxyDomains = [ "{{port}}.example.com" , "code-{{port}}.test.com" ]
236+ expect ( http . getCookieDomain ( "example.com" , proxyDomains ) ) . toBe ( "example.com" )
237+ expect ( http . getCookieDomain ( "8080.example.com" , proxyDomains ) ) . toBe ( "example.com" )
238+ expect ( http . getCookieDomain ( "8080.example.com:443" , proxyDomains ) ) . toBe ( "example.com" )
239+ expect ( http . getCookieDomain ( "code-8080.test.com" , proxyDomains ) ) . toBe ( "test.com" )
240+ } )
241+
242+ it ( "should use the highest level proxy domain" , ( ) => {
243+ const proxyDomains = [ "{{port}}.test.example.com" , "{{port}}.example.com" ]
244+ expect ( http . getCookieDomain ( "test.example.com" , proxyDomains ) ) . toBe ( "example.com" )
245+ expect ( http . getCookieDomain ( "8080.test.example.com" , proxyDomains ) ) . toBe ( "example.com" )
246+ } )
247+
248+ it ( "should use the host when no proxy domain matches" , ( ) => {
249+ expect ( http . getCookieDomain ( "code.other.com" , [ "{{port}}.example.com" ] ) ) . toBe ( "code.other.com" )
250+ expect ( http . getCookieDomain ( "8080.example.com" , [ "{{port}}.{{host}}" ] ) ) . toBe ( "8080.example.com" )
251+ expect ( http . getCookieDomain ( "8080.example.com" , [ ] ) ) . toBe ( "8080.example.com" )
252+ } )
253+
254+ it ( "should not set a domain for localhost or IP addresses" , ( ) => {
255+ const proxyDomains = [ "{{port}}.example.com" ]
256+ expect ( http . getCookieDomain ( "localhost:8080" , proxyDomains ) ) . toBe ( undefined )
257+ expect ( http . getCookieDomain ( "127.0.0.1:8080" , proxyDomains ) ) . toBe ( undefined )
258+ expect ( http . getCookieDomain ( "8080.dev.localhost" , proxyDomains ) ) . toBe ( undefined )
259+ } )
260+ } )
261+
233262 describe ( "constructRedirectPath" , ( ) => {
234263 it ( "should preserve slashes in queryString so they are human-readable" , ( ) => {
235264 const mockReq = getMockReq ( {
0 commit comments