Skip to content

Commit a019e34

Browse files
committed
Remove logic to validate licenses
This is to ensure compatibility to parse licenses for 1.3 & 1.4. Validation for 1.5 needs to be done separately. * remove tests for license choice Signed-off-by: Sebastian Ziebell <[email protected]>
1 parent 1b4b592 commit a019e34

File tree

3 files changed

+1
-99
lines changed

3 files changed

+1
-99
lines changed

cyclonedx-bom/src/models/license.rs

Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
* SPDX-License-Identifier: Apache-2.0
1717
*/
1818

19-
use std::collections::HashSet;
2019
use std::convert::TryFrom;
2120

2221
use crate::external_models::spdx::SpdxIdentifierError;
@@ -27,8 +26,7 @@ use crate::external_models::{
2726
};
2827
use crate::models::attached_text::AttachedText;
2928
use crate::validation::{
30-
FailureReason, Validate, ValidationContext, ValidationError, ValidationPathComponent,
31-
ValidationResult,
29+
Validate, ValidationContext, ValidationError, ValidationPathComponent, ValidationResult,
3230
};
3331

3432
/// Represents whether a license is a named license or an SPDX license expression
@@ -165,25 +163,6 @@ impl Validate for Licenses {
165163
) -> Result<ValidationResult, ValidationError> {
166164
let mut results: Vec<ValidationResult> = vec![];
167165

168-
// Ensure all licenses are of the same variant, either "license" or "expression" but not both
169-
let result = self.0.iter().fold(HashSet::new(), |mut result, item| {
170-
result.insert(item.is_license());
171-
result
172-
});
173-
if result.len() > 1 {
174-
let licenses_context =
175-
context.extend_context(vec![ValidationPathComponent::EnumVariant {
176-
variant_name: "license".to_string(),
177-
}]);
178-
179-
results.push(ValidationResult::Failed {
180-
reasons: vec![FailureReason {
181-
message: "Use one of 'license' or 'expression' but not both.".to_string(),
182-
context: licenses_context,
183-
}],
184-
});
185-
}
186-
187166
for (index, license_choice) in self.0.iter().enumerate() {
188167
let license_choice_context =
189168
context.extend_context(vec![ValidationPathComponent::Array { index }]);
@@ -246,34 +225,6 @@ mod test {
246225
assert_eq!(validation_result, ValidationResult::Passed);
247226
}
248227

249-
#[test]
250-
fn it_should_fail_with_mixed_license_nodes() {
251-
let validation_result = Licenses(vec![
252-
LicenseChoice::License(License {
253-
license_identifier: LicenseIdentifier::Name(NormalizedString(
254-
"MIT OR Apache-2.0".to_string(),
255-
)),
256-
text: None,
257-
url: None,
258-
}),
259-
LicenseChoice::Expression(SpdxExpression("MIT OR Apache-2.0".to_string())),
260-
])
261-
.validate_with_context(ValidationContext::default())
262-
.expect("Error while validating");
263-
264-
assert_eq!(
265-
validation_result,
266-
ValidationResult::Failed {
267-
reasons: vec![FailureReason {
268-
message: "Use one of 'license' or 'expression' but not both.".to_string(),
269-
context: ValidationContext(vec![ValidationPathComponent::EnumVariant {
270-
variant_name: "license".to_string(),
271-
}]),
272-
},]
273-
}
274-
);
275-
}
276-
277228
#[test]
278229
fn it_should_fail_validation_for_license_name() {
279230
let validation_result = Licenses(vec![LicenseChoice::License(License {

cyclonedx-bom/tests/spec/1.4/invalid-license-choice-1.4.json

Lines changed: 0 additions & 23 deletions
This file was deleted.

cyclonedx-bom/tests/spec/1.4/invalid-license-choice-1.4.xml

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)