Skip to content

Commit 82256ac

Browse files
ruromeroclaude
andauthored
fix: filter toolchain entries in GoModulesProvider (#387)
## Summary - `isGoToolchainEntry()` now filters both `go@*` and `toolchain@*` entries from Go SBOMs, aligning with the JS client's `isSpecialGoModule()` behavior - Added unit test verifying both entry types are filtered while normal modules pass through Closes [TC-3919](https://redhat.atlassian.net/browse/TC-3919) ## Test plan - [x] Unit test `test_isGoToolchainEntry_filters_go_and_toolchain` passes - [ ] `mvn verify` passes - [ ] Integration tests pass 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 79d8d54 commit 82256ac

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

src/main/java/io/github/guacsec/trustifyda/providers/GoModulesProvider.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -394,10 +394,10 @@ private static List<String> collectAllDirectDependencies(List<String> targetLine
394394
.collect(Collectors.toList());
395395
}
396396

397-
private static boolean isGoToolchainEntry(String dependency) {
398-
// Filter out Go toolchain entries like "go@1.18", "go@1.19", etc.
399-
// These are not actual dependencies but the Go toolchain itself
400-
return dependency.startsWith("go@");
397+
static boolean isGoToolchainEntry(String dependency) {
398+
// Filter out Go toolchain entries like "go@1.18" and "toolchain@go1.21.0".
399+
// These are not actual dependencies but the Go toolchain itself.
400+
return dependency.startsWith("go@") || dependency.startsWith("toolchain@");
401401
}
402402

403403
private String buildGoModulesDependencies(Path manifestPath) {

src/test/java/io/github/guacsec/trustifyda/providers/Golang_Modules_Provider_Test.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,19 @@ void Test_Golang_MvS_Logic_Disabled() throws IOException {
198198
== 1);
199199
}
200200

201+
@Test
202+
void test_isGoToolchainEntry_filters_go_and_toolchain() {
203+
// go@* entries should be filtered
204+
assertThat(GoModulesProvider.isGoToolchainEntry("go@1.18")).isTrue();
205+
assertThat(GoModulesProvider.isGoToolchainEntry("go@1.21.0")).isTrue();
206+
// toolchain@* entries should be filtered
207+
assertThat(GoModulesProvider.isGoToolchainEntry("toolchain@go1.21.0")).isTrue();
208+
assertThat(GoModulesProvider.isGoToolchainEntry("toolchain@go1.22.2")).isTrue();
209+
// normal module entries should NOT be filtered
210+
assertThat(GoModulesProvider.isGoToolchainEntry("github.com/spf13/cobra@v0.0.5")).isFalse();
211+
assertThat(GoModulesProvider.isGoToolchainEntry("golang.org/x/tools@v0.1.0")).isFalse();
212+
}
213+
201214
private String dropIgnoredKeepFormat(String s) {
202215
return s.replaceAll("goarch=\\w+&goos=\\w+&", "")
203216
.replaceAll("\"timestamp\" : \"[a-zA-Z0-9\\-\\:]+\",\n ", "");

0 commit comments

Comments
 (0)