コード例 #1
0
    def test_check_networks_both(self, gethostbyname_ex):
        allowed_networks = ['15/8', '74.125/16']
        gethostbyname_ex.return_value = (
            'example.com',
            [],
            [
                '74.125.224.64',
                '74.125.224.67',
                '74.125.224.68',
                '74.125.224.70',
            ]
        )
        self.assertTrue(validators.check_networks(
            'example.com', allowed_networks))
        self.assertTrue(validators.check_networks_strict(
            'example.com', allowed_networks))

        gethostbyname_ex.return_value = ('example.com', [], ['12.2.2.2'])
        self.assertFalse(validators.check_networks(
            'example.com', allowed_networks))

        gethostbyname_ex.return_value = (
            'example.com',
            [],
            [
                '15.8.2.2',
                '15.8.2.1',
                '16.1.1.1',
            ]
        )
        self.assertFalse(validators.check_networks_strict(
            'example.com', allowed_networks))
コード例 #2
0
    def test_check_networks_both(self, gethostbyname_ex):
        allowed_networks = ['15/8', '74.125/16']
        gethostbyname_ex.return_value = (
            'example.com',
            [],
            [
                '74.125.224.64',
                '74.125.224.67',
                '74.125.224.68',
                '74.125.224.70',
            ]
        )
        self.assertTrue(validators.check_networks(
            'example.com', allowed_networks))
        self.assertTrue(validators.check_networks_strict(
            'example.com', allowed_networks))

        gethostbyname_ex.return_value = ('example.com', [], ['12.2.2.2'])
        self.assertFalse(validators.check_networks(
            'example.com', allowed_networks))

        gethostbyname_ex.return_value = (
            'example.com',
            [],
            [
                '15.8.2.2',
                '15.8.2.1',
                '16.1.1.1',
            ]
        )
        self.assertFalse(validators.check_networks_strict(
            'example.com', allowed_networks))
コード例 #3
0
 def test_check_networks_passthrough(self):
     good_ip = netaddr.IPAddress('10.2.3.4')
     self.assertTrue(validators.check_networks(good_ip, []))
コード例 #4
0
 def test_check_networks_invalid(self):
     with self.assertRaises(TypeError):
         validators.check_networks('1.2.3.4', ['10/8'])
コード例 #5
0
 def test_check_networks(self):
     good_ip = netaddr.IPAddress('10.2.3.4')
     bad_ip = netaddr.IPAddress('88.2.3.4')
     test_allowed = ['10/8']
     self.assertTrue(validators.check_networks(good_ip, test_allowed))
     self.assertFalse(validators.check_networks(bad_ip, test_allowed))
コード例 #6
0
 def test_check_networks_bad_domain(self):
     bad_domain = 'bad!$domain'
     allowed_networks = ['127/8', '10/8']
     self.assertFalse(validators.check_networks(
         bad_domain, allowed_networks))
コード例 #7
0
 def test_check_networks_exception(self, gethostbyname_ex):
     gethostbyname_ex.side_effect = socket.gaierror()
     self.assertFalse(
         validators.check_networks('mock', ['mock']),
     )
コード例 #8
0
 def test_check_networks_bad(self):
     allowed_networks = ['15/8', '74.125/16']
     self.assertFalse(validators.check_networks(
         netaddr.IPAddress('12.2.2.2'), allowed_networks))
コード例 #9
0
 def test_check_networks_good(self):
     allowed_networks = ['15/8', '74.125/16']
     self.assertTrue(validators.check_networks(
         netaddr.IPAddress('74.125.224.64'), allowed_networks))
コード例 #10
0
 def test_check_networks_bad(self):
     allowed_networks = ['15/8', '74.125/16']
     self.assertFalse(
         validators.check_networks(netaddr.IPAddress('12.2.2.2'),
                                   allowed_networks))
コード例 #11
0
 def test_check_networks_good(self):
     allowed_networks = ['15/8', '74.125/16']
     self.assertTrue(
         validators.check_networks(netaddr.IPAddress('74.125.224.64'),
                                   allowed_networks))
コード例 #12
0
 def test_check_networks_exception(self, gethostbyname_ex):
     gethostbyname_ex.side_effect = socket.gaierror()
     self.assertFalse(
         validators.check_networks('mock', ['mock']),
     )
コード例 #13
0
 def test_check_networks_bad_domain(self, gethostbyname_ex):
     gethostbyname_ex.side_effect = socket.gaierror()
     bad_domain = 'bad!$domain'
     allowed_networks = ['127/8', '10/8']
     self.assertFalse(validators.check_networks(
         bad_domain, allowed_networks))