Exemplo n.º 1
0
 def setUp(self):
     self.client = test.Client(enforce_csrf_checks=True, REMOTE_ADDR='127.0.0.1')
     (models.ISP.objects.create(name='foo')
         .ip_set.create(
             range_from=force_ipy('127.0.0.0').int(),
             range_to=force_ipy('127.0.0.255').int()
         )
     )
     self.test_qs = {
         '0': 'tag', 
         '1': '1.0.0', 
         '2': '10480', 
         '3': '1401335782', 
         '4': md5(b'key104801401335782').hexdigest()[-8:],
         '5': '0',
         '6': '1.1',
         '7': 'test',
         '8': '1',
         '11': '14',
         '12': '16',
         '14': '5',
         '15': '160',
         '16': '160',
         '17': '900',
         '22': '6',
     }
     self.test_data = encode_post_data(self.test_qs)
Exemplo n.º 2
0
    def test_extra_whois_call_will_not_intefere_with_existing_ip_range_entry_assigned_to_different_isp(self):
        # too large ip range, extra whois call is required
        (models.ISP.objects.create(name='foo')
            .ip_set.create(
                range_from=utils.force_ipy('127.0.0.0').int(), 
                range_to=utils.force_ipy('127.255.255.255').int()
            )
        )
        (models.ISP.objects.create(name='bar')
            .ip_set.create(
                range_from=utils.force_ipy('127.0.0.0').int(), 
                range_to=utils.force_ipy('127.0.0.255').int()
            )
        )
        with patch('tracker.models.whois.whois', return_value={'ipv4range': ('127.0.0.0', '127.0.0.255')}) as mock:
            obj, created = models.ISP.objects.match_or_create('127.0.0.1')
            self.assertFalse(mock.called)
            self.assertFalse(created)
            self.assertTrue(obj.name, 'bar')

        # although an extra whois call was performed, the resolved ip range had already existed
        # and it had been assigned to a different isp
        with patch('tracker.models.ISPManager.match') as match_mock:
            with patch('tracker.models.whois.whois', return_value={'orgname': 'ham', 'ipv4range': ('127.0.0.0', '127.0.0.255')}) as whois_mock:
                match_mock.side_effect = exceptions.ObjectDoesNotExist
                obj, created = models.ISP.objects.match_or_create('127.0.0.2')
                self.assertEqual(obj.name, 'bar')
                self.assertTrue(whois_mock.called)
                self.assertFalse(created)
Exemplo n.º 3
0
 def setUp(self):
     (models.ISP.objects.create(name='foo')
         .ip_set.create(
             range_from=utils.force_ipy('127.0.0.0').int(),
             range_to=utils.force_ipy('127.0.0.255').int()
         )
     )
Exemplo n.º 4
0
 def setUp(self):
     super(UpdateProfileCase, self).setUp()
     (models.ISP.objects
         .create(name='localhost', country='un')
         .ip_set.create(range_from=utils.force_ipy('127.0.0.0').int(), range_to=utils.force_ipy('127.0.0.255').int())
     )
     self.server = models.Server.objects.create(ip='127.0.0.100', port=10480, enabled=True)
Exemplo n.º 5
0
 def setUp(self):
     super(StreamDataSavedCase, self).setUp()
     (models.ISP.objects.create(
         name='localhost', country='un').ip_set.create(
             range_from=utils.force_ipy('127.0.0.0').int(),
             range_to=utils.force_ipy('127.0.0.255').int()))
     models.Server.objects.create(ip='127.0.0.1', port=10480, enabled=True)
     self.server = models.Server.objects.first()
Exemplo n.º 6
0
 def setUp(self):
     super(WhoisApiTestCase, self).setUp()
     (models.ISP.objects
         .create(name='localhost', country='un')
         .ip_set.create(range_from=utils.force_ipy('127.0.0.0').int(), range_to=utils.force_ipy('127.0.0.255').int())
     )
     self.server = models.Server.objects.create(ip='127.0.0.1', port=10480, enabled=True, streamed=True)
     models.Game.objects.create(server=self.server)
Exemplo n.º 7
0
 def test_match_or_create_will_not_add_same_ip_range(self):
     (models.ISP.objects.create(name='foo')
         .ip_set.create(
             range_from=utils.force_ipy('127.0.0.0').int(), 
             range_to=utils.force_ipy('127.255.255.255').int()
         )
     )
     with patch('tracker.models.ISPManager.match') as match_mock:
         with patch('tracker.models.whois.whois', return_value={'orgname': 'foo', 'ipv4range': ('127.0.0.0', '127.255.255.255')}) as whois_mock:
             match_mock.side_effect = exceptions.ObjectDoesNotExist
             obj, created = models.ISP.objects.match_or_create('127.0.0.1')
             self.assertEqual(obj.name, 'foo')
             self.assertFalse(created)
             self.assertEqual(obj.ip_set.count(), 1)
             self.assertEqual(models.IP.objects.count(), 1)
