示例#1
0
    def _test_results(self):
        reply = RawScanResultsReply()
        reply.data.items.append(self._get_scan_result())
        self.cdnskey_client.mock.return_value = [reply]

        response = self.client.get(
            reverse('webwhois:scan_results', kwargs={'handle': self.domain}))

        self.assertContains(response, 'Scan results')
        cdnskey = {
            'flags': self.flags,
            'alg': self.alg,
            'proto': 0,
            'public_key': self.public_key,
            'status': CdnskeyStatus.INSECURE_KEY
        }
        result = {
            'worker_name': self.worker,
            'scan_at': self.scan_at,
            'nameserver_ip': self.ip_address,
            'nameserver': self.nameserver,
            'cdnskey': cdnskey
        }
        self.assertEqual(response.context['scan_results'], [result])
        self.assertEqual(self.get_cdnskey_client_mock.mock_calls, [call()])
示例#2
0
    def test_no_results(self):
        reply = RawScanResultsReply()
        reply.data.items.extend([])
        self.cdnskey_client.mock.return_value = [reply]

        response = self.client.get(
            reverse('webwhois:scan_results', kwargs={'handle': self.domain}))

        self.assertContains(response, 'Scan results')
        self.assertEqual(response.context['scan_results'], [])
示例#3
0
    def _test_ignore_whois_error(self, error: CORBA.Exception) -> None:
        WHOIS.get_domain_by_handle.side_effect = error
        reply = RawScanResultsReply()
        reply.data.items.append(self._get_scan_result())
        self.cdnskey_client.mock.return_value = [reply]

        response = self.client.get(
            reverse('webwhois:scan_results', kwargs={'handle': self.domain}))

        self.assertContains(response, 'Scan results')
        self.assertTrue(response.context['scan_results'])
 def test_raw_scan_results_chunked(self):
     worker = 'kryten'
     ip_address = '256.0.0.1'
     reply_1 = RawScanResultsReply()
     reply_1.data.items.append(
         self._get_scan_result(worker, ip_address, DnskeyFlag.ZONE,
                               DnskeyAlgorithm.RSAMD5))
     reply_2 = RawScanResultsReply()
     reply_2.data.items.append(
         self._get_scan_result(worker, ip_address, DnskeyFlag.ZONE,
                               DnskeyAlgorithm.DSA))
     replies = [reply_1, reply_2]
     cdnskey_1 = {
         'flags': DnskeyFlag.ZONE,
         'alg': DnskeyAlgorithm.RSAMD5,
         'proto': 0,
         'public_key': self.public_key,
         'status': CdnskeyStatus.INSECURE_KEY
     }
     result_1 = {
         'worker_name': worker,
         'scan_at': self.scan_at,
         'nameserver_ip': ip_address,
         'nameserver': self.nameserver,
         'cdnskey': cdnskey_1
     }
     cdnskey_2 = {
         'flags': DnskeyFlag.ZONE,
         'alg': DnskeyAlgorithm.DSA,
         'proto': 0,
         'public_key': self.public_key,
         'status': CdnskeyStatus.INSECURE_KEY
     }
     result_2 = {
         'worker_name': worker,
         'scan_at': self.scan_at,
         'nameserver_ip': ip_address,
         'nameserver': self.nameserver,
         'cdnskey': cdnskey_2
     }
     self._test_raw_scan_results(replies, [result_1, result_2])
示例#5
0
    def test_ignore_idna_error(self):
        # Ignore errors in IDNA.
        reply = RawScanResultsReply()
        reply.data.items.append(self._get_scan_result())
        self.cdnskey_client.mock.return_value = [reply]

        response = self.client.get(
            reverse('webwhois:scan_results',
                    kwargs={'handle': '...example.org'}))

        self.assertContains(response, 'Scan results')
        self.assertTrue(response.context['scan_results'])
示例#6
0
    def test_results_truncated(self):
        # Test results are truncated to a time of the domain registration.
        old_scan_at = datetime(2019, 3, 1, 13, tzinfo=timezone.utc)
        reply = RawScanResultsReply()
        reply.data.items.append(self._get_scan_result(scan_at=old_scan_at))
        reply.data.items.append(self._get_scan_result())
        self.cdnskey_client.mock.return_value = [reply]

        response = self.client.get(
            reverse('webwhois:scan_results', kwargs={'handle': self.domain}))

        self.assertContains(response, 'Scan results')
        self.assertEqual(len(response.context['scan_results']), 1)
        self.assertEqual(response.context['scan_results'][0]['scan_at'],
                         self.scan_at)
示例#7
0
    def test_results_ordered(self):
        scan_at_after = datetime(2020, 3, 3, 13, tzinfo=timezone.utc)
        scan_at_before = datetime(2020, 3, 1, 13, tzinfo=timezone.utc)
        reply = RawScanResultsReply()
        reply.data.items.append(self._get_scan_result(scan_at=scan_at_after))
        reply.data.items.append(self._get_scan_result())
        reply.data.items.append(self._get_scan_result(scan_at=scan_at_before))
        self.cdnskey_client.mock.return_value = [reply]

        response = self.client.get(
            reverse('webwhois:scan_results', kwargs={'handle': self.domain}))

        self.assertContains(response, 'Scan results')
        self.assertEqual(response.context['scan_results'][0]['scan_at'],
                         scan_at_before)
        self.assertEqual(response.context['scan_results'][1]['scan_at'],
                         self.scan_at)
        self.assertEqual(response.context['scan_results'][2]['scan_at'],
                         scan_at_after)