@@ -271,6 +271,20 @@ public function testHandleSocks4aConnectionWithHostnameAndSourceAddressWillEstab
271271 $ connection ->emit ('data ' , array ("\x04\x01" . "\x00\x50" . "\x00\x00\x00\x01" . "\x00" . "example.com " . "\x00" ));
272272 }
273273
274+ public function testHandleSocks4aConnectionWithSecureTlsSourceAddressWillEstablishOutgoingConnection ()
275+ {
276+ $ connection = $ this ->getMockBuilder ('React\Socket\Connection ' )->disableOriginalConstructor ()->setMethods (array ('pause ' , 'end ' , 'getRemoteAddress ' ))->getMock ();
277+ $ connection ->expects ($ this ->once ())->method ('getRemoteAddress ' )->willReturn ('tls://10.20.30.40:5060 ' );
278+
279+ $ promise = new Promise (function () { });
280+
281+ $ this ->connector ->expects ($ this ->once ())->method ('connect ' )->with ('example.com:80?source=socks4s%3A%2F%2F10.20.30.40%3A5060 ' )->willReturn ($ promise );
282+
283+ $ this ->server ->onConnection ($ connection );
284+
285+ $ connection ->emit ('data ' , array ("\x04\x01" . "\x00\x50" . "\x00\x00\x00\x01" . "\x00" . "example.com " . "\x00" ));
286+ }
287+
274288 public function testHandleSocks4aConnectionWithInvalidHostnameWillNotEstablishOutgoingConnection ()
275289 {
276290 $ connection = $ this ->getMockBuilder ('React\Socket\Connection ' )->disableOriginalConstructor ()->setMethods (array ('pause ' , 'end ' ))->getMock ();
@@ -309,6 +323,20 @@ public function testHandleSocks5ConnectionWithIpv4AndSourceAddressWillEstablishO
309323 $ connection ->emit ('data ' , array ("\x05\x01\x00" . "\x05\x01\x00\x01" . pack ('N ' , ip2long ('127.0.0.1 ' )) . "\x00\x50" ));
310324 }
311325
326+ public function testHandleSocks5ConnectionWithSecureTlsIpv4AndSourceAddressWillEstablishOutgoingConnection ()
327+ {
328+ $ connection = $ this ->getMockBuilder ('React\Socket\Connection ' )->disableOriginalConstructor ()->setMethods (array ('pause ' , 'end ' , 'write ' , 'getRemoteAddress ' ))->getMock ();
329+ $ connection ->expects ($ this ->once ())->method ('getRemoteAddress ' )->willReturn ('tls://10.20.30.40:5060 ' );
330+
331+ $ promise = new Promise (function () { });
332+
333+ $ this ->connector ->expects ($ this ->once ())->method ('connect ' )->with ('127.0.0.1:80?source=socks5s%3A%2F%2F10.20.30.40%3A5060 ' )->willReturn ($ promise );
334+
335+ $ this ->server ->onConnection ($ connection );
336+
337+ $ connection ->emit ('data ' , array ("\x05\x01\x00" . "\x05\x01\x00\x01" . pack ('N ' , ip2long ('127.0.0.1 ' )) . "\x00\x50" ));
338+ }
339+
312340 public function testHandleSocks5ConnectionWithIpv6WillEstablishOutgoingConnection ()
313341 {
314342 $ connection = $ this ->getMockBuilder ('React\Socket\Connection ' )->disableOriginalConstructor ()->setMethods (array ('pause ' , 'end ' , 'write ' ))->getMock ();
0 commit comments