Exemplo n.º 8
0
 def test_extra_whois_call_returns_same_ip_range(self):
     (models.ISP.objects.create(name='foo')
         .ip_set.create(
             range_from=utils.force_ipy('127.0.0.0').int(), 
             range_to=utils.force_ipy('127.255.255.255').int()
         )
     )
     # ip range is too large
     with patch('tracker.models.whois.whois', return_value={'orgname': 'foo', 'ipv4range': ('127.0.0.0', '127.255.255.255')}) as mock:
         obj, created = models.ISP.objects.match_or_create('127.0.0.1')
         self.assertTrue(mock.called)
         self.assertFalse(created)
     # same ip range, but different orgname
     with patch('tracker.models.whois.whois', return_value={'orgname': 'bar', 'ipv4range': ('127.0.0.0', '127.255.255.255')}) as mock:
         obj, created = models.ISP.objects.match_or_create('127.0.0.2')
         self.assertTrue(mock.called)
         self.assertFalse(created)
Exemplo n.º 9
0
    def test_match_will_prefer_the_smallest_possible_ip_range(self):
        (models.ISP.objects.create(name='foo')
            .ip_set.create(
                range_from=utils.force_ipy('127.0.0.0').int(), 
                range_to=utils.force_ipy('127.255.255.255').int()
            )
        )
        (models.ISP.objects.create(name='bar')
            .ip_set.create(
                range_from=utils.force_ipy('127.0.0.0').int(), 
                range_to=utils.force_ipy('127.0.255.255').int()
            )
        )
        (models.ISP.objects.create(name='baz')
            .ip_set.create(
                range_from=utils.force_ipy('127.0.0.0').int(), 
                range_to=utils.force_ipy('127.0.0.255').int()
            )
        )
        (models.ISP.objects.create(name='ham')
            .ip_set.create(
                range_from=utils.force_ipy('127.0.0.0').int(), 
                range_to=utils.force_ipy('127.0.0.1').int()
            )
        )
        (models.ISP.objects.create(name='spam')
            .ip_set.create(
                range_from=utils.force_ipy('127.0.0.1').int(), 
                range_to=utils.force_ipy('127.0.0.1').int()
            )
        )

        with patch('tracker.models.whois.whois') as mock:
            self.assertEqual(models.ISP.objects.match('127.0.0.1')[0].name, 'spam')
            self.assertEqual(models.ISP.objects.match('127.0.0.2')[0].name, 'baz')
            self.assertEqual(models.ISP.objects.match('127.0.0.0')[0].name, 'ham')
            self.assertEqual(models.ISP.objects.match('127.0.244.15')[0].name, 'bar')
            self.assertEqual(models.ISP.objects.match('127.12.244.15')[0].name, 'foo')
            self.assertEqual(models.ISP.objects.match('127.255.255.255')[0].name, 'foo')
            
            self.assertFalse(mock.called)
Exemplo n.º 10
0
    def test_too_large_ip_range_will_cause_an_extra_whois_call(self):
        (models.ISP.objects.create(name='foo')
            .ip_set.create(
                range_from=utils.force_ipy('127.0.0.0').int(), 
                range_to=utils.force_ipy('127.255.255.255').int()
            )
        )
        with patch('tracker.models.whois.whois', return_value={'orgname': 'foo', 'ipv4range': ('127.0.0.0', '127.255.255.255')}) as mock:
            obj, created = models.ISP.objects.match_or_create('127.0.0.1')
            self.assertTrue(mock.called)
            self.assertFalse(created)
            self.assertTrue(obj.name, 'foo')
            # the returned ip range is same
            self.assertEqual(models.IP.objects.count(), 1)

        with patch('tracker.models.whois.whois', return_value={'orgname': 'foo', 'ipv4range': ('127.0.0.0', '127.0.255.255')}) as mock:
            obj, created = models.ISP.objects.match_or_create('127.0.0.2')
            self.assertTrue(mock.called)
            self.assertFalse(created)
            self.assertTrue(obj.name, 'foo')
            # the returned ip range is different
            self.assertEqual(models.IP.objects.count(), 2)
Exemplo n.º 11
0
    def test_extra_whois_call_will_prevent_further_whois_lookups_if_the_range_length_is_okay(self):
        # too large ip range, extra whois call is required
        (models.ISP.objects.create(name='foo')
            .ip_set.create(
                range_from=utils.force_ipy('127.0.0.0').int(), 
                range_to=utils.force_ipy('127.255.255.255').int()
            )
        )
        with patch('tracker.models.whois.whois', return_value={'orgname': 'foo', 'ipv4range': ('127.0.0.0', '127.0.0.255')}) as mock:
            obj, created = models.ISP.objects.match_or_create('127.0.0.1')
            self.assertTrue(mock.called)
            self.assertFalse(created)

        with patch('tracker.models.whois.whois', return_value={'orgname': 'foo', 'ipv4range': ('127.0.0.0', '127.0.0.255')}) as mock:
            obj, created = models.ISP.objects.match_or_create('127.0.0.2')
            self.assertFalse(mock.called)
            self.assertFalse(created)

        with patch('tracker.models.whois.whois', return_value={'orgname': 'foo', 'ipv4range': ('127.0.0.0', '127.0.0.255')}) as mock:
            obj, created = models.ISP.objects.match_or_create('127.0.0.128')
            self.assertFalse(mock.called)
            self.assertFalse(created)

        self.assertEqual(models.IP.objects.count(), 2)
Exemplo n.º 12
0
 def setUp(self):
     (models.ISP.objects.create(name='foo', country='zz').ip_set.create(
         range_from=utils.force_ipy('127.0.0.0').int(),
         range_to=utils.force_ipy('127.0.0.255').int()))