-
Notifications
You must be signed in to change notification settings - Fork 187
Validate compliance standard for SPDX 3.0 #992
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
Merged
Merged
Changes from 26 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
0dae98b
improve compliance standard validation + add more unit tests
ca673f4
update unit tests
1cf3cee
move compliance standard validation to config sanitizer + add unit tests
23ceac3
add e2e tests
ce44787
add validation workflow UT
ca43bcd
merge conflict
d2875d2
punctuation
7d77802
revert to main version
438ceac
fix UTs + revert extra integrationtests changes
d5921c8
fix ut
69fa772
fix e2e tests
c7c6a3e
add support for none compliance standard
3e6df30
reword compliance standard error type to make it more generic
f93902a
fix tests
02cb33a
update error message
3d88351
updating errors and messaging
9af76aa
remove extra double quotes, fix punctuation
533d843
fix grammar
ba1eec8
fix error message
bb4a9e5
grammar
6a5c128
update unit test and remove quotes
2c7e84f
Refactor compliance standard validation (#993)
pragnya17 81d21cb
Merge branch 'main' into ppandrate_complianceStandardValidation
pragnya17 badd8bc
simplify method
defe97d
Merge branch 'ppandrate_complianceStandardValidation' of https://gith…
10ead12
Merge branch 'main' into ppandrate_complianceStandardValidation
pragnya17 544771c
Merge branch 'main' into ppandrate_complianceStandardValidation
pragnya17 75cbb91
fix merge conflict errors
331cc06
fix merge conflict errors
35415ad
update e2e test
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
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
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
35 changes: 35 additions & 0 deletions
35
....Sbom.Api/Config/ValueConverters/ComplianceStandardConfigurationSettingAddingConverter.cs
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,35 @@ | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
| // Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
|
||
| using AutoMapper; | ||
| using Microsoft.Sbom.Common.Config; | ||
| using Microsoft.Sbom.Contracts.Enums; | ||
|
|
||
| namespace Microsoft.Sbom.Api.Config.ValueConverters; | ||
|
|
||
| /// <summary> | ||
| /// Converts a ComplianceStandard member to a ConfigurationSetting decorated string member. | ||
| /// </summary> | ||
| internal class ComplianceStandardConfigurationSettingAddingConverter : IValueConverter<ComplianceStandardType?, ConfigurationSetting<ComplianceStandardType>> | ||
| { | ||
| private SettingSource settingSource; | ||
|
|
||
| public ComplianceStandardConfigurationSettingAddingConverter(SettingSource settingSource) | ||
| { | ||
| this.settingSource = settingSource; | ||
| } | ||
|
|
||
| public ConfigurationSetting<ComplianceStandardType> Convert(ComplianceStandardType? sourceMember, ResolutionContext context) | ||
| { | ||
| if (sourceMember == null) | ||
| { | ||
| settingSource = SettingSource.Default; | ||
| } | ||
|
|
||
| return new ConfigurationSetting<ComplianceStandardType> | ||
| { | ||
| Source = settingSource, | ||
| Value = sourceMember ?? ComplianceStandardType.None | ||
| }; | ||
| } | ||
| } |
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
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
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
24 changes: 24 additions & 0 deletions
24
src/Microsoft.Sbom.Common/ComplianceStandard/ComplianceExtensions.cs
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,24 @@ | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
| // Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
|
||
| namespace Microsoft.Sbom.Common.ComplianceStandard; | ||
|
|
||
| internal static class ComplianceExtensions | ||
| { | ||
| /// <summary> | ||
| /// Gets the common entity type that is used by the parser. | ||
| /// </summary> | ||
| internal static string GetCommonEntityType(this string entityType) | ||
| { | ||
| // For these special cases, remove the prefix from the type. | ||
| switch (entityType) | ||
| { | ||
| case "software_File": | ||
| return "File"; | ||
| case "software_Package": | ||
| return "Package"; | ||
| default: | ||
| return entityType; | ||
| } | ||
| } | ||
| } |
21 changes: 21 additions & 0 deletions
21
src/Microsoft.Sbom.Common/ComplianceStandard/ComplianceStandardEnforcerFactory.cs
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,21 @@ | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
| // Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
|
||
| using System; | ||
| using Microsoft.Sbom.Contracts.Enums; | ||
| using Microsoft.Sbom.Parsers.Spdx30SbomParser.ComplianceStandard.Interfaces; | ||
|
|
||
| namespace Microsoft.Sbom.Common.ComplianceStandard; | ||
|
|
||
| public static class ComplianceStandardEnforcerFactory | ||
| { | ||
| public static IComplianceStandardEnforcer Create(ComplianceStandardType complianceStandard) | ||
| { | ||
| return complianceStandard.Name switch | ||
| { | ||
| "NTIA" => new NTIAComplianceStandardEnforcer(), | ||
| "None" => new NoneComplianceStandardEnforcer(), | ||
| _ => throw new ArgumentException($"Unsupported compliance standard: {complianceStandard.Name}") | ||
| }; | ||
| } | ||
| } |
50 changes: 50 additions & 0 deletions
50
src/Microsoft.Sbom.Common/ComplianceStandard/Enums/NTIAErrorType.cs
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,50 @@ | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
| // Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
|
||
| using System; | ||
| using Microsoft.Sbom.Parsers.Spdx30SbomParser.ComplianceStandard.Interfaces; | ||
|
|
||
| namespace Microsoft.Sbom.Common.ComplianceStandard.Enums; | ||
|
|
||
| public class NTIAErrorType : IComplianceStandardErrorType, IEquatable<NTIAErrorType> | ||
| { | ||
| public string Name { get; set; } | ||
|
|
||
| public NTIAErrorType(string name) | ||
| { | ||
| Name = name; | ||
| } | ||
|
|
||
| public override string ToString() | ||
| { | ||
| return Name ?? string.Empty; | ||
| } | ||
|
|
||
| public override bool Equals(object obj) | ||
| { | ||
| return Equals(obj as NTIAErrorType); | ||
| } | ||
|
|
||
| public bool Equals(NTIAErrorType other) | ||
| { | ||
| if (other == null) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| return string.Equals(Name, other.Name, StringComparison.OrdinalIgnoreCase); | ||
| } | ||
|
|
||
| public static NTIAErrorType InvalidNTIAElement => new NTIAErrorType("InvalidNTIAElement"); | ||
|
|
||
| public static NTIAErrorType MissingValidSpdxDocument => new NTIAErrorType("MissingValidSpdxDocument"); | ||
|
|
||
| public static NTIAErrorType AdditionalSpdxDocument => new NTIAErrorType("AdditionalSpdxDocument"); | ||
|
|
||
| public static NTIAErrorType MissingValidCreationInfo => new NTIAErrorType("MissingValidCreationInfo"); | ||
|
|
||
| public override int GetHashCode() | ||
| { | ||
| return Name == null ? 0 : Name.GetHashCode(StringComparison.OrdinalIgnoreCase); | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.