@@ -88,7 +88,7 @@ public function testCancelPromiseWillCancelPendingConnection()
8888 public function testWillWriteToOpenConnection ()
8989 {
9090 $ stream = $ this ->getMockBuilder ('React\Socket\Connection ' )->disableOriginalConstructor ()->setMethods (array ('close ' , 'write ' ))->getMock ();
91- $ stream ->expects ($ this ->once ())->method ('write ' );
91+ $ stream ->expects ($ this ->once ())->method ('write ' )-> with ( " CONNECT google.com:80 HTTP/1.1 \r\n Host: google.com:80 \r\n\r\n" ) ;
9292
9393 $ promise = \React \Promise \resolve ($ stream );
9494 $ this ->connector ->expects ($ this ->once ())->method ('connect ' )->willReturn ($ promise );
@@ -98,6 +98,48 @@ public function testWillWriteToOpenConnection()
9898 $ proxy ->connect ('google.com:80 ' );
9999 }
100100
101+ public function testWillProxyAuthorizationHeaderIfProxyUriContainsAuthentication ()
102+ {
103+ $ stream = $ this ->getMockBuilder ('React\Socket\Connection ' )->disableOriginalConstructor ()->setMethods (array ('close ' , 'write ' ))->getMock ();
104+ $ stream ->expects ($ this ->once ())->method ('write ' )->with ("CONNECT google.com:80 HTTP/1.1 \r\nHost: google.com:80 \r\nProxy-Authorization: Basic dXNlcjpwYXNz \r\n\r\n" );
105+
106+ $ promise = \React \Promise \resolve ($ stream );
107+ $ this ->connector ->expects ($ this ->once ())->method ('connect ' )->willReturn ($ promise );
108+
109+ $ proxy = new ProxyConnector ('user:pass@proxy.example.com ' , $ this ->connector );
110+
111+ $ proxy ->connect ('google.com:80 ' );
112+ }
113+
114+ public function testWillProxyAuthorizationHeaderIfProxyUriContainsOnlyUsernameWithoutPassword ()
115+ {
116+ $ stream = $ this ->getMockBuilder ('React\Socket\Connection ' )->disableOriginalConstructor ()->setMethods (array ('close ' , 'write ' ))->getMock ();
117+ $ stream ->expects ($ this ->once ())->method ('write ' )->with ("CONNECT google.com:80 HTTP/1.1 \r\nHost: google.com:80 \r\nProxy-Authorization: Basic dXNlcjo= \r\n\r\n" );
118+
119+ $ promise = \React \Promise \resolve ($ stream );
120+ $ this ->connector ->expects ($ this ->once ())->method ('connect ' )->willReturn ($ promise );
121+
122+ $ proxy = new ProxyConnector ('user@proxy.example.com ' , $ this ->connector );
123+
124+ $ proxy ->connect ('google.com:80 ' );
125+ }
126+
127+ public function testWillProxyAuthorizationHeaderIfProxyUriContainsAuthenticationWithPercentEncoding ()
128+ {
129+ $ user = 'h@llÖ ' ;
130+ $ pass = '%secret? ' ;
131+
132+ $ stream = $ this ->getMockBuilder ('React\Socket\Connection ' )->disableOriginalConstructor ()->setMethods (array ('close ' , 'write ' ))->getMock ();
133+ $ stream ->expects ($ this ->once ())->method ('write ' )->with ("CONNECT google.com:80 HTTP/1.1 \r\nHost: google.com:80 \r\nProxy-Authorization: Basic " . base64_encode ($ user . ': ' . $ pass ) . "\r\n\r\n" );
134+
135+ $ promise = \React \Promise \resolve ($ stream );
136+ $ this ->connector ->expects ($ this ->once ())->method ('connect ' )->willReturn ($ promise );
137+
138+ $ proxy = new ProxyConnector (rawurlencode ($ user ) . ': ' . rawurlencode ($ pass ) . '@proxy.example.com ' , $ this ->connector );
139+
140+ $ proxy ->connect ('google.com:80 ' );
141+ }
142+
101143 public function testRejectsInvalidUri ()
102144 {
103145 $ this ->connector ->expects ($ this ->never ())->method ('connect ' );
0 commit comments