Skip to content

Commit

Permalink
pre-pr cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
nahsra committed Aug 29, 2023
1 parent 0bf61fa commit 73246c8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,13 @@ public List<Result> getResultsByPath(final Path path) {
}
List<Result> results =
sarif.getRuns().get(0).getResults().stream()
// if the semgrep is offline, the rule id will be exactly what we think it should be, if
// it's run just-in-time by our code, it will have this weird .<ruleId> suffix
/*
* The default Semgrep rules have a rule id reported that is what you'd expect. When you run
* your own custom rules locally, they'll contain part of the file system path to the rule.
*
* Because this provides support for both types, we need this check to account for which type
* of rule id we're dealing with.
*/
.filter(
result ->
result.getRuleId().endsWith("." + ruleId) || result.getRuleId().equals(ruleId))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package io.codemodder.providers.sarif.semgrep;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.*;
import static org.junit.jupiter.api.Assertions.assertThrows;

import com.contrastsecurity.sarif.Region;
Expand Down Expand Up @@ -250,6 +249,14 @@ void it_works_with_offline_semgrep(@TempDir Path tmpDir) throws IOException {
assertThat(ruleSarif, is(notNullValue()));
List<Region> regions = ruleSarif.getRegionsFromResultsByRule(javaFile);
assertThat(regions.size(), is(1));

Region region = regions.get(0);
assertThat(region.getStartLine(), equalTo(91));
assertThat(region.getStartColumn(), equalTo(7));
assertThat(
ruleSarif.getRule(),
equalTo("java.lang.security.audit.unsafe-reflection.unsafe-reflection"));
assertThat(ruleSarif.getDriver(), equalTo("semgrep"));
}

@Codemod(
Expand Down

0 comments on commit 73246c8

Please sign in to comment.