Search in sources :

Example 11 with Vulnerability

use of org.eclipse.sw360.datahandler.thrift.vulnerabilities.Vulnerability in project sw360portal by sw360.

the class VulnerabilityConnectorTest method testIsMoreRecentFirstOlder.

@Test
public void testIsMoreRecentFirstOlder() throws Exception {
    Vulnerability v1 = new Vulnerability().setLastExternalUpdate("2015");
    Vulnerability v2 = new Vulnerability().setLastExternalUpdate("2016");
    assertThat(vulnerabilityConnector.isMoreRecent(v1, v2), is(false));
}
Also used : Vulnerability(org.eclipse.sw360.datahandler.thrift.vulnerabilities.Vulnerability) Test(org.junit.Test)

Example 12 with Vulnerability

use of org.eclipse.sw360.datahandler.thrift.vulnerabilities.Vulnerability in project sw360portal by sw360.

the class CveSearchDataTranslator method apply.

@Override
public VulnerabilityWithRelation apply(CveSearchData cveSearchData) {
    Vulnerability vulnerability = new CveSearchDataToVulnerabilityTranslator().apply(cveSearchData);
    ReleaseVulnerabilityRelation relation = new CveSearchDataToReleaseVulnerabilityRelationTranslator().apply(cveSearchData);
    return new VulnerabilityWithRelation(vulnerability, relation);
}
Also used : ReleaseVulnerabilityRelation(org.eclipse.sw360.datahandler.thrift.vulnerabilities.ReleaseVulnerabilityRelation) Vulnerability(org.eclipse.sw360.datahandler.thrift.vulnerabilities.Vulnerability)

Example 13 with Vulnerability

use of org.eclipse.sw360.datahandler.thrift.vulnerabilities.Vulnerability in project sw360portal by sw360.

the class VulnerabilityUtilsTest method setUp.

@Before
public void setUp() throws Exception {
    emptyVus = getEmptyVulnerabilityUpdateStatus(RequestStatus.SUCCESS);
    vus1 = getEmptyVulnerabilityUpdateStatus(RequestStatus.SUCCESS);
    for (UpdateType updateType : UpdateType.values()) {
        vus1.statusToVulnerabilityIds.get(updateType).addAll(Arrays.asList("id0", "id1", "id2"));
    }
    vus2 = getEmptyVulnerabilityUpdateStatus(RequestStatus.SUCCESS);
    for (UpdateType updateType : UpdateType.values()) {
        vus2.statusToVulnerabilityIds.get(updateType).addAll(Arrays.asList("id3", "id4", "id5"));
    }
    vus3 = getEmptyVulnerabilityUpdateStatus(RequestStatus.FAILURE);
    for (UpdateType updateType : UpdateType.values()) {
        vus3.statusToVulnerabilityIds.get(updateType).addAll(Arrays.asList("id6", "id7", "id8"));
    }
    List<Vulnerability> nlist = Arrays.asList(new Vulnerability().setId("n1").setExternalId("ne1"), new Vulnerability().setId("n2").setExternalId("ne2"));
    List<Vulnerability> ulist = Arrays.asList(new Vulnerability().setId("u1").setExternalId("ue1"), new Vulnerability().setId("u2").setExternalId("ue2"), new Vulnerability().setId("u3").setExternalId("ue3"));
    List<Vulnerability> olist = Arrays.asList(new Vulnerability().setId("o1").setExternalId("oe1"), new Vulnerability().setId("o2").setExternalId("oe2"), new Vulnerability().setId("o3").setExternalId("oe3"));
    List<Vulnerability> flist = Arrays.asList(new Vulnerability().setId("f1").setExternalId("fe1"), new Vulnerability().setId("f2").setExternalId("fe2"), new Vulnerability().setId("f3").setExternalId("fe3"));
    updateMap = new HashMap<>();
    updateMap.put(UpdateType.NEW, nlist);
    updateMap.put(UpdateType.UPDATED, ulist);
    failedUpdateMap = new HashMap<>();
    failedUpdateMap.put(UpdateType.NEW, nlist);
    failedUpdateMap.put(UpdateType.UPDATED, ulist);
    failedUpdateMap.put(UpdateType.OLD, olist);
    failedUpdateMap.put(UpdateType.FAILED, flist);
}
Also used : Vulnerability(org.eclipse.sw360.datahandler.thrift.vulnerabilities.Vulnerability) UpdateType(org.eclipse.sw360.datahandler.thrift.cvesearch.UpdateType) Before(org.junit.Before)

