Skip to content

fix(maven): exclude test-scoped deps in component analysis - #583

Open
a-oren wants to merge 1 commit into
guacsec:mainfrom
a-oren:worktree-TC-6264
Open

a-oren wants to merge 1 commit into
guacsec:mainfrom
a-oren:worktree-TC-6264

Conversation

@a-oren

@a-oren a-oren commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Summary

The Maven component-analysis path leaked test-scoped dependencies into the SBOM sent to the backend, unlike the JavaScript client which excludes them.

generateSbomFromEffectivePom() excluded test deps by matching effective-pom deps against test deps read from the original pom using the version-sensitive DependencyAggregator.equals(). Parent/BOM-managed test deps (e.g. spring-boot-starter-test) have version == null in the source pom but a resolved version in the effective pom, so the match failed and the test dep leaked.

Fix: filter the effective-pom stream by each dependency's own isTestDependency() scope, which is version-independent and mirrors the JS client. Scope is test onlyprovided filtering is intentionally out of scope.

Changes

  • JavaMavenProvider.generateSbomFromEffectivePom(): replace the version-sensitive testsDeps.contains(dep) match with a direct !dep.isTestDependency() scope filter; drop the now-unused original-pom testsDeps computation.
  • pom_deps_with_no_ignore_common_paths/expected_component_sbom.json: drop the leaked spring-boot-starter-test@2.3.5.RELEASE entry (7 → 6 deps).

Testing

  • mvn test — all 98 tests pass. The existing parameterized test_the_provideComponent / test_the_provideComponent_With_Path now assert the corrected 6-dep output for pom_deps_with_no_ignore_common_paths; pom_deps_with_no_ignore_provided_scope remains unchanged (provided dep still included).

Implements TC-6264

🤖 Generated with Claude Code

Summary by Sourcery

Filter Maven component analysis by effective dependency scope to prevent test dependencies from leaking into generated SBOMs.

Bug Fixes:

  • Exclude test-scoped Maven dependencies from component SBOMs, including parent- or BOM-managed dependencies whose versions are resolved only in the effective POM.

Tests:

  • Update Maven component SBOM expectations to verify that test dependencies are excluded while provided-scope dependencies remain included.

generateSbomFromEffectivePom() excluded test deps by matching effective-pom
deps against original-pom test deps via version-sensitive equals(). Parent/BOM
-managed test deps (version null in source pom, resolved in effective pom) did
not match and leaked into the SBOM. Filter the effective-pom stream by its own
isTestDependency() scope instead, which is version-independent and mirrors the
JS client.

Implements TC-6264

Assisted-by: Claude Code
@sourcery-ai

sourcery-ai Bot commented Sep 16, 2026

Copy link
Copy Markdown
Contributor
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

The Maven component-analysis path now excludes test-scoped dependencies directly from the effective POM, fixing leaks caused by version-sensitive matching against source-POM dependencies while intentionally retaining provided-scope dependencies. The expected SBOM fixture and associated assertions now validate the six-dependency output.

Flow diagram for Maven dependency filtering

flowchart TD
    A["Effective POM dependencies"] --> B["resolveVersionRanges(deps)"]
    B --> C{"dep.isTestDependency()?"}
    C -->|Yes| D["Exclude from SBOM"]
    C -->|No| E["DependencyAggregator.toPurl"]
    E --> F{"Ignored dependency?"}
    F -->|Yes| G["Exclude from SBOM"]
    F -->|No| H["Add dependency to SBOM"]
    I["Provided-scope dependency"] --> E
Loading

File-Level Changes

Change Details Files
Filter test-scoped dependencies using the resolved dependency’s own scope during effective-POM SBOM generation.
  • Remove the original-POM test dependency collection.
  • Exclude dependencies via isTestDependency(), avoiding version-sensitive equality failures for parent- or BOM-managed dependencies.
  • Preserve existing ignore filtering and inclusion of provided-scope dependencies.
src/main/java/io/github/guacsec/trustifyda/providers/JavaMavenProvider.java
Update the component SBOM fixture to reflect exclusion of the leaked test dependency.
  • Remove spring-boot-starter-test@2.3.5.RELEASE from the expected output.
  • Update the expected dependency count from seven to six.
src/test/resources/tst_manifests/maven/pom_deps_with_no_ignore_common_paths/expected_component_sbom.json

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@a-oren
a-oren requested a review from Strum355 September 16, 2026 08:19

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!

Sourcery assessment

Needs a human reviewer. If the effective-POM scope check is wrong, the generated SBOM could omit a real runtime dependency or include a test-only dependency, causing inaccurate component or vulnerability analysis. The affected SBOMs can be regenerated after reverting or correcting the change, so the error is bounded and repairable.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (main@e1f3a82). Learn more about missing BASE report.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #583   +/-   ##
=======================================
  Coverage        ?   69.24%           
  Complexity      ?     1040           
=======================================
  Files           ?       66           
  Lines           ?     4367           
  Branches        ?      774           
=======================================
  Hits            ?     3024           
  Misses          ?     1000           
  Partials        ?      343           
Flag Coverage Δ
integration-tests 69.24% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants