@@ -1536,19 +1536,18 @@ describe('WebSocket', () => {
1536
1536
} ) ;
1537
1537
} ) ;
1538
1538
1539
- it ( 'drops the Authorization, Cookie and Host headers (2/4)' , function ( done ) {
1540
- if ( process . platform === 'win32' ) return this . skip ( ) ;
1541
-
1539
+ it ( 'drops the Authorization, Cookie and Host headers (2/4)' , ( done ) => {
1542
1540
// Test the `ws:` to `ws+unix:` case.
1543
1541
1544
- const socketPath = path . join (
1545
- os . tmpdir ( ) ,
1546
- `ws.${ crypto . randomBytes ( 16 ) . toString ( 'hex' ) } .sock`
1547
- ) ;
1542
+ const randomString = crypto . randomBytes ( 16 ) . toString ( 'hex' ) ;
1543
+ const ipcPath =
1544
+ process . platform === 'win32'
1545
+ ? `\\\\.\\pipe\\ws-pipe-${ randomString } `
1546
+ : path . join ( os . tmpdir ( ) , `ws-${ randomString } .sock` ) ;
1548
1547
1549
1548
server . once ( 'upgrade' , ( req , socket ) => {
1550
1549
socket . end (
1551
- `HTTP/1.1 302 Found\r\nLocation: ws+unix:${ socketPath } \r\n\r\n`
1550
+ `HTTP/1.1 302 Found\r\nLocation: ws+unix:${ ipcPath } \r\n\r\n`
1552
1551
) ;
1553
1552
} ) ;
1554
1553
@@ -1563,7 +1562,7 @@ describe('WebSocket', () => {
1563
1562
ws . close ( ) ;
1564
1563
} ) ;
1565
1564
1566
- redirectedServer . listen ( socketPath , ( ) => {
1565
+ redirectedServer . listen ( ipcPath , ( ) => {
1567
1566
const headers = {
1568
1567
authorization : 'Basic Zm9vOmJhcg==' ,
1569
1568
cookie : 'foo=bar' ,
@@ -1589,34 +1588,42 @@ describe('WebSocket', () => {
1589
1588
1590
1589
ws . on ( 'close' , ( code ) => {
1591
1590
assert . strictEqual ( code , 1005 ) ;
1592
- assert . strictEqual ( ws . url , `ws+unix:${ socketPath } ` ) ;
1591
+ assert . strictEqual ( ws . url , `ws+unix:${ ipcPath } ` ) ;
1593
1592
assert . strictEqual ( ws . _redirects , 1 ) ;
1594
1593
1595
1594
redirectedServer . close ( done ) ;
1596
1595
} ) ;
1597
1596
} ) ;
1598
1597
} ) ;
1599
1598
1600
- it ( 'drops the Authorization, Cookie and Host headers (3/4)' , function ( done ) {
1601
- if ( process . platform === 'win32' ) return this . skip ( ) ;
1602
-
1599
+ it ( 'drops the Authorization, Cookie and Host headers (3/4)' , ( done ) => {
1603
1600
// Test the `ws+unix:` to `ws+unix:` case.
1604
1601
1605
- const redirectingServerSocketPath = path . join (
1606
- os . tmpdir ( ) ,
1607
- `ws.${ crypto . randomBytes ( 16 ) . toString ( 'hex' ) } .sock`
1608
- ) ;
1609
- const redirectedServerSocketPath = path . join (
1610
- os . tmpdir ( ) ,
1611
- `ws.${ crypto . randomBytes ( 16 ) . toString ( 'hex' ) } .sock`
1612
- ) ;
1602
+ const randomString1 = crypto . randomBytes ( 16 ) . toString ( 'hex' ) ;
1603
+ const randomString2 = crypto . randomBytes ( 16 ) . toString ( 'hex' ) ;
1604
+ let redirectingServerIpcPath ;
1605
+ let redirectedServerIpcPath ;
1606
+
1607
+ if ( process . platform === 'win32' ) {
1608
+ redirectingServerIpcPath = `\\\\.\\pipe\\ws-pipe-${ randomString1 } ` ;
1609
+ redirectedServerIpcPath = `\\\\.\\pipe\\ws-pipe-${ randomString2 } ` ;
1610
+ } else {
1611
+ redirectingServerIpcPath = path . join (
1612
+ os . tmpdir ( ) ,
1613
+ `ws-${ randomString1 } .sock`
1614
+ ) ;
1615
+ redirectedServerIpcPath = path . join (
1616
+ os . tmpdir ( ) ,
1617
+ `ws-${ randomString2 } .sock`
1618
+ ) ;
1619
+ }
1613
1620
1614
1621
const redirectingServer = http . createServer ( ) ;
1615
1622
1616
1623
redirectingServer . on ( 'upgrade' , ( req , socket ) => {
1617
1624
socket . end (
1618
1625
'HTTP/1.1 302 Found\r\n' +
1619
- `Location: ws+unix:${ redirectedServerSocketPath } \r\n\r\n`
1626
+ `Location: ws+unix:${ redirectedServerIpcPath } \r\n\r\n`
1620
1627
) ;
1621
1628
} ) ;
1622
1629
@@ -1631,8 +1638,8 @@ describe('WebSocket', () => {
1631
1638
ws . close ( ) ;
1632
1639
} ) ;
1633
1640
1634
- redirectingServer . listen ( redirectingServerSocketPath , listening ) ;
1635
- redirectedServer . listen ( redirectedServerSocketPath , listening ) ;
1641
+ redirectingServer . listen ( redirectingServerIpcPath , listening ) ;
1642
+ redirectedServer . listen ( redirectedServerIpcPath , listening ) ;
1636
1643
1637
1644
let callCount = 0 ;
1638
1645
@@ -1645,7 +1652,7 @@ describe('WebSocket', () => {
1645
1652
host : 'foo'
1646
1653
} ;
1647
1654
1648
- const ws = new WebSocket ( `ws+unix:${ redirectingServerSocketPath } ` , {
1655
+ const ws = new WebSocket ( `ws+unix:${ redirectingServerIpcPath } ` , {
1649
1656
followRedirects : true ,
1650
1657
headers
1651
1658
} ) ;
@@ -1664,10 +1671,7 @@ describe('WebSocket', () => {
1664
1671
1665
1672
ws . on ( 'close' , ( code ) => {
1666
1673
assert . strictEqual ( code , 1005 ) ;
1667
- assert . strictEqual (
1668
- ws . url ,
1669
- `ws+unix:${ redirectedServerSocketPath } `
1670
- ) ;
1674
+ assert . strictEqual ( ws . url , `ws+unix:${ redirectedServerIpcPath } ` ) ;
1671
1675
assert . strictEqual ( ws . _redirects , 1 ) ;
1672
1676
1673
1677
redirectingServer . close ( ) ;
@@ -1676,9 +1680,7 @@ describe('WebSocket', () => {
1676
1680
}
1677
1681
} ) ;
1678
1682
1679
- it ( 'drops the Authorization, Cookie and Host headers (4/4)' , function ( done ) {
1680
- if ( process . platform === 'win32' ) return this . skip ( ) ;
1681
-
1683
+ it ( 'drops the Authorization, Cookie and Host headers (4/4)' , ( done ) => {
1682
1684
// Test the `ws+unix:` to `ws:` case.
1683
1685
1684
1686
const redirectingServer = http . createServer ( ) ;
@@ -1696,12 +1698,13 @@ describe('WebSocket', () => {
1696
1698
ws . close ( ) ;
1697
1699
} ) ;
1698
1700
1699
- const socketPath = path . join (
1700
- os . tmpdir ( ) ,
1701
- `ws.${ crypto . randomBytes ( 16 ) . toString ( 'hex' ) } .sock`
1702
- ) ;
1701
+ const randomString = crypto . randomBytes ( 16 ) . toString ( 'hex' ) ;
1702
+ const ipcPath =
1703
+ process . platform === 'win32'
1704
+ ? `\\\\.\\pipe\\ws-pipe-${ randomString } `
1705
+ : path . join ( os . tmpdir ( ) , `ws-${ randomString } .sock` ) ;
1703
1706
1704
- redirectingServer . listen ( socketPath , listening ) ;
1707
+ redirectingServer . listen ( ipcPath , listening ) ;
1705
1708
redirectedServer . listen ( 0 , listening ) ;
1706
1709
1707
1710
let callCount = 0 ;
@@ -1723,7 +1726,7 @@ describe('WebSocket', () => {
1723
1726
host : 'foo'
1724
1727
} ;
1725
1728
1726
- const ws = new WebSocket ( `ws+unix:${ socketPath } ` , {
1729
+ const ws = new WebSocket ( `ws+unix:${ ipcPath } ` , {
1727
1730
followRedirects : true ,
1728
1731
headers
1729
1732
} ) ;
0 commit comments