Skip to content
Snippets Groups Projects
Commit 36f3443e authored by Zachary Sabourin's avatar Zachary Sabourin Committed by Martin Lowe
Browse files

fix: Fix issue deserializing GH CVE object

parent cf2421b4
No related branches found
No related tags found
1 merge request!27fix: Fix issue deserializing GH CVE object
...@@ -66,7 +66,7 @@ public abstract class CveProjectData { ...@@ -66,7 +66,7 @@ public abstract class CveProjectData {
@AutoValue @AutoValue
@JsonDeserialize(builder = AutoValue_CveProjectData_Impact.Builder.class) @JsonDeserialize(builder = AutoValue_CveProjectData_Impact.Builder.class)
public abstract static class Impact { public abstract static class Impact {
public abstract ImpactScore getCvss(); public abstract List<Cvss> getCvss();
public static Builder builder() { public static Builder builder() {
return new AutoValue_CveProjectData_Impact.Builder(); return new AutoValue_CveProjectData_Impact.Builder();
...@@ -75,14 +75,14 @@ public abstract class CveProjectData { ...@@ -75,14 +75,14 @@ public abstract class CveProjectData {
@AutoValue.Builder @AutoValue.Builder
@JsonPOJOBuilder(withPrefix = "set") @JsonPOJOBuilder(withPrefix = "set")
public abstract static class Builder { public abstract static class Builder {
public abstract Builder setCvss(ImpactScore cvss); public abstract Builder setCvss(List<Cvss> cvss);
public abstract Impact build(); public abstract Impact build();
} }
} }
@AutoValue @AutoValue
@JsonDeserialize(builder = AutoValue_CveProjectData_ImpactScore.Builder.class) @JsonDeserialize(builder = AutoValue_CveProjectData_Cvss.Builder.class)
public abstract static class ImpactScore { public abstract static class Cvss {
@Nullable @Nullable
public abstract Double getBaseScore(); public abstract Double getBaseScore();
@Nullable @Nullable
...@@ -90,16 +90,18 @@ public abstract class CveProjectData { ...@@ -90,16 +90,18 @@ public abstract class CveProjectData {
public abstract String getVersion(); public abstract String getVersion();
public static Builder builder() { public static Builder builder() {
return new AutoValue_CveProjectData_ImpactScore.Builder(); return new AutoValue_CveProjectData_Cvss.Builder();
} }
@AutoValue.Builder @AutoValue.Builder
@JsonPOJOBuilder(withPrefix = "set") @JsonPOJOBuilder(withPrefix = "set")
public abstract static class Builder { public abstract static class Builder {
@JsonProperty("baseScore")
public abstract Builder setBaseScore(@Nullable Double baseScore); public abstract Builder setBaseScore(@Nullable Double baseScore);
@JsonProperty("vectorString")
public abstract Builder setVectorString(@Nullable String vectorString); public abstract Builder setVectorString(@Nullable String vectorString);
public abstract Builder setVersion(String version); public abstract Builder setVersion(String version);
public abstract ImpactScore build(); public abstract Cvss build();
} }
} }
......
...@@ -115,8 +115,8 @@ public interface CveService extends StartupProxy { ...@@ -115,8 +115,8 @@ public interface CveService extends StartupProxy {
.findFirst() .findFirst()
.orElse(LocalizedValue.builder().setLang("en").setValue("").build()) .orElse(LocalizedValue.builder().setLang("en").setValue("").build())
.getValue()) .getValue())
.setCvss(cveDetails.getImpact().isPresent() .setCvss(cveDetails.getImpact().isPresent() && !cveDetails.getImpact().get().getCvss().isEmpty()
? cveDetails.getImpact().get().getCvss().getBaseScore() ? cveDetails.getImpact().get().getCvss().get(0).getBaseScore()
: null) : null)
.build(); .build();
} }
......
...@@ -19,9 +19,9 @@ import java.util.Optional; ...@@ -19,9 +19,9 @@ import java.util.Optional;
import org.eclipsefoundation.cve.model.CveData; import org.eclipsefoundation.cve.model.CveData;
import org.eclipsefoundation.cve.model.CveProjectData; import org.eclipsefoundation.cve.model.CveProjectData;
import org.eclipsefoundation.cve.model.CveProjectData.Cvss;
import org.eclipsefoundation.cve.model.CveProjectData.Description; import org.eclipsefoundation.cve.model.CveProjectData.Description;
import org.eclipsefoundation.cve.model.CveProjectData.Impact; import org.eclipsefoundation.cve.model.CveProjectData.Impact;
import org.eclipsefoundation.cve.model.CveProjectData.ImpactScore;
import org.eclipsefoundation.cve.model.CveProjectData.LocalizedValue; import org.eclipsefoundation.cve.model.CveProjectData.LocalizedValue;
import org.eclipsefoundation.cve.model.CveProjectData.MetaData; import org.eclipsefoundation.cve.model.CveProjectData.MetaData;
import org.eclipsefoundation.cve.service.CveService; import org.eclipsefoundation.cve.service.CveService;
...@@ -72,10 +72,10 @@ public class StubbedCveService implements CveService { ...@@ -72,10 +72,10 @@ public class StubbedCveService implements CveService {
.setid("CVE-2020-27225") .setid("CVE-2020-27225")
.build()) .build())
.setImpact(Optional.of(Impact.builder() .setImpact(Optional.of(Impact.builder()
.setCvss(ImpactScore.builder() .setCvss(Arrays.asList(Cvss.builder()
.setVersion("someVersion") .setVersion("someVersion")
.setBaseScore(4.2) .setBaseScore(4.2)
.build()) .build()))
.build())) .build()))
.setDescription(Description.builder() .setDescription(Description.builder()
.setDescriptionData(Arrays.asList( .setDescriptionData(Arrays.asList(
...@@ -90,10 +90,10 @@ public class StubbedCveService implements CveService { ...@@ -90,10 +90,10 @@ public class StubbedCveService implements CveService {
.setid("CVE-2022-0103") .setid("CVE-2022-0103")
.build()) .build())
.setImpact(Optional.of(Impact.builder() .setImpact(Optional.of(Impact.builder()
.setCvss(ImpactScore.builder() .setCvss(Arrays.asList(Cvss.builder()
.setVersion("someVersion") .setVersion("someVersion")
.setBaseScore(9.0) .setBaseScore(9.0)
.build()) .build()))
.build())) .build()))
.setDescription(Description.builder() .setDescription(Description.builder()
.setDescriptionData(Arrays.asList( .setDescriptionData(Arrays.asList(
......
...@@ -23,9 +23,9 @@ import org.eclipse.microprofile.rest.client.inject.RestClient; ...@@ -23,9 +23,9 @@ import org.eclipse.microprofile.rest.client.inject.RestClient;
import org.eclipsefoundation.cve.api.GithubCveAPI; import org.eclipsefoundation.cve.api.GithubCveAPI;
import org.eclipsefoundation.cve.api.models.GithubRequestParams; import org.eclipsefoundation.cve.api.models.GithubRequestParams;
import org.eclipsefoundation.cve.model.CveProjectData; import org.eclipsefoundation.cve.model.CveProjectData;
import org.eclipsefoundation.cve.model.CveProjectData.Cvss;
import org.eclipsefoundation.cve.model.CveProjectData.Description; import org.eclipsefoundation.cve.model.CveProjectData.Description;
import org.eclipsefoundation.cve.model.CveProjectData.Impact; import org.eclipsefoundation.cve.model.CveProjectData.Impact;
import org.eclipsefoundation.cve.model.CveProjectData.ImpactScore;
import org.eclipsefoundation.cve.model.CveProjectData.LocalizedValue; import org.eclipsefoundation.cve.model.CveProjectData.LocalizedValue;
import org.eclipsefoundation.cve.model.CveProjectData.MetaData; import org.eclipsefoundation.cve.model.CveProjectData.MetaData;
...@@ -49,10 +49,10 @@ public class StubbedGithubCveAPI implements GithubCveAPI { ...@@ -49,10 +49,10 @@ public class StubbedGithubCveAPI implements GithubCveAPI {
.setid("CVE-2020-27225") .setid("CVE-2020-27225")
.build()) .build())
.setImpact(Optional.of(Impact.builder() .setImpact(Optional.of(Impact.builder()
.setCvss(ImpactScore.builder() .setCvss(Arrays.asList(Cvss.builder()
.setVersion("someVersion") .setVersion("someVersion")
.setBaseScore(4.2) .setBaseScore(4.2)
.build()) .build()))
.build())) .build()))
.setDescription(Description.builder() .setDescription(Description.builder()
.setDescriptionData(Arrays.asList( .setDescriptionData(Arrays.asList(
...@@ -67,10 +67,10 @@ public class StubbedGithubCveAPI implements GithubCveAPI { ...@@ -67,10 +67,10 @@ public class StubbedGithubCveAPI implements GithubCveAPI {
.setid("CVE-2022-0103") .setid("CVE-2022-0103")
.build()) .build())
.setImpact(Optional.of(Impact.builder() .setImpact(Optional.of(Impact.builder()
.setCvss(ImpactScore.builder() .setCvss(Arrays.asList(Cvss.builder()
.setVersion("someVersion") .setVersion("someVersion")
.setBaseScore(9.0) .setBaseScore(9.0)
.build()) .build()))
.build())) .build()))
.setDescription(Description.builder() .setDescription(Description.builder()
.setDescriptionData(Arrays.asList( .setDescriptionData(Arrays.asList(
...@@ -86,7 +86,8 @@ public class StubbedGithubCveAPI implements GithubCveAPI { ...@@ -86,7 +86,8 @@ public class StubbedGithubCveAPI implements GithubCveAPI {
public String getCveDetails(GithubRequestParams params) { public String getCveDetails(GithubRequestParams params) {
try { try {
return om.writeValueAsString( return om.writeValueAsString(
internal.stream().filter(cve -> cve.getMetaData().getId().equalsIgnoreCase(params.getCveId())).findFirst()); internal.stream().filter(cve -> cve.getMetaData().getId().equalsIgnoreCase(params.getCveId()))
.findFirst());
} catch (JsonProcessingException e) { } catch (JsonProcessingException e) {
throw new RuntimeException("Could not fetch test GH CVE data", e); throw new RuntimeException("Could not fetch test GH CVE data", e);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment