1
- package org .dependencytrack .event .kafka .streams . processor ;
1
+ package org .dependencytrack .event .kafka .processor ;
2
2
3
- import org .apache .kafka .common .serialization .Serdes ;
4
- import org .apache .kafka .common .serialization .StringSerializer ;
5
- import org .apache .kafka .streams .StreamsBuilder ;
6
- import org .apache .kafka .streams .TestInputTopic ;
7
- import org .apache .kafka .streams .TopologyTestDriver ;
8
- import org .apache .kafka .streams .kstream .Consumed ;
9
- import org .cyclonedx .proto .v1_4 .Bom ;
10
- import org .dependencytrack .PersistenceCapableTest ;
11
- import org .dependencytrack .event .kafka .serialization .KafkaProtobufSerde ;
12
- import org .dependencytrack .event .kafka .serialization .KafkaProtobufSerializer ;
13
3
import org .dependencytrack .model .Severity ;
14
4
import org .dependencytrack .model .Vulnerability ;
15
5
import org .dependencytrack .persistence .CweImporter ;
16
- import org .dependencytrack .util .KafkaTestUtil ;
17
- import org .junit .After ;
18
6
import org .junit .Before ;
19
7
import org .junit .Test ;
20
8
21
9
import static org .assertj .core .api .Assertions .assertThat ;
10
+ import static org .dependencytrack .util .KafkaTestUtil .generateBomFromJson ;
22
11
23
- public class MirrorVulnerabilityProcessorTest extends PersistenceCapableTest {
24
-
25
- private TopologyTestDriver testDriver ;
26
- private TestInputTopic <String , Bom > inputTopic ;
12
+ public class VulnerabilityMirrorProcessorTest extends AbstractProcessorTest {
27
13
28
14
@ Before
29
- public void setUp () throws Exception {
30
- final var streamsBuilder = new StreamsBuilder ();
31
- streamsBuilder
32
- .stream ("input-topic" , Consumed
33
- .with (Serdes .String (), new KafkaProtobufSerde <>(Bom .parser ())))
34
- .process (MirrorVulnerabilityProcessor ::new );
35
-
36
- testDriver = new TopologyTestDriver (streamsBuilder .build ());
37
- inputTopic = testDriver .createInputTopic ("input-topic" ,
38
- new StringSerializer (), new KafkaProtobufSerializer <>());
15
+ public void before () throws Exception {
16
+ super .before ();
39
17
40
18
new CweImporter ().processCweDefinitions (); // Required for CWE mapping
41
19
}
42
20
43
- @ After
44
- public void tearDown () {
45
- if (testDriver != null ) {
46
- testDriver .close ();
47
- }
48
- }
49
-
50
21
@ Test
51
22
public void testProcessNvdVuln () throws Exception {
52
- inputTopic . pipeInput ( "NVD/CVE-2022-40489" , KafkaTestUtil . generateBomFromJson ( """
23
+ final var bovJson = """
53
24
{
54
25
"components": [
55
26
{
@@ -91,7 +62,10 @@ public void testProcessNvdVuln() throws Exception {
91
62
{ "url": "https://github.com/thinkcmf/thinkcmf/issues/736" }
92
63
]
93
64
}
94
- """ ));
65
+ """ ;
66
+
67
+ final var processor = new VulnerabilityMirrorProcessor ();
68
+ processor .process (aConsumerRecord ("NVD/CVE-2022-40489" , generateBomFromJson (bovJson )).build ());
95
69
96
70
final Vulnerability vuln = qm .getVulnerabilityByVulnId ("NVD" , "CVE-2022-40489" );
97
71
assertThat (vuln ).isNotNull ();
@@ -160,7 +134,7 @@ public void testProcessNvdVuln() throws Exception {
160
134
161
135
@ Test
162
136
public void testProcessGitHubVuln () throws Exception {
163
- inputTopic . pipeInput ( "GITHUB/GHSA-fxwm-579q-49qq" , KafkaTestUtil . generateBomFromJson ( """
137
+ final var bovJson = """
164
138
{
165
139
"components": [
166
140
{
@@ -223,7 +197,10 @@ public void testProcessGitHubVuln() throws Exception {
223
197
{ "url": "https://github.com/advisories/GHSA-fxwm-579q-49qq" }
224
198
]
225
199
}
226
- """ ));
200
+ """ ;
201
+
202
+ final var processor = new VulnerabilityMirrorProcessor ();
203
+ processor .process (aConsumerRecord ("GITHUB/GHSA-fxwm-579q-49qq" , generateBomFromJson (bovJson )).build ());
227
204
228
205
final Vulnerability vuln = qm .getVulnerabilityByVulnId ("GITHUB" , "GHSA-fxwm-579q-49qq" );
229
206
assertThat (vuln ).isNotNull ();
@@ -375,7 +352,7 @@ public void testProcessGitHubVuln() throws Exception {
375
352
376
353
@ Test
377
354
public void testProcessOsvVuln () throws Exception {
378
- inputTopic . pipeInput ( "OSV/GHSA-2cc5-23r7-vc4v" , KafkaTestUtil . generateBomFromJson ( """
355
+ final var bovJson = """
379
356
{
380
357
"components": [
381
358
{
@@ -427,7 +404,10 @@ public void testProcessOsvVuln() throws Exception {
427
404
{ "url": "https://github.com/ratpack/ratpack/blob/29434f7ac6fd4b36a4495429b70f4c8163100332/ratpack-session/src/main/java/ratpack/session/clientside/ClientSideSessionConfig.java#L29" }
428
405
]
429
406
}
430
- """ ));
407
+ """ ;
408
+
409
+ final var processor = new VulnerabilityMirrorProcessor ();
410
+ processor .process (aConsumerRecord ("OSV/GHSA-2cc5-23r7-vc4v" , generateBomFromJson (bovJson )).build ());
431
411
432
412
final Vulnerability vuln = qm .getVulnerabilityByVulnId ("GITHUB" , "GHSA-2cc5-23r7-vc4v" );
433
413
assertThat (vuln ).isNotNull ();
@@ -555,7 +535,7 @@ public void testProcessOsvVuln() throws Exception {
555
535
556
536
@ Test
557
537
public void testProcessVulnWithoutAffects () throws Exception {
558
- inputTopic . pipeInput ( "NVD/CVE-2022-40489" , KafkaTestUtil . generateBomFromJson ( """
538
+ final var bovJson = """
559
539
{
560
540
"components": [
561
541
{
@@ -573,7 +553,10 @@ public void testProcessVulnWithoutAffects() throws Exception {
573
553
}
574
554
]
575
555
}
576
- """ ));
556
+ """ ;
557
+
558
+ final var processor = new VulnerabilityMirrorProcessor ();
559
+ processor .process (aConsumerRecord ("NVD/CVE-2022-40489" , generateBomFromJson (bovJson )).build ());
577
560
578
561
final Vulnerability vuln = qm .getVulnerabilityByVulnId ("NVD" , "CVE-2022-40489" );
579
562
assertThat (vuln ).isNotNull ();
@@ -613,7 +596,7 @@ public void testProcessVulnWithoutAffects() throws Exception {
613
596
614
597
@ Test
615
598
public void testProcessVulnWithUnmatchedAffectsBomRef () throws Exception {
616
- inputTopic . pipeInput ( "NVD/CVE-2022-40489" , KafkaTestUtil . generateBomFromJson ( """
599
+ final var bovJson = """
617
600
{
618
601
"components": [
619
602
{
@@ -639,7 +622,10 @@ public void testProcessVulnWithUnmatchedAffectsBomRef() throws Exception {
639
622
}
640
623
]
641
624
}
642
- """ ));
625
+ """ ;
626
+
627
+ final var processor = new VulnerabilityMirrorProcessor ();
628
+ processor .process (aConsumerRecord ("NVD/CVE-2022-40489" , generateBomFromJson (bovJson )).build ());
643
629
644
630
final Vulnerability vuln = qm .getVulnerabilityByVulnId ("NVD" , "CVE-2022-40489" );
645
631
assertThat (vuln ).isNotNull ();
@@ -679,7 +665,7 @@ public void testProcessVulnWithUnmatchedAffectsBomRef() throws Exception {
679
665
680
666
@ Test
681
667
public void testProcessVulnWithVersConstraints () throws Exception {
682
- inputTopic . pipeInput ( "NVD/CVE-2022-40489" , KafkaTestUtil . generateBomFromJson ( """
668
+ final var bovJson = """
683
669
{
684
670
"components": [
685
671
{
@@ -731,7 +717,10 @@ public void testProcessVulnWithVersConstraints() throws Exception {
731
717
}
732
718
]
733
719
}
734
- """ ));
720
+ """ ;
721
+
722
+ final var processor = new VulnerabilityMirrorProcessor ();
723
+ processor .process (aConsumerRecord ("NVD/CVE-2022-40489" , generateBomFromJson (bovJson )).build ());
735
724
736
725
final Vulnerability vuln = qm .getVulnerabilityByVulnId ("NVD" , "CVE-2022-40489" );
737
726
assertThat (vuln ).isNotNull ();
@@ -935,7 +924,7 @@ public void testProcessVulnWithVersConstraints() throws Exception {
935
924
936
925
@ Test
937
926
public void testProcessVulnWithInvalidCpeOrPurl () throws Exception {
938
- inputTopic . pipeInput ( "NVD/CVE-2022-40489" , KafkaTestUtil . generateBomFromJson ( """
927
+ final var bovJson = """
939
928
{
940
929
"components": [
941
930
{
@@ -997,7 +986,10 @@ public void testProcessVulnWithInvalidCpeOrPurl() throws Exception {
997
986
}
998
987
]
999
988
}
1000
- """ ));
989
+ """ ;
990
+
991
+ final var processor = new VulnerabilityMirrorProcessor ();
992
+ processor .process (aConsumerRecord ("NVD/CVE-2022-40489" , generateBomFromJson (bovJson )).build ());
1001
993
1002
994
final Vulnerability vuln = qm .getVulnerabilityByVulnId ("NVD" , "CVE-2022-40489" );
1003
995
assertThat (vuln ).isNotNull ();
@@ -1035,4 +1027,4 @@ public void testProcessVulnWithInvalidCpeOrPurl() throws Exception {
1035
1027
assertThat (vuln .getVulnerableSoftware ()).isEmpty ();
1036
1028
}
1037
1029
1038
- }
1030
+ }
0 commit comments