Commit e8921c8
fix(go): distinguish direct from indirect dependencies (guacsec#449)
## Summary
- Fix Go provider to correctly distinguish direct from indirect
dependencies using `go mod edit -json` parsing, matching the JS client
behavior
- Since Go 1.17, `go mod tidy` records all transitively-imported modules
in `go.mod` as `require` entries with `// indirect`, and `go mod graph`
emits root-level edges for all of them — the Java client was treating
all root-level edges as direct dependencies
- Match JS client empty SBOM structure: ensure `"components": []` is
always present and `"dependencies": []` is empty when all components are
filtered out
## Changes
**`GoModulesProvider.java`**
- Add `getDirectDependencyPaths()` — runs `go mod edit -json`, parses
the `Require` array, returns the set of non-indirect module paths
- Filter root-level edges in both `buildSbomFromGraph()` and
`buildSbomFromList()` to only include direct dependencies
**`CycloneDXSbom.java`**
- Clear dependencies list when all components are filtered out (matches
JS client)
- Post-process JSON to ensure `"components"` key is always present
(CycloneDX library omits empty collections)
## Test plan
- [x] Updated expected SBOM fixtures for `go_mod_light_no_ignore`,
`go_mod_no_ignore`, `go_mod_with_ignore`, `go_mod_with_all_ignore`, and
`msc/golang/mvs_logic`
- [x] Verified fixture parity with JS client test expectations
- [ ] Unit tests (blocked by pre-existing `NoClassDefFoundError` in
`cyclonedx-core-java` 12.1.0 JPMS module setup — exists on `main`)
Closes [TC-4300](https://redhat.atlassian.net/browse/TC-4300)
Related to [TC-3818](https://redhat.atlassian.net/browse/TC-3818)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
[TC-4300]:
https://redhat.atlassian.net/browse/TC-4300?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
## Summary by Sourcery
Correct Go module SBOM generation to only include direct dependencies
and align CycloneDX JSON output structure with other clients, while
updating automation config and documentation.
Bug Fixes:
- Ensure Go SBOMs treat only non-indirect Go modules as direct
dependencies when building both list and graph-based dependency views.
- Make generated CycloneDX JSON SBOMs always include an empty components
array and clear dependencies when all components are filtered out,
matching expected consumer behavior.
Enhancements:
- Add parsing of `go mod edit -json` output to derive direct dependency
module paths for Go projects.
- Introduce helper utilities to normalize Go module graph entries by
stripping version suffixes before filtering.
Build:
- Reconfigure Dependabot ecosystems and explicitly scope Maven test
fixture directories to prevent unintended dependency updates while
keeping production Maven dependencies updatable.
Documentation:
- Add a CONVENTIONS.md documenting project-specific coding standards,
structure, testing practices, and dependency management guidelines.
Tests:
- Update Go SBOM JSON fixtures to reflect the new handling of direct
dependencies and empty component sets in generated SBOMs.
---------
Signed-off-by: Ruben Romero Montes <rromerom@redhat.com>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>1 parent 2786440 commit e8921c8
18 files changed
Lines changed: 1119 additions & 2120 deletions
File tree
- src
- main/java/io/github/guacsec/trustifyda
- providers
- sbom
- test/resources
- msc/golang/mvs_logic
- tst_manifests
- golang
- go_mod_light_no_ignore
- go_mod_no_ignore
- go_mod_with_all_ignore
- go_mod_with_ignore
- maven
- deps_with_ignore_on_artifact
- deps_with_ignore_on_dependency
- deps_with_ignore_on_group
- deps_with_ignore_on_version
Lines changed: 77 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
21 | 24 | | |
22 | 25 | | |
23 | 26 | | |
| |||
40 | 43 | | |
41 | 44 | | |
42 | 45 | | |
| 46 | + | |
43 | 47 | | |
44 | 48 | | |
45 | 49 | | |
| 50 | + | |
46 | 51 | | |
47 | 52 | | |
48 | 53 | | |
| |||
136 | 141 | | |
137 | 142 | | |
138 | 143 | | |
| 144 | + | |
139 | 145 | | |
140 | 146 | | |
141 | 147 | | |
142 | 148 | | |
143 | 149 | | |
144 | 150 | | |
145 | 151 | | |
146 | | - | |
| 152 | + | |
147 | 153 | | |
148 | | - | |
| 154 | + | |
149 | 155 | | |
150 | 156 | | |
151 | 157 | | |
| |||
264 | 270 | | |
265 | 271 | | |
266 | 272 | | |
267 | | - | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
268 | 277 | | |
269 | 278 | | |
270 | 279 | | |
| |||
300 | 309 | | |
301 | 310 | | |
302 | 311 | | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
303 | 323 | | |
304 | 324 | | |
305 | 325 | | |
| |||
422 | 442 | | |
423 | 443 | | |
424 | 444 | | |
425 | | - | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
426 | 498 | | |
427 | 499 | | |
428 | 500 | | |
| |||
433 | 505 | | |
434 | 506 | | |
435 | 507 | | |
| 508 | + | |
436 | 509 | | |
437 | 510 | | |
438 | 511 | | |
| |||
Lines changed: 32 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
21 | 24 | | |
22 | 25 | | |
23 | 26 | | |
| |||
67 | 70 | | |
68 | 71 | | |
69 | 72 | | |
70 | | - | |
71 | 73 | | |
| 74 | + | |
72 | 75 | | |
73 | 76 | | |
74 | 77 | | |
| |||
230 | 233 | | |
231 | 234 | | |
232 | 235 | | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
233 | 239 | | |
234 | 240 | | |
235 | 241 | | |
| |||
302 | 308 | | |
303 | 309 | | |
304 | 310 | | |
| 311 | + | |
305 | 312 | | |
306 | 313 | | |
307 | 314 | | |
308 | 315 | | |
309 | 316 | | |
310 | | - | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
311 | 341 | | |
312 | 342 | | |
313 | 343 | | |
| |||
Lines changed: 1 addition & 39 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3989 | 3989 | | |
3990 | 3990 | | |
3991 | 3991 | | |
3992 | | - | |
3993 | | - | |
3994 | 3992 | | |
3995 | | - | |
3996 | | - | |
3997 | | - | |
3998 | | - | |
3999 | | - | |
4000 | | - | |
4001 | | - | |
4002 | | - | |
4003 | | - | |
4004 | 3993 | | |
4005 | | - | |
4006 | 3994 | | |
4007 | | - | |
4008 | | - | |
4009 | 3995 | | |
4010 | | - | |
4011 | | - | |
4012 | | - | |
4013 | | - | |
4014 | | - | |
4015 | | - | |
4016 | | - | |
4017 | | - | |
4018 | | - | |
4019 | | - | |
4020 | | - | |
4021 | | - | |
4022 | | - | |
4023 | | - | |
4024 | | - | |
4025 | | - | |
4026 | 3996 | | |
4027 | | - | |
4028 | | - | |
4029 | 3997 | | |
4030 | | - | |
4031 | | - | |
4032 | | - | |
4033 | | - | |
4034 | | - | |
4035 | | - | |
4036 | | - | |
| 3998 | + | |
4037 | 3999 | | |
4038 | 4000 | | |
4039 | 4001 | | |
| |||
Lines changed: 2 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | 32 | | |
41 | 33 | | |
42 | 34 | | |
43 | 35 | | |
44 | 36 | | |
45 | 37 | | |
46 | 38 | | |
47 | | - | |
48 | | - | |
| 39 | + | |
49 | 40 | | |
50 | 41 | | |
51 | 42 | | |
| |||
55 | 46 | | |
56 | 47 | | |
57 | 48 | | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | 49 | | |
63 | 50 | | |
64 | | - | |
| 51 | + | |
Lines changed: 1 addition & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
315 | 315 | | |
316 | 316 | | |
317 | 317 | | |
318 | | - | |
319 | | - | |
| 318 | + | |
320 | 319 | | |
321 | 320 | | |
322 | 321 | | |
| |||
0 commit comments