Skip to content

Commit

Permalink
created epss processor convert test
Browse files Browse the repository at this point in the history
  • Loading branch information
sahibamittal committed Mar 25, 2024
1 parent 1472313 commit a1fdf30
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* SPDX-License-Identifier: Apache-2.0
* Copyright (c) OWASP Foundation. All Rights Reserved.
*/
package org.dependencytrack.event.kafka.streams.processor;
package org.dependencytrack.event.kafka.processor;

import alpine.common.logging.Logger;
import org.apache.kafka.clients.consumer.ConsumerRecord;
Expand All @@ -27,10 +27,10 @@
import org.dependencytrack.proto.mirror.v1.EpssItem;


public class MirrorEpssProcessor implements Processor<String, EpssItem> {
public class EpssMirrorProcessor implements Processor<String, EpssItem> {

public static final String PROCESSOR_NAME = "vuln.mirror";
private static final Logger LOGGER = Logger.getLogger(MirrorEpssProcessor.class);
private static final Logger LOGGER = Logger.getLogger(EpssMirrorProcessor.class);

@Override
public void process(ConsumerRecord<String, EpssItem> record) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import alpine.common.logging.Logger;
import org.dependencytrack.event.kafka.KafkaTopics;
import org.dependencytrack.event.kafka.processor.api.ProcessorManager;
import org.dependencytrack.event.kafka.streams.processor.MirrorEpssProcessor;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
Expand All @@ -39,8 +38,8 @@ public void contextInitialized(final ServletContextEvent event) {
PROCESSOR_MANAGER.registerProcessor(VulnerabilityMirrorProcessor.PROCESSOR_NAME,
KafkaTopics.NEW_VULNERABILITY, new VulnerabilityMirrorProcessor());

PROCESSOR_MANAGER.registerProcessor(MirrorEpssProcessor.PROCESSOR_NAME,
KafkaTopics.VULNERABILITY_MIRROR_EPSS, new MirrorEpssProcessor());
PROCESSOR_MANAGER.registerProcessor(EpssMirrorProcessor.PROCESSOR_NAME,
KafkaTopics.VULNERABILITY_MIRROR_EPSS, new EpssMirrorProcessor());

PROCESSOR_MANAGER.startAll();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@
*/
package org.dependencytrack.event.kafka.processor;

import org.dependencytrack.event.kafka.streams.processor.MirrorEpssProcessor;
import org.dependencytrack.proto.mirror.v1.EpssItem;
import org.junit.Before;
import org.junit.Test;

import static org.assertj.core.api.Assertions.assertThat;

public class MirrorEpssProcessorTest extends AbstractProcessorTest {
public class EpssMirrorProcessorTest extends AbstractProcessorTest {

@Before
public void before() throws Exception {
Expand All @@ -36,7 +35,7 @@ public void before() throws Exception {
public void testProcessEpssRecord() {
final var epssRecord = EpssItem.newBuilder()
.setCve("CVE-333").setEpss(2.3).setPercentile(5.6).build();
final var processor = new MirrorEpssProcessor();
final var processor = new EpssMirrorProcessor();
processor.process(aConsumerRecord("CVE-333", epssRecord).build());
final var epss = qm.getEpssByCveId("CVE-333");
assertThat(epss).isNotNull();
Expand All @@ -46,7 +45,7 @@ public void testProcessEpssRecord() {

@Test
public void testProcessEpssRecordd() {
final var processor = new MirrorEpssProcessor();
final var processor = new EpssMirrorProcessor();
processor.process(aConsumerRecord("CVE-333", EpssItem.newBuilder().build()).build());
final var epss = qm.getEpssByCveId("CVE-333");
assertThat(epss).isNull();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* This file is part of Dependency-Track.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
* Copyright (c) OWASP Foundation. All Rights Reserved.
*/
package org.dependencytrack.parser.dependencytrack;

import org.dependencytrack.PersistenceCapableTest;
import org.dependencytrack.model.Epss;
import org.dependencytrack.proto.mirror.v1.EpssItem;
import org.junit.Test;

import static org.assertj.core.api.Assertions.assertThat;

public class EpssModelConverterTest extends PersistenceCapableTest {

@Test
public void testConvert() {
final var epssItemInput = EpssItem.newBuilder().setCve("CVE-111")
.setEpss(2.2).setPercentile(3.3).build();
final Epss epssConverted = EpssModelConverter.convert(epssItemInput);
assertThat(epssConverted.getCve()).isEqualTo("CVE-111");
assertThat(epssConverted.getEpss()).isEqualByComparingTo("2.2");
assertThat(epssConverted.getPercentile()).isEqualByComparingTo("3.3");
}
}

0 comments on commit a1fdf30

Please sign in to comment.