@@ -64,6 +64,41 @@ it('should use proxy', async ({ contextFactory, server, proxyServer }) => {
64
64
await context . close ( ) ;
65
65
} ) ;
66
66
67
+ it ( 'should send secure cookies to subdomain.localhost' , async ( { contextFactory, browserName, server, proxyServer } ) => {
68
+ proxyServer . forwardTo ( server . PORT ) ;
69
+ const context = await contextFactory ( {
70
+ proxy : { server : `localhost:${ proxyServer . PORT } ` } ,
71
+ } ) ;
72
+ server . setRoute ( '/set-cookie.html' , async ( req , res ) => {
73
+ res . setHeader ( 'Set-Cookie' , [ `non-secure=1; HttpOnly` , `secure=1; HttpOnly; Secure` ] ) ;
74
+ res . end ( ) ;
75
+ } ) ;
76
+ server . setRoute ( '/read-cookie.html' , async ( req , res ) => {
77
+ res . setHeader ( 'Content-Type' , `text/html` ) ;
78
+ res . end ( `<div>Cookie: ${ req . headers . cookie . split ( ';' ) . map ( c => c . trim ( ) ) . sort ( ) . join ( '; ' ) } </div>` ) ;
79
+ } ) ;
80
+
81
+ const page = await context . newPage ( ) ;
82
+
83
+ await page . goto ( `http://subdomain.localhost/set-cookie.html` ) ;
84
+
85
+ const cookies = await context . cookies ( 'http://subdomain.localhost' ) ;
86
+ expect ( cookies . map ( ( { name, domain } ) => ( { name, domain } ) ) ) . toEqual ( [
87
+ {
88
+ name : 'non-secure' ,
89
+ domain : 'subdomain.localhost' ,
90
+ } ,
91
+ ...( browserName === 'webkit' ? [ ] : [ {
92
+ name : 'secure' ,
93
+ domain : 'subdomain.localhost' ,
94
+ } ] ) ,
95
+ ] ) ;
96
+
97
+ await page . goto ( `http://subdomain.localhost/read-cookie.html` ) ;
98
+ await expect ( page . locator ( 'div' ) ) . toHaveText ( browserName === 'webkit' ? 'Cookie: non-secure=1' : 'Cookie: non-secure=1; secure=1' ) ;
99
+
100
+ await context . close ( ) ;
101
+ } ) ;
67
102
68
103
it ( 'should set cookie for top-level domain' , {
69
104
annotation : { type : 'issue' , description : 'https://github.com/microsoft/playwright/issues/18362' }
0 commit comments