| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace PragmaRX\Firewall\Tests; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use PragmaRX\Firewall\Vendor\Laravel\Facade as Firewall; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 6 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 7 |  |  | class GeoIpTest extends TestCase | 
            
                                                        
            
                                    
            
            
                | 8 |  |  | { | 
            
                                                        
            
                                    
            
            
                | 9 |  |  |     public function setUp() | 
            
                                                        
            
                                    
            
            
                | 10 |  |  |     { | 
            
                                                        
            
                                    
            
            
                | 11 |  |  |         parent::setUp(); | 
            
                                                        
            
                                    
            
            
                | 12 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 13 |  |  |         Firewall::updateGeoIp(); | 
            
                                                        
            
                                    
            
            
                | 14 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 15 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 16 |  |  |     public function test_get_country() | 
            
                                                        
            
                                    
            
            
                | 17 |  |  |     { | 
            
                                                        
            
                                    
            
            
                | 18 |  |  |         $this->assertEquals('us', Firewall::getCountryFromIp('8.8.8.8')); | 
            
                                                        
            
                                    
            
            
                | 19 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 20 |  |  |         $this->assertEquals('br', Firewall::getCountryFromIp('200.222.0.24')); | 
            
                                                        
            
                                    
            
            
                | 21 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 22 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 23 |  |  |     public function test_block_per_country() | 
            
                                                        
            
                                    
            
            
                | 24 |  |  |     { | 
            
                                                        
            
                                    
            
            
                | 25 |  |  |         Firewall::blacklist('country:us'); | 
            
                                                        
            
                                    
            
            
                | 26 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 27 |  |  |         $this->assertTrue(Firewall::isBlacklisted('8.8.8.8')); | 
            
                                                        
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 29 |  |  |         $this->assertFalse(Firewall::isWhitelisted('8.8.8.8')); | 
            
                                                        
            
                                    
            
            
                | 30 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 32 |  |  |     public function test_make_country() | 
            
                                                        
            
                                    
            
            
                | 33 |  |  |     { | 
            
                                                        
            
                                    
            
            
                | 34 |  |  |         $this->assertEquals('country:br', Firewall::makeCountryFromString('br')); | 
            
                                                        
            
                                    
            
            
                | 35 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 36 |  |  |         $this->assertEquals('country:br', Firewall::makeCountryFromString('country:br')); | 
            
                                                        
            
                                    
            
            
                | 37 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 38 |  |  |         $this->assertEquals('country:br', Firewall::makeCountryFromString('200.222.0.21')); | 
            
                                                        
            
                                    
            
            
                | 39 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 41 |  |  |     public function test_country_ip_listing() | 
            
                                                        
            
                                    
            
            
                | 42 |  |  |     { | 
            
                                                        
            
                                    
            
            
                | 43 |  |  |         Firewall::blacklist('8.8.8.7'); | 
            
                                                        
            
                                    
            
            
                | 44 |  |  |         Firewall::blacklist('8.8.8.8'); | 
            
                                                        
            
                                    
            
            
                | 45 |  |  |         Firewall::blacklist('8.8.8.9'); | 
            
                                                        
            
                                    
            
            
                | 46 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 47 |  |  |         Firewall::blacklist('200.222.0.21'); | 
            
                                                        
            
                                    
            
            
                | 48 |  |  |         Firewall::blacklist('200.222.0.22'); | 
            
                                                        
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 50 |  |  |         $this->assertCount(2, Firewall::allByCountry('br')); | 
            
                                                        
            
                                    
            
            
                | 51 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 52 |  |  |         $this->assertCount(3, Firewall::allByCountry('us')); | 
            
                                                        
            
                                    
            
            
                | 53 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 55 |  |  |     public function test_country_is_valid() | 
            
                                                        
            
                                    
            
            
                | 56 |  |  |     { | 
            
                                                        
            
                                    
            
            
                | 57 |  |  |         $this->assertTrue(Firewall::validCountry('country:us')); | 
            
                                                        
            
                                    
            
            
                | 58 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 59 |  |  |         $this->assertTrue(Firewall::validCountry('country:br')); | 
            
                                                        
            
                                    
            
            
                | 60 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 61 |  |  |         $this->assertFalse(Firewall::validCountry('country:xx')); | 
            
                                                        
            
                                    
            
            
                | 62 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 63 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 64 |  |  |  |