Skip to content

Commit

Permalink
feat: expose LicenseUrl in output (#42)
Browse files Browse the repository at this point in the history
Co-authored-by: Patrick Garcia <[email protected]>
  • Loading branch information
garcipat and U52284 authored Feb 29, 2024
1 parent a8e85c5 commit 2c618a3
Show file tree
Hide file tree
Showing 289 changed files with 25,561 additions and 21,378 deletions.
2 changes: 2 additions & 0 deletions src/NuGetUtility/LicenseValidator/LicenseValidationResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ public record LicenseValidationResult(string PackageId,
INuGetVersion PackageVersion,
string? PackageProjectUrl,
string? License,
string? LicenseUrl,
LicenseInformationOrigin LicenseInformationOrigin,
List<ValidationError>? ValidationErrors = null)
{
public List<ValidationError> ValidationErrors { get; } = ValidationErrors ?? new List<ValidationError>();

public string? License { get; set; } = License;
public string? LicenseUrl { get; set; } = LicenseUrl;
public LicenseInformationOrigin LicenseInformationOrigin { get; set; } = LicenseInformationOrigin;
}
}
2 changes: 2 additions & 0 deletions src/NuGetUtility/LicenseValidator/LicenseValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ private void AddOrUpdateLicense(
info.Identity.Version,
info.ProjectUrl?.ToString(),
license,
info.LicenseUrl?.AbsoluteUri,
origin,
new List<ValidationError> { error });
result.AddOrUpdate(new LicenseNameAndVersion(info.Identity.Id, info.Identity.Version),
Expand All @@ -97,6 +98,7 @@ private void AddOrUpdateLicense(
info.Identity.Version,
info.ProjectUrl?.ToString(),
license,
info.LicenseUrl?.AbsoluteUri,
origin);
result.AddOrUpdate(new LicenseNameAndVersion(info.Identity.Id, info.Identity.Version),
newValue,
Expand Down
1 change: 1 addition & 0 deletions src/NuGetUtility/Output/Table/TableOutputFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public async Task Write(Stream stream, IList<LicenseValidationResult> results)
new ColumnDefinition("Version", license => license.PackageVersion, license => true, true),
new ColumnDefinition("License Information Origin", license => license.LicenseInformationOrigin, license => true, true),
new ColumnDefinition("License Expression", license => license.License, license => license.License != null),
new ColumnDefinition("License Url", license => license.LicenseUrl, license => license.LicenseUrl != null),
new ColumnDefinition("Package Project Url",license => license.PackageProjectUrl, license => license.PackageProjectUrl != null),
errorColumnDefinition,
new ColumnDefinition("Error Context", license => license.ValidationErrors.Select(e => e.Context), license => license.ValidationErrors.Any()),
Expand Down
19 changes: 19 additions & 0 deletions tests/NuGetUtility.Test/LicenseValidator/LicenseValidatorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ public async Task ValidatingLicenses_Should_IgnorePackage_If_PackageNameMatchesE
packageVersion,
_projectUrl.ToString(),
null,
null,
LicenseInformationOrigin.Ignored)
})
.Using(new LicenseValidationResultValueEqualityComparer()));
Expand Down Expand Up @@ -149,6 +150,7 @@ public async Task ValidatingLicenses_Should_NotIgnorePackage_If_PackageNameDoesN
packageVersion,
_projectUrl.ToString(),
license,
null,
LicenseInformationOrigin.Expression)
})
.Using(new LicenseValidationResultValueEqualityComparer()));
Expand Down Expand Up @@ -179,6 +181,7 @@ public async Task ValidatingLicenses_Should_IgnorePackage_If_IgnoreWildcardMatch
packageVersion,
_projectUrl.ToString(),
null,
null,
LicenseInformationOrigin.Ignored)
})
.Using(new LicenseValidationResultValueEqualityComparer()));
Expand Down Expand Up @@ -209,6 +212,7 @@ public async Task ValidatingLicenses_Should_IgnorePackage_If_IgnoreWildcardMatch
packageVersion,
_projectUrl.ToString(),
null,
null,
LicenseInformationOrigin.Ignored)
})
.Using(new LicenseValidationResultValueEqualityComparer()));
Expand Down Expand Up @@ -240,6 +244,7 @@ public async Task ValidatingLicenses_Should_IgnorePackage_If_IgnoreWildcardMatch
packageVersion,
_projectUrl.ToString(),
null,
null,
LicenseInformationOrigin.Ignored)
})
.Using(new LicenseValidationResultValueEqualityComparer()));
Expand Down Expand Up @@ -267,6 +272,7 @@ public async Task ValidatingLicenses_Should_IgnorePackage_If_IgnoreWildcardMatch
packageVersion,
_projectUrl.ToString(),
null,
null,
LicenseInformationOrigin.Ignored)
})
.Using(new LicenseValidationResultValueEqualityComparer()));
Expand Down Expand Up @@ -295,6 +301,7 @@ public async Task ValidatingLicensesWithExpressionLicenseInformation_Should_Give
packageVersion,
_projectUrl.ToString(),
license,
null,
LicenseInformationOrigin.Expression)
})
.Using(new LicenseValidationResultValueEqualityComparer()));
Expand Down Expand Up @@ -323,6 +330,7 @@ public async Task ValidatingLicensesWithOverwriteLicenseInformation_Should_GiveC
packageVersion,
_projectUrl.ToString(),
license,
null,
LicenseInformationOrigin.Overwrite)
})
.Using(new LicenseValidationResultValueEqualityComparer()));
Expand Down Expand Up @@ -360,6 +368,7 @@ public async Task ValidatingLicensesWithMatchingLicenseUrl_Should_GiveCorrectVal
packageVersion,
_projectUrl.ToString(),
mappingLicense.Value,
mappingLicense.Key.AbsoluteUri,
LicenseInformationOrigin.Url)
})
.Using(new LicenseValidationResultValueEqualityComparer()));
Expand Down Expand Up @@ -388,6 +397,7 @@ public async Task ValidatingLicensesWithMatchingLicenseUrl_Should_GiveCorrectVal
packageVersion,
_projectUrl.ToString(),
licenseUrl.ToString(),
licenseUrl.ToString(),
LicenseInformationOrigin.Url)
})
.Using(new LicenseValidationResultValueEqualityComparer()));
Expand Down Expand Up @@ -419,6 +429,7 @@ public async Task ValidatingLicensesWithNotSupportedLicenseMetadata_Should_GiveC
packageVersion,
_projectUrl.ToString(),
null,
null,
LicenseInformationOrigin.Unknown,
new List<ValidationError>
{
Expand Down Expand Up @@ -451,6 +462,7 @@ public async Task ValidatingLicensesWithoutLicenseInformation_Should_GiveCorrect
packageVersion,
_projectUrl.ToString(),
null,
null,
LicenseInformationOrigin.Unknown,
new List<ValidationError>
{
Expand Down Expand Up @@ -479,6 +491,7 @@ public async Task ValidatingLicensesWithExpressionLicenseInformation_Should_Give
packageVersion,
_projectUrl.ToString(),
license,
null,
LicenseInformationOrigin.Expression,
new List<ValidationError>
{
Expand Down Expand Up @@ -507,6 +520,7 @@ public async Task ValidatingLicensesWithOverwriteLicenseInformation_Should_GiveC
packageVersion,
_projectUrl.ToString(),
license,
null,
LicenseInformationOrigin.Overwrite,
new List<ValidationError>
{
Expand Down Expand Up @@ -535,6 +549,7 @@ public async Task ValidatingLicensesWithExpressionLicenseInformation_Should_Give
packageVersion,
_projectUrl.ToString(),
validLicense,
null,
LicenseInformationOrigin.Expression)
})
.Using(new LicenseValidationResultValueEqualityComparer()));
Expand All @@ -558,6 +573,7 @@ public async Task ValidatingLicensesWithOverwriteLicenseInformation_Should_GiveC
packageVersion,
_projectUrl.ToString(),
validLicense,
null,
LicenseInformationOrigin.Overwrite)
})
.Using(new LicenseValidationResultValueEqualityComparer()));
Expand All @@ -581,6 +597,7 @@ public async Task ValidatingLicensesWithMatchingUrlInformation_Should_GiveCorrec
packageVersion,
_projectUrl.ToString(),
urlMatch.Value,
urlMatch.Key.AbsoluteUri,
LicenseInformationOrigin.Url,
new List<ValidationError>
{
Expand Down Expand Up @@ -648,6 +665,7 @@ public async Task ValidatingLicensesWithMatchingUrlInformation_Should_GiveCorrec
packageVersion,
_projectUrl.ToString(),
urlMatch.Value,
urlMatch.Key.AbsoluteUri,
LicenseInformationOrigin.Url)
})
.Using(new LicenseValidationResultValueEqualityComparer()));
Expand All @@ -671,6 +689,7 @@ public async Task ValidatingLicensesWithNotMatchingUrlInformation_Should_GiveCor
packageVersion,
_projectUrl.ToString(),
licenseUrl.ToString(),
licenseUrl.ToString(),
LicenseInformationOrigin.Url,
new List<ValidationError>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"PackageId":"Principal Functionality Agent","PackageVersion":"1.5.3","ValidationErrors":[{"Error":"Judson","Context":"https://wilson.net"},{"Error":"Guadalupe","Context":"http://otho.info"},{"Error":"General","Context":"https://skylar.name"},{"Error":"Haylie","Context":"http://audreanne.info"}],"License":"connecting the firewall won\u0027t do anything, we need to copy the digital XSS firewall!","LicenseInformationOrigin":0}]
[{"PackageId":"Principal Functionality Agent","PackageVersion":"1.5.3","ValidationErrors":[{"Error":"Paige","Context":"https://remington.info"},{"Error":"Aletha","Context":"https://isobel.info"},{"Error":"Pearline","Context":"https://johnathon.info"},{"Error":"Eleanora","Context":"http://jaeden.info"},{"Error":"Nikolas","Context":"https://daphney.net"},{"Error":"Oceane","Context":"http://clifton.com"},{"Error":"Francisco","Context":"http://bessie.com"}],"License":"connecting the firewall won\u0027t do anything, we need to copy the digital XSS firewall!","LicenseInformationOrigin":0}]
Loading

0 comments on commit 2c618a3

Please sign in to comment.