@@ -65,10 +65,10 @@ public static function getExcludeData(): array
65
65
/**
66
66
* @dataProvider getExcludeData
67
67
*/
68
- public function testExclude (string $ ipAddr , $ subnets , bool $ mustThrow )
68
+ public function testExcludeByIp (string $ ipAddr , $ subnets , bool $ mustThrow )
69
69
{
70
70
$ content = 'foo ' ;
71
- $ url = sprintf ('http://%s/ ' , 0 < substr_count ($ ipAddr , ': ' ) ? sprintf ( ' [%s] ' , $ ipAddr ) : $ ipAddr );
71
+ $ url = sprintf ('http://%s/ ' , strtr ($ ipAddr , '.: ' , ' -- ' ) );
72
72
73
73
if ($ mustThrow ) {
74
74
$ this ->expectException (TransportException::class);
@@ -85,6 +85,29 @@ public function testExclude(string $ipAddr, $subnets, bool $mustThrow)
85
85
}
86
86
}
87
87
88
+ /**
89
+ * @dataProvider getExcludeData
90
+ */
91
+ public function testExcludeByHost (string $ ipAddr , $ subnets , bool $ mustThrow )
92
+ {
93
+ $ content = 'foo ' ;
94
+ $ url = sprintf ('http://%s/ ' , str_contains ($ ipAddr , ': ' ) ? sprintf ('[%s] ' , $ ipAddr ) : $ ipAddr );
95
+
96
+ if ($ mustThrow ) {
97
+ $ this ->expectException (TransportException::class);
98
+ $ this ->expectExceptionMessage (sprintf ('Host "%s" is blocked for "%s". ' , $ ipAddr , $ url ));
99
+ }
100
+
101
+ $ previousHttpClient = $ this ->getHttpClientMock ($ url , $ ipAddr , $ content );
102
+ $ client = new NoPrivateNetworkHttpClient ($ previousHttpClient , $ subnets );
103
+ $ response = $ client ->request ('GET ' , $ url );
104
+
105
+ if (!$ mustThrow ) {
106
+ $ this ->assertEquals ($ content , $ response ->getContent ());
107
+ $ this ->assertEquals (200 , $ response ->getStatusCode ());
108
+ }
109
+ }
110
+
88
111
public function testCustomOnProgressCallback ()
89
112
{
90
113
$ ipAddr = '104.26.14.6 ' ;
0 commit comments