Skip to content

Commit

Permalink
CR comments changes
Browse files Browse the repository at this point in the history
  • Loading branch information
checkmarx-kobi-hagmi committed Jun 4, 2024
1 parent fcb8a47 commit 101967d
Show file tree
Hide file tree
Showing 5 changed files with 178 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/checkmarx/ast/ScanResult/Error.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import com.fasterxml.jackson.annotation.JsonProperty;

public class Error {
int code;
String description;
public int code;
public String description;

@JsonCreator
public Error(
Expand Down
Binary file modified src/main/resources/cx.exe
Binary file not shown.
43 changes: 34 additions & 9 deletions src/test/java/com/checkmarx/ast/ScanTest.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package com.checkmarx.ast;

import com.checkmarx.ast.ScanResult.Error;
import com.checkmarx.ast.ScanResult.ScanDetail;
import com.checkmarx.ast.ScanResult.ScanResult;
import com.checkmarx.ast.kicsRealtimeResults.KicsRealtimeResults;
import com.checkmarx.ast.scan.Scan;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.Map;
import java.util.UUID;
Expand All @@ -24,19 +23,45 @@ void testScanShow() throws Exception {
}

@Test
void testScanVorpalSuccessfulResponse() throws Exception {
ScanResult scanResult = wrapper.ScanVorpal("src/test/resources/csharp-file.cs", true);
void testScanVorpal_WhenFileWithVulnerabilitiesIsSent_ReturnSuccessfulResponseWithCorrectValues() throws Exception {
ScanResult scanResult = wrapper.ScanVorpal("src/test/resources/python-vul-file.py", true);
Assertions.assertNotNull(scanResult.getRequestId());
Assertions.assertTrue(scanResult.isStatus());
Assertions.assertEquals(2, scanResult.getScanDetails().size());
Assertions.assertNull(scanResult.getError());
ScanDetail firstScanDetails = scanResult.getScanDetails().get(0);
Assertions.assertEquals(37, firstScanDetails.getLine());
Assertions.assertEquals("Stored XSS", firstScanDetails.getQueryName());
Assertions.assertEquals("High", firstScanDetails.getSeverity());
Assertions.assertNotNull(firstScanDetails.getRemediation());
Assertions.assertNotNull(firstScanDetails.getDescription());
ScanDetail secondScanDetails = scanResult.getScanDetails().get(1);
Assertions.assertEquals(76, secondScanDetails.getLine());
Assertions.assertEquals("Missing HSTS Header", secondScanDetails.getQueryName());
Assertions.assertEquals("Medium", secondScanDetails.getSeverity());
Assertions.assertNotNull(secondScanDetails.getRemediation());
Assertions.assertNotNull(secondScanDetails.getDescription());
}

@Test
void testScanVorpalFailureResponse() throws Exception {
ScanResult scanResult = wrapper.ScanVorpal("src/test/resources/csharp-file.cs", false);
Assertions.assertEquals("1111", scanResult.getRequestId());
void testScanVorpal_WhenFileWithoutVulnerabilitiesIsSent_ReturnSuccessfulResponseWithCorrectValues() throws Exception {
ScanResult scanResult = wrapper.ScanVorpal("src/test/resources/csharp-no-vul.cs", true);
Assertions.assertNotNull(scanResult.getRequestId());
Assertions.assertTrue(scanResult.isStatus());
Assertions.assertEquals(0, scanResult.getScanDetails().size());
Assertions.assertNull(scanResult.getError());
}

@Test
void testScanVorpal_WhenInvalidRequestIsSent_ReturnInternalErrorFailure() throws Exception {
ScanResult scanResult = wrapper.ScanVorpal("src/test/resources/python-vul-file.py", false);
Assertions.assertEquals("some-request-id", scanResult.getRequestId());
Assertions.assertFalse(scanResult.isStatus());
Assertions.assertNotNull(scanResult.getError());
Assertions.assertNull(scanResult.getScanDetails());
Error error = scanResult.getError();
Assertions.assertNotNull(error);
Assertions.assertEquals("An internal error occurred.", error.description);
Assertions.assertEquals(2, error.code);
}

@Test
Expand Down
44 changes: 44 additions & 0 deletions src/test/resources/csharp-no-vul.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
namespace EvidenceResolver.Tests.Contract
{
public static class MockProviderServiceExtenstion
{
public static IMockProviderService WithRequest(this IMockProviderService mockProviderService,
HttpVerb method, object path, object body = null, Dictionary<string, object> headers = null)
{
var providerServiceRequest = new ProviderServiceRequest
{
Method = method,
Path = path
};

providerServiceRequest.Headers = headers ?? new Dictionary<string, object>
{
{"Content-Type", "application/json"}
};

if (body != null) {
providerServiceRequest.Body = PactNet.Matchers.Match.Type(body);
}

return mockProviderService.With(providerServiceRequest);
}

public static void WillRespondParameters(this IMockProviderService mockProviderService,
int status, dynamic body = null, Dictionary<string, object> headers = null)
{
if (body == null) {
body = new { };
}

var expectedResponse = new ProviderServiceResponse
{
Status = status,
Headers = headers ?? new Dictionary<string, object>
{{"Content-Type", "application/json; charset=utf-8"}},
Body = PactNet.Matchers.Match.Type(body)
};

mockProviderService.WillRespondWith(expectedResponse);
}
}
}
Loading

0 comments on commit 101967d

Please sign in to comment.