Example 14 with Vulnerability

use of org.eclipse.sw360.datahandler.thrift.vulnerabilities.Vulnerability in project sw360portal by sw360.

the class CveSearchDataTranslatorTest method testIdTranslation.

@Test
public void testIdTranslation() {
    Vulnerability v = cveSearchDataTranslator.apply(cveSearchData).vulnerability;
    Set<CVEReference> cveReferences = v.getCveReferences();
    assert (cveReferences.size() == 1);
    CVEReference cveReference = cveReferences.stream().findAny().get();
    assert (CVEYEAR.equals(cveReference.getYear()));
    assert ((CVENUMBER + ID).equals(cveReference.getNumber()));
}
Also used : CVEReference(org.eclipse.sw360.datahandler.thrift.vulnerabilities.CVEReference) Vulnerability(org.eclipse.sw360.datahandler.thrift.vulnerabilities.Vulnerability) Test(org.junit.Test)

Example 15 with Vulnerability

use of org.eclipse.sw360.datahandler.thrift.vulnerabilities.Vulnerability in project sw360portal by sw360.

the class VulnerabilityConnector method addOrUpdate.

public UpdateType addOrUpdate(Vulnerability vulnerability, ReleaseVulnerabilityRelation partiallyFilledRelation) {
    RequestStatus vulRequestStatus = RequestStatus.SUCCESS;
    UpdateType updateType;
    Vulnerability dbVulnerability = vulnerabilityDatabaseHandler.getByExternalId(Vulnerability.class, vulnerability.getExternalId());
    if (dbVulnerability != null) {
        if (isMoreRecent(vulnerability, dbVulnerability)) {
            updateType = UpdateType.UPDATED;
            dbVulnerability = VulnerabilityMapper.updateFromVulnerability(dbVulnerability, vulnerability);
            vulRequestStatus = vulnerabilityDatabaseHandler.update(dbVulnerability);
        } else {
            updateType = UpdateType.OLD;
        }
    } else {
        updateType = UpdateType.NEW;
        vulRequestStatus = vulnerabilityDatabaseHandler.add(vulnerability);
        dbVulnerability = vulnerability;
    }
    if (RequestStatus.FAILURE.equals(vulRequestStatus)) {
        return UpdateType.FAILED;
    }
    partiallyFilledRelation.setVulnerabilityId(dbVulnerability.getId());
    RequestStatus requestStatus = addOrUpdate(partiallyFilledRelation);
    if (RequestStatus.FAILURE.equals(requestStatus)) {
        return UpdateType.FAILED;
    }
    return updateType;
}
Also used : Vulnerability(org.eclipse.sw360.datahandler.thrift.vulnerabilities.Vulnerability) UpdateType(org.eclipse.sw360.datahandler.thrift.cvesearch.UpdateType) RequestStatus(org.eclipse.sw360.datahandler.thrift.RequestStatus)

Aggregations

Vulnerability (org.eclipse.sw360.datahandler.thrift.vulnerabilities.Vulnerability)28 Test (org.junit.Test)15 UpdateType (org.eclipse.sw360.datahandler.thrift.cvesearch.UpdateType)10 User (org.eclipse.sw360.datahandler.thrift.users.User)8 TException (org.apache.thrift.TException)6 VulnerabilityService (org.eclipse.sw360.datahandler.thrift.vulnerabilities.VulnerabilityService)5 ReleaseVulnerabilityRelation (org.eclipse.sw360.datahandler.thrift.vulnerabilities.ReleaseVulnerabilityRelation)4 JSONObject (com.liferay.portal.kernel.json.JSONObject)3 PrintWriter (java.io.PrintWriter)3 VulnerabilityUpdateStatus (org.eclipse.sw360.datahandler.thrift.cvesearch.VulnerabilityUpdateStatus)3 Before (org.junit.Before)3 IOException (java.io.IOException)2 java.util (java.util)2 ArrayList (java.util.ArrayList)2 Collectors (java.util.stream.Collectors)2 CommonUtils (org.eclipse.sw360.datahandler.common.CommonUtils)2 PortletUtils.getVerificationState (org.eclipse.sw360.portal.common.PortletUtils.getVerificationState)2 ResponseEntity (org.springframework.http.ResponseEntity)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 JsonFactory (com.fasterxml.jackson.core.JsonFactory)1