예제 #1
0
 def test_task_download_and_scan_with_non_valid_uri(self):
     scan1 = Scan.objects.create(uri="thisisnotaproperuri")
     download_and_scan(scan1.pk)
     scan1.refresh_from_db()
     expected = ("Invalid URL 'thisisnotaproperuri': No schema supplied. "
                 "Perhaps you meant http://thisisnotaproperuri?")
     self.assertIn(expected, scan1.task_output)
예제 #2
0
    def test_download_and_scan_proper(self, mock_get):
        url = "https://localhost/filename.zip"
        mock_get.return_value = mock.Mock(content=b"\x00",
                                          headers={},
                                          status_code=200,
                                          url=url)
        scan1 = Scan.objects.create(uri=url)
        download_and_scan(scan1.pk)
        scan1.refresh_from_db()
        self.assertEqual(36, len(str(scan1.task_id)))
        self.assertEqual(0, scan1.task_exitcode)
        self.assertIn("Extracting archives...", scan1.task_output)
        self.assertIn("Extracting done.", scan1.task_output)
        self.assertIn("Scanning done.", scan1.task_output)
        self.assertTrue(scan1.task_start_date)
        self.assertTrue(scan1.task_end_date)
        self.assertEqual(scancode_version, scan1.scancode_version)
        self.assertEqual("filename.zip", scan1.filename)
        self.assertEqual("5ba93c9db0cff93f52b521d7420e43f6eda2784f",
                         scan1.sha1)
        self.assertEqual("93b885adfe0da089cdf634904fd59f71", scan1.md5)
        self.assertEqual(1, scan1.size)

        summary_expected_keys = [
            "authors",
            "holders",
            "packages",
            "key_files",
            "copyrights",
            "license_matches",
            "license_expressions",
            "programming_language",
            "license_clarity_score",
        ]
        self.assertEqual(summary_expected_keys, list(scan1.summary.keys()))
예제 #3
0
 def test_task_download_and_scan_with_fake_uri(self):
     scan1 = Scan.objects.create(uri="http://thisdoesnotexists.com")
     download_and_scan(scan1.pk)
     scan1.refresh_from_db()
     expected = "HTTPConnectionPool(host='thisdoesnotexists.com', port=80)"
     self.assertIn(expected, scan1.task_output)
예제 #4
0
 def test_download_and_scan_with_404_uri(self, mock_get):
     mock_get.return_value = mock.Mock(status_code=404)
     scan1 = Scan.objects.create(uri="http://www.nexb.com/not_existing.jar")
     download_and_scan(scan1.pk)
     scan1.refresh_from_db()
     self.assertEqual("Not found", scan1.task_output)