@@ -88,7 +88,7 @@ public function testCancelPromiseWillCancelPendingConnection()
88
88
public function testWillWriteToOpenConnection ()
89
89
{
90
90
$ 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" ) ;
92
92
93
93
$ promise = \React \Promise \resolve ($ stream );
94
94
$ this ->connector ->expects ($ this ->once ())->method ('connect ' )->willReturn ($ promise );
@@ -98,6 +98,48 @@ public function testWillWriteToOpenConnection()
98
98
$ proxy ->connect ('google.com:80 ' );
99
99
}
100
100
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:[email protected] ' ,
$ 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 (
'[email protected] ' ,
$ 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
+
101
143
public function testRejectsInvalidUri ()
102
144
{
103
145
$ this ->connector ->expects ($ this ->never ())->method ('connect ' );
0 commit comments