@@ -23,20 +23,38 @@ public function testInvalidProxy()
23
23
new ProxyConnector ('/// ' , $ this ->connector );
24
24
}
25
25
26
+ /**
27
+ * @expectedException InvalidArgumentException
28
+ */
29
+ public function testInvalidProxyScheme ()
30
+ {
31
+ new ProxyConnector ('ftp://example.com ' , $ this ->connector );
32
+ }
33
+
26
34
public function testCreatesConnectionToHttpPort ()
27
35
{
28
36
$ promise = new Promise (function () { });
29
- $ this ->connector ->expects ($ this ->once ())->method ('connect ' )->with ('proxy.example.com:80?hostname=google.com ' )->willReturn ($ promise );
37
+ $ this ->connector ->expects ($ this ->once ())->method ('connect ' )->with ('tcp:// proxy.example.com:80?hostname=google.com ' )->willReturn ($ promise );
30
38
31
39
$ proxy = new ProxyConnector ('proxy.example.com ' , $ this ->connector );
32
40
33
41
$ proxy ->connect ('google.com:80 ' );
34
42
}
35
43
44
+ public function testCreatesConnectionToHttpPortAndPassesThroughUriComponents ()
45
+ {
46
+ $ promise = new Promise (function () { });
47
+ $ this ->connector ->expects ($ this ->once ())->method ('connect ' )->with ('tcp://proxy.example.com:80/path?foo=bar&hostname=google.com#segment ' )->willReturn ($ promise );
48
+
49
+ $ proxy = new ProxyConnector ('proxy.example.com ' , $ this ->connector );
50
+
51
+ $ proxy ->connect ('google.com:80/path?foo=bar#segment ' );
52
+ }
53
+
36
54
public function testCreatesConnectionToHttpPortAndObeysExplicitHostname ()
37
55
{
38
56
$ promise = new Promise (function () { });
39
- $ this ->connector ->expects ($ this ->once ())->method ('connect ' )->with ('proxy.example.com:80?hostname=www.google.com ' )->willReturn ($ promise );
57
+ $ this ->connector ->expects ($ this ->once ())->method ('connect ' )->with ('tcp:// proxy.example.com:80?hostname=www.google.com ' )->willReturn ($ promise );
40
58
41
59
$ proxy = new ProxyConnector ('proxy.example.com ' , $ this ->connector );
42
60
@@ -46,7 +64,7 @@ public function testCreatesConnectionToHttpPortAndObeysExplicitHostname()
46
64
public function testCreatesConnectionToHttpsPort ()
47
65
{
48
66
$ promise = new Promise (function () { });
49
- $ this ->connector ->expects ($ this ->once ())->method ('connect ' )->with ('proxy.example.com:443?hostname=google.com ' )->willReturn ($ promise );
67
+ $ this ->connector ->expects ($ this ->once ())->method ('connect ' )->with ('tls:// proxy.example.com:443?hostname=google.com ' )->willReturn ($ promise );
50
68
51
69
$ proxy = new ProxyConnector ('https://proxy.example.com ' , $ this ->connector );
52
70
@@ -80,6 +98,28 @@ public function testWillWriteToOpenConnection()
80
98
$ proxy ->connect ('google.com:80 ' );
81
99
}
82
100
101
+ public function testRejectsInvalidUri ()
102
+ {
103
+ $ this ->connector ->expects ($ this ->never ())->method ('connect ' );
104
+
105
+ $ proxy = new ProxyConnector ('proxy.example.com ' , $ this ->connector );
106
+
107
+ $ promise = $ proxy ->connect ('/// ' );
108
+
109
+ $ promise ->then (null , $ this ->expectCallableOnce ());
110
+ }
111
+
112
+ public function testRejectsUriWithNonTcpScheme ()
113
+ {
114
+ $ this ->connector ->expects ($ this ->never ())->method ('connect ' );
115
+
116
+ $ proxy = new ProxyConnector ('proxy.example.com ' , $ this ->connector );
117
+
118
+ $ promise = $ proxy ->connect ('tls://google.com:80 ' );
119
+
120
+ $ promise ->then (null , $ this ->expectCallableOnce ());
121
+ }
122
+
83
123
public function testRejectsAndClosesIfStreamWritesNonHttp ()
84
124
{
85
125
$ stream = $ this ->getMockBuilder ('React\Socket\Connection ' )->disableOriginalConstructor ()->setMethods (array ('close ' , 'write ' ))->getMock ();
0 commit comments