|
11 | 11 |
|
12 | 12 | namespace CodeIgniter\HTTP; |
13 | 13 |
|
| 14 | +use CodeIgniter\Exceptions\ConfigException; |
14 | 15 | use CodeIgniter\HTTP\Exceptions\HTTPException; |
15 | 16 | use CodeIgniter\HTTP\Files\UploadedFile; |
16 | 17 | use CodeIgniter\Test\CIUnitTestCase; |
@@ -793,5 +794,35 @@ public function testGetIPAddressThruProxyOutofSubnet() |
793 | 794 | $this->assertSame($expected, $this->request->getIPAddress()); |
794 | 795 | } |
795 | 796 |
|
| 797 | + public function testGetIPAddressThruProxyInvalidConfigString() |
| 798 | + { |
| 799 | + $this->expectException(ConfigException::class); |
| 800 | + $this->expectExceptionMessage( |
| 801 | + 'You must set an array with Proxy IP address key and HTTP header name value in Config\App::$proxyIPs.' |
| 802 | + ); |
| 803 | + |
| 804 | + $config = new App(); |
| 805 | + $config->proxyIPs = '192.168.5.0/28'; |
| 806 | + $this->request = new Request($config); |
| 807 | + $this->request->populateHeaders(); |
| 808 | + |
| 809 | + $this->request->getIPAddress(); |
| 810 | + } |
| 811 | + |
| 812 | + public function testGetIPAddressThruProxyInvalidConfigArray() |
| 813 | + { |
| 814 | + $this->expectException(ConfigException::class); |
| 815 | + $this->expectExceptionMessage( |
| 816 | + 'You must set an array with Proxy IP address key and HTTP header name value in Config\App::$proxyIPs.' |
| 817 | + ); |
| 818 | + |
| 819 | + $config = new App(); |
| 820 | + $config->proxyIPs = ['192.168.5.0/28']; |
| 821 | + $this->request = new Request($config); |
| 822 | + $this->request->populateHeaders(); |
| 823 | + |
| 824 | + $this->request->getIPAddress(); |
| 825 | + } |
| 826 | + |
796 | 827 | // @TODO getIPAddress should have more testing, to 100% code coverage |
797 | 828 | } |
0 commit comments