Search in sources :

Example 6 with CveSearchData

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

the class CveSearchJsonParserTest method testDateParser2_2.

@Test
public void testDateParser2_2() {
    long dateAsLong = 1299534616563L;
    String json = "{\"Modified\": { \"$date\": " + dateAsLong + "}}";
    Object resultO = cveSearchJsonParserSingle.apply(toBufferedReader(json));
    CveSearchData result = (CveSearchData) resultO;
    assert (result.getModified() != null);
    assert (result.getModified().length() > 0);
    assert (result.getModified().startsWith("2011-03-07T"));
}
Also used : CveSearchData(org.eclipse.sw360.cvesearch.datasource.CveSearchData) Test(org.junit.Test)

Example 7 with CveSearchData

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

the class CveSearchJsonParserTest method testDateParser2_1.

@Test
public void testDateParser2_1() {
    String date = "2011-03-07T21:50:16.563-05:00";
    String json = "{\"Modified\": \"" + date + "\"}";
    Object resultO = cveSearchJsonParserSingle.apply(toBufferedReader(json));
    CveSearchData result = (CveSearchData) resultO;
    assert (result.getModified() != null);
    assert (result.getModified().length() > 0);
    assert (date.equals(result.getModified()));
}
Also used : CveSearchData(org.eclipse.sw360.cvesearch.datasource.CveSearchData) Test(org.junit.Test)

Example 8 with CveSearchData

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

the class CveSearchJsonParserTest method singleFull_B.

@Test
public void singleFull_B() {
    Object resultO = cveSearchJsonParserSingle.apply(toBufferedReader(SEARCH_RESULT_SINGLE_B));
    CveSearchData result = (CveSearchData) resultO;
    assert (result.getCvss() == 5.0);
    assert ("CVE-2002-0438".equals(result.getId()));
    assert (result.getVulnerable_configuration().size() == 6);
    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);
    assert (!vce.get().getKey().equals(vce.get().getValue()));
}
Also used : CveSearchData(org.eclipse.sw360.cvesearch.datasource.CveSearchData) Test(org.junit.Test)

Example 9 with CveSearchData

use of org.eclipse.sw360.cvesearch.datasource.CveSearchData 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 10 with CveSearchData

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

the class CveSearchDataToVulnerabilityTranslator method apply.

@Override
public Vulnerability apply(CveSearchData cveSearchData) {
    Vulnerability vulnerability = new Vulnerability().setTitle(cveSearchData.getId()).setCveReferences(getCVEReferencesForCveSearchdata(cveSearchData)).setDescription(cveSearchData.getSummary()).setPublishDate(cveSearchData.getPublished()).setLastExternalUpdate(cveSearchData.getModified()).setReferences(cveSearchData.getReferences()).setExternalId(cveSearchData.getId()).setImpact(cveSearchData.getImpact()).setAccess(cveSearchData.getAccess()).setVulnerableConfiguration(cveSearchData.getVulnerable_configuration()).setCwe(cveSearchData.getCwe()).setCveFurtherMetaDataPerSource(cveSearchData.getMap_cve_all());
    if (cveSearchData.getCvss() != null) {
        vulnerability.setIsSetCvss(true);
        vulnerability.setCvss(cveSearchData.getCvss());
        vulnerability.setCvssTime(cveSearchData.getCvss_time());
    }
    return vulnerability;
}
Also used : Vulnerability(org.eclipse.sw360.datahandler.thrift.vulnerabilities.Vulnerability)

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