-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2974 from mercedes-benz/develop
Merge `develop` into `master` for cx-wrapper release
- Loading branch information
Showing
11 changed files
with
366 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
.../src/main/java/com/mercedesbenz/sechub/sereco/importer/GitleaksSarifImportWorkaround.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// SPDX-License-Identifier: MIT | ||
package com.mercedesbenz.sechub.sereco.importer; | ||
|
||
import org.springframework.stereotype.Component; | ||
|
||
import de.jcup.sarif_2_1_0.model.ReportingDescriptor; | ||
import de.jcup.sarif_2_1_0.model.Run; | ||
import de.jcup.sarif_2_1_0.model.Tool; | ||
import de.jcup.sarif_2_1_0.model.ToolComponent; | ||
|
||
@Component | ||
public class GitleaksSarifImportWorkaround implements SarifImportProductWorkaround { | ||
|
||
@Override | ||
public String resolveType(ReportingDescriptor rule, Run run) { | ||
if (rule == null) { | ||
return null; | ||
} | ||
if (isGitleaksRun(run)) { | ||
return rule.getName(); | ||
} | ||
return null; | ||
} | ||
|
||
private boolean isGitleaksRun(Run run) { | ||
if (run == null) { | ||
return false; | ||
} | ||
Tool tool = run.getTool(); | ||
if (tool == null) { | ||
return false; | ||
} | ||
ToolComponent driver = tool.getDriver(); | ||
if (driver == null) { | ||
return false; | ||
} | ||
return "gitleaks".equalsIgnoreCase(driver.getName()); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...o/src/main/java/com/mercedesbenz/sechub/sereco/importer/SarifImportProductWorkaround.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// SPDX-License-Identifier: MIT | ||
package com.mercedesbenz.sechub.sereco.importer; | ||
|
||
import de.jcup.sarif_2_1_0.model.ReportingDescriptor; | ||
import de.jcup.sarif_2_1_0.model.Run; | ||
|
||
public interface SarifImportProductWorkaround { | ||
|
||
/** | ||
* Resolve type from SARIF rule and SARIF run. | ||
* | ||
* @param rule | ||
* @param run | ||
* @return Resolve type or <code>null</code> if type could not be resolved by | ||
* this workaround. | ||
*/ | ||
public default String resolveType(ReportingDescriptor rule, Run run) { | ||
return null; | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...ain/java/com/mercedesbenz/sechub/sereco/importer/SarifImportProductWorkaroundSupport.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// SPDX-License-Identifier: MIT | ||
package com.mercedesbenz.sechub.sereco.importer; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
import de.jcup.sarif_2_1_0.model.ReportingDescriptor; | ||
import de.jcup.sarif_2_1_0.model.Run; | ||
|
||
/** | ||
* Support to handle any kind of workaround for SARIF imports. | ||
*/ | ||
@Component | ||
public class SarifImportProductWorkaroundSupport { | ||
|
||
@Autowired | ||
List<SarifImportProductWorkaround> workarounds = new ArrayList<>(); | ||
|
||
/** | ||
* Resolve type from SARIF rule and SARIF run. | ||
* | ||
* @param rule | ||
* @param run | ||
* @return Resolved type or <code>null</code> if type could not be resolved by | ||
* any available workaround. | ||
*/ | ||
public String resolveType(ReportingDescriptor rule, Run run) { | ||
for (SarifImportProductWorkaround workaround : workarounds) { | ||
String resolvedType = workaround.resolveType(rule, run); | ||
if (resolvedType != null) { | ||
return resolvedType; | ||
} | ||
} | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
.../test/java/com/mercedesbenz/sechub/sereco/importer/GitleaksSarifImportWorkaroundTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
// SPDX-License-Identifier: MIT | ||
package com.mercedesbenz.sechub.sereco.importer; | ||
|
||
import static org.junit.Assert.assertNull; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import de.jcup.sarif_2_1_0.model.ReportingDescriptor; | ||
import de.jcup.sarif_2_1_0.model.Run; | ||
import de.jcup.sarif_2_1_0.model.Tool; | ||
import de.jcup.sarif_2_1_0.model.ToolComponent; | ||
|
||
class GitleaksSarifImportWorkaroundTest { | ||
|
||
private GitleaksSarifImportWorkaround workaroundToTest = new GitleaksSarifImportWorkaround(); | ||
|
||
@Test | ||
void rule_is_null_results_in_resolved_type_is_null() { | ||
/* execute */ | ||
String resolvedType = workaroundToTest.resolveType(null, new Run()); | ||
|
||
/* test */ | ||
assertNull(resolvedType); | ||
} | ||
|
||
@Test | ||
void run_is_null_results_in_resolved_type_is_null() { | ||
/* execute */ | ||
String resolvedType = workaroundToTest.resolveType(new ReportingDescriptor(), null); | ||
|
||
/* test */ | ||
assertNull(resolvedType); | ||
} | ||
|
||
@Test | ||
void run_tool_is_null_results_in_resolved_type_is_null() { | ||
/* prepare */ | ||
Run run = new Run(); | ||
run.setTool(null); | ||
|
||
/* execute */ | ||
String resolvedType = workaroundToTest.resolveType(new ReportingDescriptor(), run); | ||
|
||
/* test */ | ||
assertNull(resolvedType); | ||
} | ||
|
||
@Test | ||
void run_tool_driver_is_null_results_in_resolved_type_is_null() { | ||
/* prepare */ | ||
Run run = new Run(); | ||
Tool tool = new Tool(); | ||
tool.setDriver(null); | ||
run.setTool(tool); | ||
|
||
/* execute */ | ||
String resolvedType = workaroundToTest.resolveType(new ReportingDescriptor(), run); | ||
|
||
/* test */ | ||
assertNull(resolvedType); | ||
} | ||
|
||
@Test | ||
void run_tool_driver_name_is_gitleaks_results_in_resolved_type_is_rule_name() { | ||
/* prepare */ | ||
Run run = new Run(); | ||
Tool tool = new Tool(); | ||
ToolComponent driver = new ToolComponent(); | ||
driver.setName("gitleaks"); | ||
tool.setDriver(driver); | ||
run.setTool(tool); | ||
|
||
ReportingDescriptor rule = new ReportingDescriptor(); | ||
rule.setName("GitHub Personal Access Token"); | ||
|
||
/* execute */ | ||
String resolvedType = workaroundToTest.resolveType(rule, run); | ||
|
||
/* test */ | ||
assertEquals(rule.getName(), resolvedType); | ||
} | ||
|
||
@Test | ||
void run_tool_driver_name_is_NOT_gitleaks_results_in_resolved_type_is_null() { | ||
/* prepare */ | ||
Run run = new Run(); | ||
Tool tool = new Tool(); | ||
ToolComponent driver = new ToolComponent(); | ||
driver.setName("random-name"); | ||
tool.setDriver(driver); | ||
run.setTool(tool); | ||
|
||
ReportingDescriptor rule = new ReportingDescriptor(); | ||
rule.setName("GitHub Personal Access Token"); | ||
|
||
/* execute */ | ||
String resolvedType = workaroundToTest.resolveType(rule, run); | ||
|
||
/* test */ | ||
assertNull(resolvedType); | ||
} | ||
|
||
} |
Oops, something went wrong.