Skip to content

fix(java): mark Android test configurations as dev in gradle.lockfile - #11768

Open
Sun-Wukhan wants to merge 1 commit into
aquasecurity:mainfrom
Sun-Wukhan:fix/gradle-lockfile-android-test-configs
Open

Sun-Wukhan wants to merge 1 commit into
aquasecurity:mainfrom
Sun-Wukhan:fix/gradle-lockfile-android-test-configs

Conversation

@Sun-Wukhan

Copy link
Copy Markdown

Description

The gradle.lockfile parser marked a dependency as dev only when all of its configurations started with test (the JVM naming, e.g. testCompileClasspath). The Android Gradle Plugin names test configurations after the build variant instead, e.g. debugUnitTestRuntimeClasspath or debugAndroidTestCompileClasspath, so Android test-only dependencies (such as junit on debugUnitTest*/releaseUnitTest* classpaths) were reported as production dependencies and their vulnerabilities surfaced without --include-dev-deps.

This change treats a configuration as a test configuration when its whole name matches <variant>(UnitTest|AndroidTest)(CompileClasspath|RuntimeClasspath|AnnotationProcessorClasspath), in addition to the existing test prefix rule. The match is anchored and requires a non-empty variant prefix, so production configurations are never marked dev. The existing rule that a dependency is dev only when all of its configurations are test configurations is unchanged.

Tests: a new android.lockfile fixture covers Android-test-only dependencies (marked dev) and a mixed case with one production configuration (not dev), and a unit test covers the configuration matcher including near-miss names. Before this change the new fixture case failed with the Android test dependencies reported as Dev: false; after the change go test ./pkg/dependency/parser/gradle/lockfile/... passes.

Related issues

Checklist

  • I've read the guidelines for contributing to this repository.
  • I've followed the conventions in the PR title.
  • I've added tests that prove my fix is effective or that my feature works.
  • I've updated the documentation with the relevant information (if needed).
  • I've added usage information (if the PR introduces new options)
  • I've included a "before" and "after" example to the description (if the PR is a user interface change).

The gradle.lockfile parser marked a dependency as dev only when all of
its configurations started with "test". The Android Gradle Plugin names
test configurations after the build variant instead (e.g.
debugUnitTestRuntimeClasspath, debugAndroidTestCompileClasspath), so
Android test-only dependencies were reported as production dependencies
and their vulnerabilities surfaced without --include-dev-deps.

Treat a configuration as a test configuration when its whole name
matches <variant>(UnitTest|AndroidTest)(CompileClasspath|
RuntimeClasspath|AnnotationProcessorClasspath), in addition to the
existing "test" prefix rule.

Refs aquasecurity#11728

Signed-off-by: Navid Khan (Ali) <60997541+Sun-Wukhan@users.noreply.github.com>

This branch has not been deployed

No deployments
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.

feat(java): mark dependencies from Android test configurations in gradle.lockfile as dev

1 participant