@@ -152,7 +152,7 @@ public function testHandleSocksConnectionWillEndOnInvalidData()
152152 $ connection ->emit ('data ' , array ('asdasdasdasdasd ' ));
153153 }
154154
155- public function testHandleSocksConnectionWillEstablishOutgoingConnection ()
155+ public function testHandleSocks4ConnectionWithIpv4WillEstablishOutgoingConnection ()
156156 {
157157 $ connection = $ this ->getMockBuilder ('React\Socket\Connection ' )->disableOriginalConstructor ()->setMethods (array ('pause ' , 'end ' ))->getMock ();
158158
@@ -165,6 +165,80 @@ public function testHandleSocksConnectionWillEstablishOutgoingConnection()
165165 $ connection ->emit ('data ' , array ("\x04\x01" . "\x00\x50" . pack ('N ' , ip2long ('127.0.0.1 ' )) . "\x00" ));
166166 }
167167
168+ public function testHandleSocks4aConnectionWithHostnameWillEstablishOutgoingConnection ()
169+ {
170+ $ connection = $ this ->getMockBuilder ('React\Socket\Connection ' )->disableOriginalConstructor ()->setMethods (array ('pause ' , 'end ' ))->getMock ();
171+
172+ $ promise = new Promise (function () { });
173+
174+ $ this ->connector ->expects ($ this ->once ())->method ('connect ' )->with ('example.com:80 ' )->willReturn ($ promise );
175+
176+ $ this ->server ->onConnection ($ connection );
177+
178+ $ connection ->emit ('data ' , array ("\x04\x01" . "\x00\x50" . "\x00\x00\x00\x01" . "\x00" . "example.com " . "\x00" ));
179+ }
180+
181+ public function testHandleSocks4aConnectionWithInvalidHostnameWillNotEstablishOutgoingConnection ()
182+ {
183+ $ connection = $ this ->getMockBuilder ('React\Socket\Connection ' )->disableOriginalConstructor ()->setMethods (array ('pause ' , 'end ' ))->getMock ();
184+
185+ $ this ->connector ->expects ($ this ->never ())->method ('connect ' );
186+
187+ $ this ->server ->onConnection ($ connection );
188+
189+ $ connection ->emit ('data ' , array ("\x04\x01" . "\x00\x50" . "\x00\x00\x00\x01" . "\x00" . "tls://example.com:80? " . "\x00" ));
190+ }
191+
192+ public function testHandleSocks5ConnectionWithIpv4WillEstablishOutgoingConnection ()
193+ {
194+ $ connection = $ this ->getMockBuilder ('React\Socket\Connection ' )->disableOriginalConstructor ()->setMethods (array ('pause ' , 'end ' , 'write ' ))->getMock ();
195+
196+ $ promise = new Promise (function () { });
197+
198+ $ this ->connector ->expects ($ this ->once ())->method ('connect ' )->with ('127.0.0.1:80 ' )->willReturn ($ promise );
199+
200+ $ this ->server ->onConnection ($ connection );
201+
202+ $ connection ->emit ('data ' , array ("\x05\x01\x00" . "\x05\x01\x00\x01" . pack ('N ' , ip2long ('127.0.0.1 ' )) . "\x00\x50" ));
203+ }
204+
205+ public function testHandleSocks5ConnectionWithIpv6WillEstablishOutgoingConnection ()
206+ {
207+ $ connection = $ this ->getMockBuilder ('React\Socket\Connection ' )->disableOriginalConstructor ()->setMethods (array ('pause ' , 'end ' , 'write ' ))->getMock ();
208+
209+ $ promise = new Promise (function () { });
210+
211+ $ this ->connector ->expects ($ this ->once ())->method ('connect ' )->with ('[::1]:80 ' )->willReturn ($ promise );
212+
213+ $ this ->server ->onConnection ($ connection );
214+
215+ $ connection ->emit ('data ' , array ("\x05\x01\x00" . "\x05\x01\x00\x04" . inet_pton ('::1 ' ) . "\x00\x50" ));
216+ }
217+
218+ public function testHandleSocks5ConnectionWithHostnameWillEstablishOutgoingConnection ()
219+ {
220+ $ connection = $ this ->getMockBuilder ('React\Socket\Connection ' )->disableOriginalConstructor ()->setMethods (array ('pause ' , 'end ' , 'write ' ))->getMock ();
221+
222+ $ promise = new Promise (function () { });
223+
224+ $ this ->connector ->expects ($ this ->once ())->method ('connect ' )->with ('example.com:80 ' )->willReturn ($ promise );
225+
226+ $ this ->server ->onConnection ($ connection );
227+
228+ $ connection ->emit ('data ' , array ("\x05\x01\x00" . "\x05\x01\x00\x03\x0B" . "example.com " . "\x00\x50" ));
229+ }
230+
231+ public function testHandleSocks5ConnectionWithInvalidHostnameWillNotEstablishOutgoingConnection ()
232+ {
233+ $ connection = $ this ->getMockBuilder ('React\Socket\Connection ' )->disableOriginalConstructor ()->setMethods (array ('pause ' , 'end ' , 'write ' ))->getMock ();
234+
235+ $ this ->connector ->expects ($ this ->never ())->method ('connect ' );
236+
237+ $ this ->server ->onConnection ($ connection );
238+
239+ $ connection ->emit ('data ' , array ("\x05\x01\x00" . "\x05\x01\x00\x03\x15" . "tls://example.com:80? " . "\x00\x50" ));
240+ }
241+
168242 public function testHandleSocksConnectionWillCancelOutputConnectionIfIncomingCloses ()
169243 {
170244 $ connection = $ this ->getMockBuilder ('React\Socket\Connection ' )->disableOriginalConstructor ()->setMethods (array ('pause ' , 'end ' ))->getMock ();
0 commit comments