11import re
22
3- import pytest
4- from socketsecurity .core .messages import Messages
53from socketsecurity .core .classes import Diff , Issue
4+ from socketsecurity .core .messages import Messages
65
76
87class TestGitLabFormat :
@@ -87,7 +86,10 @@ def test_identifier_extraction_with_cve(self):
8786 type = "vulnerability" ,
8887 severity = "critical" ,
8988 title = "Known CVE" ,
90- props = {"cve" : ["CVE-2024-5678" , "CVE-2024-9012" ]},
89+ props = {
90+ "cveId" : ["CVE-2024-5678" , "CVE-2024-9012" ],
91+ "ghsaId" : "GHSA-1234-5678-9012" ,
92+ },
9193 pkg_type = "npm" ,
9294 key = "test-key" ,
9395 purl = "pkg:npm/vulnerable-pkg@2.0.0"
@@ -97,15 +99,17 @@ def test_identifier_extraction_with_cve(self):
9799 report = Messages .create_security_comment_gitlab (diff )
98100 vuln = report ["vulnerabilities" ][0 ]
99101
100- # Should have socket_alert identifier + 2 CVE identifiers
101- assert len (vuln ["identifiers" ]) >= 3
102+ # Should have socket_alert identifier + CVE and GHSA identifiers
103+ assert len (vuln ["identifiers" ]) == 4
102104 cve_identifiers = [i for i in vuln ["identifiers" ] if i ["type" ] == "cve" ]
103105 assert len (cve_identifiers ) == 2
104106 assert any (i ["value" ] == "CVE-2024-5678" for i in cve_identifiers )
105107 assert any (i ["value" ] == "CVE-2024-9012" for i in cve_identifiers )
108+ ghsa_identifiers = [i for i in vuln ["identifiers" ] if i ["type" ] == "ghsa" ]
109+ assert ghsa_identifiers [0 ]["value" ] == "GHSA-1234-5678-9012"
106110
107111 def test_identifier_extraction_with_single_cve_string (self ):
108- """Test single CVE identifier as string """
112+ """Legacy CVE property remains supported """
109113 diff = Diff ()
110114 diff .id = "test-scan-id"
111115 diff .diff_url = "https://socket.dev/test"
@@ -130,6 +134,23 @@ def test_identifier_extraction_with_single_cve_string(self):
130134 assert len (cve_identifiers ) == 1
131135 assert cve_identifiers [0 ]["value" ] == "CVE-2024-1111"
132136
137+ def test_identifier_extraction_deduplicates_legacy_and_current_cve_fields (self ):
138+ issue = Issue (
139+ pkg_name = "vulnerable-pkg" ,
140+ pkg_version = "2.0.0" ,
141+ type = "vulnerability" ,
142+ severity = "high" ,
143+ title = "Duplicate CVE" ,
144+ props = {"cve" : "CVE-2024-1111" , "cveId" : "CVE-2024-1111" },
145+ pkg_type = "npm" ,
146+ key = "test-key" ,
147+ purl = "pkg:npm/vulnerable-pkg@2.0.0" ,
148+ )
149+
150+ identifiers = Messages .extract_identifiers_gitlab (issue )
151+
152+ assert [item ["value" ] for item in identifiers ].count ("CVE-2024-1111" ) == 1
153+
133154 def test_dependency_chain_handling_transitive (self ):
134155 """Test transitive dependency path is captured"""
135156 diff = Diff ()
0 commit comments