|
42 | 42 | from scanpipe.models import CodebaseRelation |
43 | 43 | from scanpipe.models import CodebaseResource |
44 | 44 | from scanpipe.models import DiscoveredDependency |
| 45 | +from scanpipe.models import DiscoveredLicense |
45 | 46 | from scanpipe.models import DiscoveredPackage |
46 | 47 | from scanpipe.models import Project |
47 | 48 | from scanpipe.pipes import make_relation |
@@ -1397,6 +1398,84 @@ def test_scanpipe_views_license_details_view(self): |
1397 | 1398 | response = self.client.get(xss_url) |
1398 | 1399 | self.assertEqual(response.status_code, 404) |
1399 | 1400 |
|
| 1401 | + def test_scanpipe_views_license_detection_details_view_match_texts(self): |
| 1402 | + matches = [ |
| 1403 | + { |
| 1404 | + "score": 100.0, |
| 1405 | + "start_line": 1, |
| 1406 | + "end_line": 1, |
| 1407 | + "matched_length": 4, |
| 1408 | + "match_coverage": 100.0, |
| 1409 | + "matcher": "1-hash", |
| 1410 | + "license_expression": "mit", |
| 1411 | + "rule_identifier": "mit_1.RULE", |
| 1412 | + "rule_text": "license: MIT", |
| 1413 | + "matched_text": "License: MIT", |
| 1414 | + "matched_text_diagnostics": "License MIT", |
| 1415 | + "from_file": "LICENSE", |
| 1416 | + } |
| 1417 | + ] |
| 1418 | + license_detection = DiscoveredLicense.objects.create( |
| 1419 | + project=self.project1, |
| 1420 | + license_expression="mit", |
| 1421 | + license_expression_spdx="MIT", |
| 1422 | + identifier="mit-123", |
| 1423 | + matches=matches, |
| 1424 | + file_regions=[{"path": "LICENSE", "start_line": 1, "end_line": 1}], |
| 1425 | + ) |
| 1426 | + |
| 1427 | + url = reverse( |
| 1428 | + "license_detail", |
| 1429 | + args=[self.project1.slug, license_detection.identifier], |
| 1430 | + ) |
| 1431 | + response = self.client.get(url) |
| 1432 | + |
| 1433 | + self.assertContains(response, "Diagnostic matched text") |
| 1434 | + self.assertContains(response, "License MIT") |
| 1435 | + self.assertContains(response, "Matched text") |
| 1436 | + self.assertContains(response, "License: MIT") |
| 1437 | + self.assertContains(response, "Rule text") |
| 1438 | + self.assertContains(response, "license: MIT") |
| 1439 | + |
| 1440 | + def test_scanpipe_views_resource_details_view_inlines_detection_match_texts(self): |
| 1441 | + license_detections = [ |
| 1442 | + { |
| 1443 | + "identifier": "mit-123", |
| 1444 | + "license_expression": "mit", |
| 1445 | + "license_expression_spdx": "MIT", |
| 1446 | + "matches": [ |
| 1447 | + { |
| 1448 | + "score": 100.0, |
| 1449 | + "start_line": 1, |
| 1450 | + "end_line": 1, |
| 1451 | + "matched_length": 4, |
| 1452 | + "match_coverage": 100.0, |
| 1453 | + "matcher": "1-hash", |
| 1454 | + "license_expression": "mit", |
| 1455 | + "rule_identifier": "mit_1.RULE", |
| 1456 | + "rule_text": "license: MIT", |
| 1457 | + "matched_text": "License: MIT", |
| 1458 | + "matched_text_diagnostics": "License MIT", |
| 1459 | + } |
| 1460 | + ], |
| 1461 | + } |
| 1462 | + ] |
| 1463 | + resource = make_resource_file( |
| 1464 | + self.project1, |
| 1465 | + "LICENSE", |
| 1466 | + detected_license_expression="mit", |
| 1467 | + license_detections=license_detections, |
| 1468 | + ) |
| 1469 | + |
| 1470 | + response = self.client.get(resource.get_absolute_url()) |
| 1471 | + |
| 1472 | + self.assertContains(response, "Diagnostic matched text") |
| 1473 | + self.assertContains(response, "License MIT") |
| 1474 | + self.assertContains(response, "Matched text") |
| 1475 | + self.assertContains(response, "License: MIT") |
| 1476 | + self.assertContains(response, "Rule text") |
| 1477 | + self.assertContains(response, "license: MIT") |
| 1478 | + |
1400 | 1479 | @mock.patch("scanpipe.models.DiscoveredPackage.get_absolute_url") |
1401 | 1480 | def test_scanpipe_views_project_dependency_tree(self, mock_get_url): |
1402 | 1481 | mock_get_url.return_value = "mocked-url" |
|
0 commit comments