Search in sources :

Example 11 with CveSearchData

use of org.eclipse.sw360.cvesearch.datasource.CveSearchData in project sw360portal by sw360.

the class CveSearchHandler method updateForRelease.

private VulnerabilityUpdateStatus updateForRelease(Release release) {
    Optional<List<CveSearchData>> cveSearchDatas = cveSearchWrapper.searchForRelease(release);
    if (!cveSearchDatas.isPresent()) {
        return new VulnerabilityUpdateStatus().setRequestStatus(RequestStatus.FAILURE);
    }
    CveSearchDataTranslator cveSearchDataTranslator = new CveSearchDataTranslator();
    List<CveSearchDataTranslator.VulnerabilityWithRelation> translated = cveSearchDatas.get().stream().map(cveSearchDataTranslator).map(vulnerabilityWithRelation -> {
        vulnerabilityWithRelation.relation.setReleaseId(release.getId());
        return vulnerabilityWithRelation;
    }).collect(Collectors.toList());
    VulnerabilityUpdateStatus updateStatus = getEmptyVulnerabilityUpdateStatus();
    for (CveSearchDataTranslator.VulnerabilityWithRelation vulnerabilityWithRelation : translated) {
        updateStatus = vulnerabilityConnector.addOrUpdate(vulnerabilityWithRelation.vulnerability, vulnerabilityWithRelation.relation, updateStatus);
    }
    return updateStatus;
}
Also used : VulnerabilityConnector(org.eclipse.sw360.cvesearch.datasink.VulnerabilityConnector) java.util(java.util) CveSearchData(org.eclipse.sw360.cvesearch.datasource.CveSearchData) CveSearchService(org.eclipse.sw360.datahandler.thrift.cvesearch.CveSearchService) Component(org.eclipse.sw360.datahandler.thrift.components.Component) Release(org.eclipse.sw360.datahandler.thrift.components.Release) CveSearchWrapper(org.eclipse.sw360.cvesearch.datasource.CveSearchWrapper) TException(org.apache.thrift.TException) IOException(java.io.IOException) VulnerabilityUpdateStatus(org.eclipse.sw360.datahandler.thrift.cvesearch.VulnerabilityUpdateStatus) Collectors(java.util.stream.Collectors) RequestStatus(org.eclipse.sw360.datahandler.thrift.RequestStatus) UpdateType(org.eclipse.sw360.datahandler.thrift.cvesearch.UpdateType) CommonUtils(org.eclipse.sw360.datahandler.common.CommonUtils) Logger(org.apache.log4j.Logger) CveSearchDataTranslator(org.eclipse.sw360.cvesearch.entitytranslation.CveSearchDataTranslator) VulnerabilityUtils(org.eclipse.sw360.cvesearch.helper.VulnerabilityUtils) CveSearchApiImpl(org.eclipse.sw360.cvesearch.datasource.CveSearchApiImpl) Project(org.eclipse.sw360.datahandler.thrift.projects.Project) VulnerabilityUpdateStatus(org.eclipse.sw360.datahandler.thrift.cvesearch.VulnerabilityUpdateStatus) CveSearchDataTranslator(org.eclipse.sw360.cvesearch.entitytranslation.CveSearchDataTranslator)

Example 12 with CveSearchData

use of org.eclipse.sw360.cvesearch.datasource.CveSearchData in project sw360portal by sw360.

the class CveSearchJsonParserTest method singleFull_A.

@Test
public void singleFull_A() {
    Object resultO = cveSearchJsonParserSingle.apply(toBufferedReader(SEARCH_RESULT_SINGLE_A));
    CveSearchData result = (CveSearchData) resultO;
    assert (result.getCvss() == 5.0);
    assert ("CVE-2002-0438".equals(result.getId()));
    Optional<Map.Entry<String, String>> vce = result.getVulnerable_configuration().entrySet().stream().findAny();
    assert (vce.isPresent());
    assert (vce.get().getKey().length() > 2);
    assert (vce.get().getValue().length() > 2);
}
Also used : CveSearchData(org.eclipse.sw360.cvesearch.datasource.CveSearchData) Test(org.junit.Test)

Example 13 with CveSearchData

use of org.eclipse.sw360.cvesearch.datasource.CveSearchData in project sw360portal by sw360.

the class CveSearchJsonParserTest method setUp.

