Skip to content

Commit 112cc6d

Browse files
committed
path should be full
1 parent 5933dfa commit 112cc6d

File tree

3 files changed

+10
-12
lines changed

3 files changed

+10
-12
lines changed

framework/codemodder-testutils/src/main/java/io/codemodder/testutils/CodemodTestMixin.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,6 @@ private void verifyCodemod(
8383
Path pathToJavaFile = tmpDir.resolve("Test.java");
8484
Files.copy(before, pathToJavaFile, StandardCopyOption.REPLACE_EXISTING);
8585

86-
// Check for any sarif files and build the RuleSarif map
87-
List<Path> allSarifs = new ArrayList<>();
88-
Files.newDirectoryStream(testResourceDir, "*.sarif")
89-
.iterator()
90-
.forEachRemaining(allSarifs::add);
91-
92-
Map<String, List<RuleSarif>> map = SarifParser.create().parseIntoMap(allSarifs, tmpDir);
93-
9486
// rename file if needed
9587
if (!renameTestFile.isBlank()) {
9688
Path parent = tmpDir.resolve(renameTestFile).getParent();
@@ -105,6 +97,13 @@ private void verifyCodemod(
10597
// add the sonar JSON if one exists
10698
Path sonarJson = testResourceDir.resolve("sonar-issues.json");
10799

100+
// Check for any sarif files and build the RuleSarif map
101+
List<Path> allSarifs = new ArrayList<>();
102+
Files.newDirectoryStream(testResourceDir, "*.sarif")
103+
.iterator()
104+
.forEachRemaining(allSarifs::add);
105+
Map<String, List<RuleSarif>> map = SarifParser.create().parseIntoMap(allSarifs, tmpDir);
106+
108107
// run the codemod
109108
CodemodLoader loader =
110109
new CodemodLoader(

plugins/codemodder-plugin-appscan/src/main/java/io/codemodder/providers/sarif/appscan/AppScanRuleSarif.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public AppScanRuleSarif(
5858
existingRealPath.ifPresent(
5959
p ->
6060
artifactLocationIndices
61-
.computeIfAbsent(repositoryRoot.relativize(p), k -> new HashSet<>())
61+
.computeIfAbsent(p, k -> new HashSet<>())
6262
.add(index));
6363
}
6464
this.artifactLocationIndices = Map.copyOf(artifactLocationIndices);

plugins/codemodder-plugin-appscan/src/test/java/io/codemodder/providers/sarif/appscan/AppScanRuleSarifFactoryTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,11 @@ void it_parses_sarif_and_maps_java_locations(@TempDir final Path tmpDir) throws
5353

5454
// get the results for the file path (not the weird HCL thing) and confirm we have the right
5555
// results
56-
Path p = Path.of(expectedPath);
57-
List<Result> resultsForPath = ruleSarif.getResultsByLocationPath(p);
56+
List<Result> resultsForPath = ruleSarif.getResultsByLocationPath(actualAssignmentedJavaFilePath);
5857
assertThat(resultsForPath).isNotEmpty();
5958

6059
// get the regions affected by the given file
61-
List<Region> regions = ruleSarif.getRegionsFromResultsByRule(p);
60+
List<Region> regions = ruleSarif.getRegionsFromResultsByRule(actualAssignmentedJavaFilePath);
6261

6362
// there is an injection in two form parameters in the SQL, so these 2 share the same sink
6463
assertThat(regions).hasSize(2);

0 commit comments

Comments
 (0)