-
Notifications
You must be signed in to change notification settings - Fork 11
fix(license): treat UNKNOWN-category dependencies as incompatible #513
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
a-oren
wants to merge
1
commit into
guacsec:main
Choose a base branch
from
a-oren:TC-4707
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
src/test/java/io/github/guacsec/trustifyda/license/License_Compatibility_Test.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| /* | ||
| * Copyright 2023-2025 Trustify Dependency Analytics Authors | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package io.github.guacsec.trustifyda.license; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| import io.github.guacsec.trustifyda.api.v5.LicenseCategory; | ||
| import io.github.guacsec.trustifyda.license.LicenseUtils.Compatibility; | ||
| import java.util.stream.Stream; | ||
| import org.junit.jupiter.api.Nested; | ||
| import org.junit.jupiter.params.ParameterizedTest; | ||
| import org.junit.jupiter.params.provider.Arguments; | ||
| import org.junit.jupiter.params.provider.EnumSource; | ||
| import org.junit.jupiter.params.provider.MethodSource; | ||
|
|
||
| /** Tests for {@link LicenseUtils#getCompatibility} with UNKNOWN category handling. */ | ||
| class License_Compatibility_Test { | ||
|
|
||
| @Nested | ||
| class Unknown_Dependency_Category { | ||
|
|
||
| /** Known project + UNKNOWN dependency should be INCOMPATIBLE. */ | ||
| @ParameterizedTest | ||
| @EnumSource( | ||
| value = LicenseCategory.class, | ||
| names = {"PERMISSIVE", "WEAK_COPYLEFT", "STRONG_COPYLEFT"}) | ||
| void known_project_and_unknown_dependency_returns_incompatible( | ||
| LicenseCategory projectCategory) { | ||
| // When | ||
| Compatibility result = | ||
| LicenseUtils.getCompatibility(projectCategory, LicenseCategory.UNKNOWN); | ||
|
|
||
| // Then | ||
| assertThat(result).isEqualTo(Compatibility.INCOMPATIBLE); | ||
| } | ||
| } | ||
|
|
||
| @Nested | ||
| class Unknown_Project_Category { | ||
|
|
||
| /** UNKNOWN project category should always return UNKNOWN. */ | ||
| @ParameterizedTest | ||
| @EnumSource(LicenseCategory.class) | ||
| void unknown_project_returns_unknown(LicenseCategory dependencyCategory) { | ||
| // When | ||
| Compatibility result = | ||
| LicenseUtils.getCompatibility(LicenseCategory.UNKNOWN, dependencyCategory); | ||
|
|
||
| // Then | ||
| assertThat(result).isEqualTo(Compatibility.UNKNOWN); | ||
| } | ||
|
|
||
| /** Null project category should return UNKNOWN. */ | ||
| @ParameterizedTest | ||
| @EnumSource(LicenseCategory.class) | ||
| void null_project_returns_unknown(LicenseCategory dependencyCategory) { | ||
| // When | ||
| Compatibility result = LicenseUtils.getCompatibility(null, dependencyCategory); | ||
|
|
||
| // Then | ||
| assertThat(result).isEqualTo(Compatibility.UNKNOWN); | ||
| } | ||
| } | ||
|
|
||
| @Nested | ||
| class Known_Categories { | ||
|
|
||
| /** Existing compatibility logic for known categories remains unchanged. */ | ||
| @ParameterizedTest | ||
| @MethodSource( | ||
| "io.github.guacsec.trustifyda.license.License_Compatibility_Test#knownCategoryPairs") | ||
| void known_categories_preserve_existing_behavior( | ||
| LicenseCategory project, LicenseCategory dependency, Compatibility expected) { | ||
| // When | ||
| Compatibility result = LicenseUtils.getCompatibility(project, dependency); | ||
|
|
||
| // Then | ||
| assertThat(result).isEqualTo(expected); | ||
| } | ||
| } | ||
|
|
||
| static Stream<Arguments> knownCategoryPairs() { | ||
| return Stream.of( | ||
| // Same restrictiveness → compatible | ||
| Arguments.of( | ||
| LicenseCategory.PERMISSIVE, LicenseCategory.PERMISSIVE, Compatibility.COMPATIBLE), | ||
| Arguments.of( | ||
| LicenseCategory.WEAK_COPYLEFT, LicenseCategory.WEAK_COPYLEFT, Compatibility.COMPATIBLE), | ||
| Arguments.of( | ||
| LicenseCategory.STRONG_COPYLEFT, | ||
| LicenseCategory.STRONG_COPYLEFT, | ||
| Compatibility.COMPATIBLE), | ||
| // Less restrictive dependency → compatible | ||
| Arguments.of( | ||
| LicenseCategory.STRONG_COPYLEFT, LicenseCategory.PERMISSIVE, Compatibility.COMPATIBLE), | ||
| Arguments.of( | ||
| LicenseCategory.STRONG_COPYLEFT, | ||
| LicenseCategory.WEAK_COPYLEFT, | ||
| Compatibility.COMPATIBLE), | ||
| Arguments.of( | ||
| LicenseCategory.WEAK_COPYLEFT, LicenseCategory.PERMISSIVE, Compatibility.COMPATIBLE), | ||
| // More restrictive dependency → incompatible | ||
| Arguments.of( | ||
| LicenseCategory.PERMISSIVE, LicenseCategory.WEAK_COPYLEFT, Compatibility.INCOMPATIBLE), | ||
| Arguments.of( | ||
| LicenseCategory.PERMISSIVE, | ||
| LicenseCategory.STRONG_COPYLEFT, | ||
| Compatibility.INCOMPATIBLE), | ||
| Arguments.of( | ||
| LicenseCategory.WEAK_COPYLEFT, | ||
| LicenseCategory.STRONG_COPYLEFT, | ||
| Compatibility.INCOMPATIBLE)); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (testing): Add tests for null dependency category to fully cover the null-handling branch
The implementation returns
Compatibility.UNKNOWNwhen eitherprojectCategoryordependencyCategoryisnull, but tests only cover thenullproject case. Please also add parameterized tests for:getCompatibility(projectCategory, null)for each non-null project category (includingUNKNOWN).getCompatibility(null, null)explicitly.This will fully cover the null-handling branch and protect against regressions.
Suggested implementation:
If
@Testis not already imported in this test class, add:import org.junit.jupiter.api.Test;near the other JUnit imports.