Skip to content

Commit

Permalink
Merge pull request #25 from bmrvilela/master
Browse files Browse the repository at this point in the history
New models for scan result with hierarchy for both soap and priority APIs
  • Loading branch information
portilha authored Jul 16, 2024
2 parents 2a7f621 + 40599a7 commit de56ef3
Show file tree
Hide file tree
Showing 9 changed files with 572 additions and 313 deletions.
82 changes: 63 additions & 19 deletions Checkmarx.API.Tests/ScanTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections.Generic;
using System.Configuration;
using System.Diagnostics;
using System.Dynamic;
using System.IO;
using System.IO.Compression;
using System.Linq;
Expand All @@ -17,6 +18,7 @@
using System.Xml.Linq;
using Checkmarx.API;
using Checkmarx.API.Exceptions;
using Checkmarx.API.Models;
using cxPriorityWebService;
using Microsoft.Extensions.Configuration;
using Microsoft.OData.Client;
Expand Down Expand Up @@ -394,9 +396,9 @@ public void GetResultsForScan()
// New, Fixed, Recorrence
var resultByType = severity.GroupBy(x => x.ResultStatus).ToDictionary(x => x.Key);

csvFields.Add(!resultByType.ContainsKey(PortalSoap.CompareStatusType.New) ? 0 : resultByType[PortalSoap.CompareStatusType.New].Count());
csvFields.Add(!resultByType.ContainsKey(PortalSoap.CompareStatusType.Fixed) ? 0 : resultByType[PortalSoap.CompareStatusType.Fixed].Count());
csvFields.Add(!resultByType.ContainsKey(PortalSoap.CompareStatusType.Reoccured) ? 0 : resultByType[PortalSoap.CompareStatusType.Reoccured].Count());
csvFields.Add(!resultByType.ContainsKey(ResultStatus.New) ? 0 : resultByType[ResultStatus.New].Count());
csvFields.Add(!resultByType.ContainsKey(ResultStatus.Fixed) ? 0 : resultByType[ResultStatus.Fixed].Count());
csvFields.Add(!resultByType.ContainsKey(ResultStatus.Reoccured) ? 0 : resultByType[ResultStatus.Reoccured].Count());

csvFields.Add(query.Status.ToString());

Expand Down Expand Up @@ -526,7 +528,7 @@ public void GetNotExploitableResults()
{
var pathhistory = clientV93.GetPathCommentsHistory(scan.Id, result.PathId);

var uri = Utils.GetLink(result, clientV93, 1, scan.Id);
var uri = result.GetLink(clientV93, 1, scan.Id);

stringBuilder.AppendLine($"<a href=\"{uri.AbsoluteUri}\">{uri.AbsoluteUri}</a>");

Expand Down Expand Up @@ -832,43 +834,85 @@ public void ConflictIdInODataQueryTest()
public void GetXSSResultsTest()
{
var results = clientV93.GetResultsForScan(2013975); // SOAP ...

Trace.WriteLine("Count: " + results.Count());
foreach (var result in results)
{
Trace.WriteLine(result.QueryId + ";" + result.QueryVersionCode);
}


var odataResults = clientV93.GetODataV95Results(2013975); // OData

Trace.WriteLine("ODATA Count: " + odataResults.Count());

foreach (var odataResult in odataResults)
{
Trace.WriteLine(odataResult.QueryId + ";" + odataResult.QueryVersionId + ";" + odataResult.Query.Name);
}


Assert.AreEqual(odataResults.Count(), results.Count(), "The results from OData and SOAP should be equal");
}


[TestMethod]
public void PriorityAPIGetScanResultsTest()
{
var results = clientV93.GetResultsForScan(2013975); // SOAP ...
try
{
var resultProperties = typeof(SoapSingleResultData).GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.GetProperty);

Trace.WriteLine("Property values using PortalSoap");
var results = clientV9.GetResultsForScan(1705892); // Portal SOAP
foreach (var result in results)
{
foreach (var property in resultProperties)
Trace.WriteLine(property.Name + ": " + property.GetValue(result));
}

var resultProperties = typeof(CxWSResponseScanResultsPriority).GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.GetProperty);
//Trace.WriteLine("");
//Trace.WriteLine("Property values using Priority");
//var resultsPriority = clientV9.GetResultsForScan(1705892, usePriority: true); // Priority
//foreach (var result in resultsPriority)
//{
// foreach (var property in resultProperties)
// Trace.WriteLine(property.Name + ": " + property.GetValue(result));
//}
}
catch (Exception ex)
{
Trace.WriteLine(ex.Message);
}
}

foreach (var result in results.Take(1))
[TestMethod]
public void CompareSoapVsOdataScanResultsTest()
{
var projects = clientV93.GetAllProjectsDetails();
foreach (var project in projects)
{
foreach (var property in resultProperties)
try
{
var scanInfo = clientV93.GetLastScan(project.Id);
if (scanInfo != null)
{
var odataResults = clientV93.GetODataV95Results(scanInfo.Id); // OData
var results = clientV93.GetResultsForScan(scanInfo.Id); // SOAP
if (odataResults.Count() != results.Count())
{
var odataQueryIds = odataResults.Where(x => x.QueryId.HasValue).Select(x => x.QueryId.Value).Distinct();
var queryIds = results.Select(x => x.QueryId).Distinct();

// Find queries in odata that are not in soap
var difference1 = odataQueryIds.Except(queryIds).ToList();

// Find queries in soap that are not in odata
var difference2 = queryIds.Except(odataQueryIds).ToList();

// Total diff
var totalDiff = difference1.Union(difference2);

Trace.WriteLine($"Project {project.Id} - Scan {scanInfo.Id} - Query Difference: {string.Join(";", totalDiff)}");
}
}
}
catch (Exception ex)
{
Trace.WriteLine(property.Name + ": " + property.GetValue(result));
Trace.WriteLine($"Error for project {project.Id}: {ex.Message}");
}
}

}
}
}
6 changes: 6 additions & 0 deletions Checkmarx.API/Checkmarx.API.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,32 @@ It also provides access to the Access Control API.</Description>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
<WarningsNotAsErrors>VSSpell001</WarningsNotAsErrors>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
<WarningsNotAsErrors>VSSpell001</WarningsNotAsErrors>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
<WarningsNotAsErrors>VSSpell001</WarningsNotAsErrors>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
<WarningsNotAsErrors>VSSpell001</WarningsNotAsErrors>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Publish|AnyCPU'">
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
<WarningsNotAsErrors>VSSpell001</WarningsNotAsErrors>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Publish|x64'">
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
<WarningsNotAsErrors>VSSpell001</WarningsNotAsErrors>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Checkmarx.API/Connected Services/PortalSoap/Reference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22181,7 +22181,7 @@ public PortalSoap.CxWSResponceScanResults GetResultsForScanByLanguage(string ses
return base.Channel.GetResultsForScanByLanguageAsync(sessionID, scanId, Language);
}

public PortalSoap.CxWSResponceScanResults GetResultsForScan(string sessionID, long scanId)
internal PortalSoap.CxWSResponceScanResults GetResultsForScan(string sessionID, long scanId)
{
return base.Channel.GetResultsForScan(sessionID, scanId);
}
Expand Down
Loading

0 comments on commit de56ef3

Please sign in to comment.