Skip to content

Commit 2ce46bb

Browse files
authored
Merge pull request #45 from logchange/maven_dependency_check
Added Maven Dependency Check GitLab format conversion to JUNIT
2 parents 18ad2ef + 001ea05 commit 2ce46bb

File tree

10 files changed

+1408
-10
lines changed

10 files changed

+1408
-10
lines changed

.gitpod.Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ FROM gitpod/workspace-python-3.10
22

33
USER gitpod
44

5-
RUN curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python -
5+
RUN curl -sSL https://install.python-poetry.org/ | python -
66

77
RUN poetry --version

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ Procedure:
4242
2. Convert report
4343
3. Upload converted report as junit report
4444

45+
### Report input types:
46+
You can use following report types as inputs with `ss2ju` command. (f.e `ss2ju sast ....`)
47+
- [**sast**](https://docs.gitlab.com/ee/user/application_security/sast/)
48+
- [**secrets**](https://docs.gitlab.com/ee/user/application_security/secret_detection/pipeline/)
49+
- [**container_scanning**](https://docs.gitlab.com/ee/user/application_security/container_scanning/)
50+
- [**maven_dependency_check**](https://github.com/jeremylong/DependencyCheck)
51+
4552
### Example for Secret Scanning
4653
This example can be used as is.
4754
```yaml

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ readme = "README.md"
88
homepage = "https://github.com/logchange/SecScanner2JUnit"
99
repository = "https://github.com/logchange/SecScanner2JUnit"
1010
packages = [
11-
{ include = 'secscanner2junit' },
11+
{ include = 'secscanner2junit' },
1212
]
1313

1414
[tool.poetry.dependencies]

secscanner2junit/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from secscanner2junit.config import get_config, Config
1010
from secscanner2junit.container_scanning import ContainerScanningParser
11+
from secscanner2junit.maven_dependency_check import MavenDependencyCheckParser
1112
from secscanner2junit.sast import SastParser
1213
from secscanner2junit.secrets import SecretsParser
1314

@@ -16,6 +17,8 @@ class ScanType(enum.Enum):
1617
SECRETS = 'secrets'
1718
SAST = 'sast'
1819
CS = 'container_scanning'
20+
MAVEN_DEPENDENCY_CHECK = 'maven_dependency_check'
21+
1922

2023
@staticmethod
2124
def list():
@@ -64,6 +67,8 @@ def main(args=None):
6467
parser = SastParser(report, args.input_file, ss2ju_config)
6568
elif args.activity == ScanType.CS.value:
6669
parser = ContainerScanningParser(report, args.input_file, ss2ju_config)
70+
elif args.activity == ScanType.MAVEN_DEPENDENCY_CHECK.value:
71+
parser = MavenDependencyCheckParser(report, args.input_file, ss2ju_config)
6772
else:
6873
raise NotImplementedError
6974
testsuite = parser.parse()
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from junit_xml import TestSuite, TestCase
2+
3+
from secscanner2junit.config import Config
4+
from secscanner2junit.parser import Parser
5+
from secscanner2junit.vulnerability import MavenDependencyCheckVulnerability
6+
7+
8+
# https://github.com/jeremylong/DependencyCheck
9+
class MavenDependencyCheckParser(Parser):
10+
def __init__(self, report, ts_name, config: Config):
11+
super().__init__(report, ts_name, config)
12+
self.p_type = "MavenDependencyCheck"
13+
14+
def parse_vulnerability(self, raw_vulnerability):
15+
vulnerability = MavenDependencyCheckVulnerability(raw_vulnerability)
16+
17+
tc = TestCase(name=vulnerability.get_testcase_name(),
18+
classname=self.p_type,
19+
file=vulnerability.get_location(),
20+
elapsed_sec=1)
21+
22+
tc.add_failure_info(message=vulnerability.get_description(),
23+
output=vulnerability.get_output(),
24+
failure_type=vulnerability.get_failure_type())
25+
return tc
26+
27+
def parse(self):
28+
vulnerabilities = self.report['vulnerabilities']
29+
vulnerabilities = self.config.suppress(vulnerabilities)
30+
31+
testsuites = []
32+
testcases = []
33+
34+
for raw_vulnerability in vulnerabilities:
35+
testcases.append(self.parse_vulnerability(raw_vulnerability))
36+
37+
testsuites.append(TestSuite(name=self.ts_name, test_cases=testcases))
38+
return testsuites

secscanner2junit/vulnerability.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,15 @@ def get_location(self):
120120
return self.__location.get_location()
121121

122122

123+
class MavenDependencyCheckVulnerability(_Vulnerability):
124+
def __init__(self, raw_vulnerability: dict):
125+
super().__init__(raw_vulnerability)
126+
self.__location = MavenDependencyCheckLocation(super()._parse_required_property('location'))
127+
128+
def get_location(self):
129+
return self.__location.get_location()
130+
131+
123132
class SecretsVulnerability(SastVulnerability):
124133
def __init__(self, raw_vulnerability: dict):
125134
super().__init__(raw_vulnerability)
@@ -180,6 +189,16 @@ def get_location(self):
180189
return self.__image
181190

182191

192+
class MavenDependencyCheckLocation(Location):
193+
def __init__(self, raw_location: dict):
194+
super().__init__(raw_location)
195+
self.__dependency = Dependency(super()._parse_required_property('dependency'))
196+
self.__file = super()._parse_required_property('file')
197+
198+
def get_location(self):
199+
return str(self.__dependency)
200+
201+
183202
# https://gitlab.com/gitlab-org/security-products/security-report-schemas/-/blob/master/src/security-report-format.json
184203
class Dependency(_Base):
185204
def __init__(self, raw_dependency: dict):
@@ -190,9 +209,15 @@ def __init__(self, raw_dependency: dict):
190209
self.__direct = super()._parse_simple_property('direct')
191210
# dependency_path - TODO in future ?
192211

212+
def __repr__(self):
213+
return str(self.__package) + " version: " + self.__version
214+
193215

194216
# https://gitlab.com/gitlab-org/security-products/security-report-schemas/-/blob/master/src/security-report-format.json
195217
class Package(_Base):
196218
def __init__(self, raw_package: dict):
197219
super().__init__(raw_package)
198220
self.__name = super()._parse_required_property('name')
221+
222+
def __repr__(self):
223+
return "Package: " + self.__name

0 commit comments

Comments
 (0)