@Before
public void setUp() {
    Type listTargetType = new TypeToken<List<CveSearchData>>() {
    }.getType();
    Type singleTargetType = new TypeToken<CveSearchData>() {
    }.getType();
    cveSearchJsonParserSingle = new CveSearchJsonParser(singleTargetType);
    cveSearchJsonParserList = new CveSearchJsonParser(listTargetType);
}
Also used : Type(java.lang.reflect.Type) List(java.util.List) CveSearchData(org.eclipse.sw360.cvesearch.datasource.CveSearchData) Before(org.junit.Before)

Example 14 with CveSearchData

use of org.eclipse.sw360.cvesearch.datasource.CveSearchData in project sw360portal by sw360.

the class CveSearchJsonParserTest method singleEmptyObj.

@Test
public void singleEmptyObj() {
    Object resultO = cveSearchJsonParserSingle.apply(toBufferedReader(SEARCH_RESULT_EMPTYOBJ));
    CveSearchData result = (CveSearchData) resultO;
}
Also used : CveSearchData(org.eclipse.sw360.cvesearch.datasource.CveSearchData) Test(org.junit.Test)

Example 15 with CveSearchData

use of org.eclipse.sw360.cvesearch.datasource.CveSearchData in project sw360portal by sw360.

the class CveSearchDataTranslatorTest method testWithApacheData.

@Test
public void testWithApacheData() throws IOException {
    List<CveSearchData> cveSearchDatas = new CveSearchApiImpl(host).search("apache", ".*");
    List<CveSearchDataTranslator.VulnerabilityWithRelation> vms = cveSearchDatas.stream().map(cveSearchData -> cveSearchDataTranslator.apply(cveSearchData)).collect(Collectors.toList());
    assert (vms != null);
    List<Vulnerability> vs = vms.stream().map(vm -> vm.vulnerability).collect(Collectors.toList());
    assert (vs.size() > 700);
}
Also used : java.util(java.util) CveSearchData(org.eclipse.sw360.cvesearch.datasource.CveSearchData) Test(org.junit.Test) IOException(java.io.IOException) CveSearchHandler(org.eclipse.sw360.cvesearch.service.CveSearchHandler) Collectors(java.util.stream.Collectors) CommonUtils(org.eclipse.sw360.datahandler.common.CommonUtils) CveSearchApiImpl(org.eclipse.sw360.cvesearch.datasource.CveSearchApiImpl) Assume(org.junit.Assume) CVEReference(org.eclipse.sw360.datahandler.thrift.vulnerabilities.CVEReference) Vulnerability(org.eclipse.sw360.datahandler.thrift.vulnerabilities.Vulnerability) Before(org.junit.Before) CveSearchDataTestHelper.isUrlReachable(org.eclipse.sw360.cvesearch.datasource.CveSearchDataTestHelper.isUrlReachable) Vulnerability(org.eclipse.sw360.datahandler.thrift.vulnerabilities.Vulnerability) CveSearchData(org.eclipse.sw360.cvesearch.datasource.CveSearchData) CveSearchApiImpl(org.eclipse.sw360.cvesearch.datasource.CveSearchApiImpl) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)12 CveSearchData (org.eclipse.sw360.cvesearch.datasource.CveSearchData)10 Vulnerability (org.eclipse.sw360.datahandler.thrift.vulnerabilities.Vulnerability)5 List (java.util.List)4 Release (org.eclipse.sw360.datahandler.thrift.components.Release)4 IOException (java.io.IOException)3 java.util (java.util)3 Collectors (java.util.stream.Collectors)3 CveSearchApiImpl (org.eclipse.sw360.cvesearch.datasource.CveSearchApiImpl)3 CommonUtils (org.eclipse.sw360.datahandler.common.CommonUtils)3 CVEReference (org.eclipse.sw360.datahandler.thrift.vulnerabilities.CVEReference)3 Before (org.junit.Before)3 CveSearchDataTestHelper.isUrlReachable (org.eclipse.sw360.cvesearch.datasource.CveSearchDataTestHelper.isUrlReachable)2 CveSearchHandler (org.eclipse.sw360.cvesearch.service.CveSearchHandler)2 Assume (org.junit.Assume)2 Ignore (org.junit.Ignore)2 Type (java.lang.reflect.Type)1 Logger (org.apache.log4j.Logger)1 TException (org.apache.thrift.TException)1 VulnerabilityConnector (org.eclipse.sw360.cvesearch.datasink.VulnerabilityConnector)1