Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions Docs/known-endpoints.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ Known endpoints
List of known endpoints to which the tool can send a request:

- [opensource.org](https://opensource.org)
- [api.opensource.org](https://api.opensource.org)
- [spdx.org](https://spdx.org)
- [www.codeproject.com](https://www.codeproject.com)
- [github.com](https://github.com)
Expand All @@ -21,13 +20,6 @@ List of known endpoints to which the tool can send a request:
- [go.microsoft.com](https://go.microsoft.com)
- [www.apache.org](https://www.apache.org)

opensource.org
--------------

Depending on the license code the tool can send a request to a URL defined in the corresponding `text` section. Media type preferences: `text/plain`, `text/html`, `any other`.

For example, for the [MIT](https://api.opensource.org/license/MIT) license defined in the [index](https://api.opensource.org/licenses), the content will be downloaded from https://opensource.org/license/mit/, for [GPL-3.0](https://api.opensource.org/license/GPL-3.0) from https://www.gnu.org/licenses/gpl-3.0.txt.

codeproject
-----------

Expand Down
2 changes: 1 addition & 1 deletion Examples/export-to-csv/packages.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"Name","Version","Package Url","License","License Url","Authors","Copyright"
"chalk","5.3.0","https://www.npmjs.com/package/chalk/v/5.3.0","MIT License","https://spdx.org/licenses/MIT","",""
"chalk","5.6.2","https://www.npmjs.com/package/chalk/v/5.6.2","MIT License","https://spdx.org/licenses/MIT","",""
"DotLiquid","2.3.197","https://www.nuget.org/packages/DotLiquid/2.3.197","Apache-2.0 OR MS-PL","https://spdx.org/licenses/Apache-2.0https://spdx.org/licenses/MS-PL","Tim Jones, Alessandro Petrelli",""
"Microsoft.Bcl.AsyncInterfaces","9.0.9","https://www.nuget.org/packages/Microsoft.Bcl.AsyncInterfaces/9.0.9","MIT License","https://spdx.org/licenses/MIT","Microsoft","© Microsoft Corporation. All rights reserved."
"Microsoft.Extensions.Configuration","9.0.9","https://www.nuget.org/packages/Microsoft.Extensions.Configuration/9.0.9","MIT License","https://spdx.org/licenses/MIT","Microsoft","© Microsoft Corporation. All rights reserved."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ License MICROSOFT .NET LIBRARY, full text can be found at https://www.microsoft.
Copyright: © Microsoft Corporation. All rights reserved.

License MIT License, full text can be found at https://spdx.org/licenses/MIT or in Licenses/MIT-license.txt
chalk (https://www.npmjs.com/package/chalk/v/5.3.0)
chalk (https://www.npmjs.com/package/chalk/v/5.6.2)
Microsoft.Bcl.AsyncInterfaces (https://www.nuget.org/packages/Microsoft.Bcl.AsyncInterfaces/9.0.9)
Authors: Microsoft
Copyright: © Microsoft Corporation. All rights reserved.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Third party libraries

THIRD-PARTY SOFTWARE NOTICES AND INFORMATION

chalk (https://www.npmjs.com/package/chalk/v/5.3.0)
chalk (https://www.npmjs.com/package/chalk/v/5.6.2)
License: MIT License, full text can be found at https://spdx.org/licenses/MIT or in Licenses/chalk

DotLiquid (https://www.nuget.org/packages/DotLiquid/2.3.197)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Third party libraries

THIRD-PARTY SOFTWARE NOTICES AND INFORMATION

chalk (https://www.npmjs.com/package/chalk/v/5.3.0)
chalk (https://www.npmjs.com/package/chalk/v/5.6.2)
License: MIT License, full text can be found at https://spdx.org/licenses/MIT or in Licenses/MIT-license.txt

DotLiquid (https://www.nuget.org/packages/DotLiquid/2.3.197)
Expand Down
2 changes: 1 addition & 1 deletion Sources/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</PropertyGroup>

<PropertyGroup>
<DefaultPackageVersion>3.8.0</DefaultPackageVersion>
<DefaultPackageVersion>3.9.0</DefaultPackageVersion>

<Version>$(DefaultPackageVersion)</Version>
<AssemblyVersion>$(DefaultPackageVersion).0</AssemblyVersion>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,79 +1,63 @@
[
{
"id": "AAL-test",
"identifiers": [
{
"identifier": "AAL",
"scheme": "SPDX"
},
{
"identifier": "License :: OSI Approved :: Attribution Assurance License",
"scheme": "Trove"
}
"id": "apache-2-0",
"name": "Apache License, Version 2.0",
"spdx_id": "Apache-2.0",
"version": "2.0",
"submission_date": "20040208",
"submission_url": "http:\/\/lists.opensource.org\/pipermail\/license-discuss_lists.opensource.org\/2004-February\/007654.html",
"submitter_name": "Kevin Coar",
"approved": false,
"approval_date": "",
"license_steward_version": "",
"license_steward_url": "https:\/\/www.apache.org\/licenses\/LICENSE-2.0",
"board_minutes": "",
"stewards": [
"apache-software-foundation"
],
"links": [
{
"note": "OSI Page",
"url": "https://opensource.org/licenses/AAL"
}
"keywords": [
"popular-strong-community"
],
"name": "Attribution Assurance License",
"other_names": [],
"superseded_by": null,
"keywords": [ "osi-approved", "discouraged", "redundant" ],
"text": [
{
"media_type": "text/html",
"title": "HTML",
"url": "https://opensource.org/licenses/AAL"
}
]
},
{
"id": "Apache-2.0",
"identifiers": [
{
"identifier": "Apache-2.0",
"scheme": "DEP5"
"_links": {
"self": {
"href": "https:\/\/opensource.org\/api\/license\/apache-2-0"
},
{
"identifier": "Apache-2.0",
"scheme": "SPDX"
"html": {
"href": "https:\/\/opensource.org\/license\/apache-2-0"
},
{
"identifier": "License :: OSI Approved :: Apache Software License",
"scheme": "Trove"
"collection": {
"href": "https:\/\/opensource.org\/api\/licenses"
}
}
},
{
"id": "bsd-3-clause",
"name": "The 3-Clause BSD License",
"spdx_id": "BSD-3-Clause",
"version": "",
"submission_date": "",
"submission_url": "",
"submitter_name": "",
"approved": false,
"approval_date": "",
"license_steward_version": "",
"license_steward_url": "",
"board_minutes": "",
"stewards": [
],
"links": [
{
"note": "tl;dr legal",
"url": "https://tldrlegal.com/license/apache-license-2.0-%28apache-2.0%29"
},
{
"note": "Wikipedia page",
"url": "https://en.wikipedia.org/wiki/Apache_License"
},
{
"note": "OSI Page",
"url": "https://opensource.org/licenses/Apache-2.0"
}
"keywords": [
"popular-strong-community"
],
"name": "Apache License, Version 2.0",
"other_names": [],
"superseded_by": null,
"keywords": [ "osi-approved", "popular", "permissive" ],
"text": [
{
"media_type": "text/html",
"title": "HTML",
"url": "https://www.apache.org/licenses/LICENSE-2.0"
"_links": {
"self": {
"href": "https:\/\/opensource.org\/api\/license\/bsd-3-clause"
},
"html": {
"href": "https:\/\/opensource.org\/license\/bsd-3-clause"
},
{
"media_type": "text/plain",
"title": "Plain Text",
"url": "https://www.gnu.org/licenses/apache-2.0.txt"
"collection": {
"href": "https:\/\/opensource.org\/api\/licenses"
}
]
}
}
]
]
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using NUnit.Framework;
using RichardSzalay.MockHttp;
using Shouldly;
using ThirdPartyLibraries.Generic.Internal.Domain;

namespace ThirdPartyLibraries.Generic.Internal;

Expand All @@ -23,7 +24,7 @@ public void BeforeEachTest()
public async Task LoadIndexAsync()
{
_mockHttp
.When(HttpMethod.Get, "https://api.opensource.org/licenses/")
.When(HttpMethod.Get, "https://opensource.org/api/license/")
.Respond(
MediaTypeNames.Application.Json,
TempFile.OpenResource(GetType(), "OpenSourceOrgRepositoryTest.Index.json"));
Expand All @@ -32,100 +33,75 @@ public async Task LoadIndexAsync()

_sut.Index.ShouldNotBeNull();

_sut.Index.TryGetEntry("AAL", out var aal).ShouldBeTrue();
aal.ShouldNotBeNull();

aal.FullName.ShouldBe("Attribution Assurance License");
aal.Urls.ShouldBe(new[] { new Uri("https://opensource.org/licenses/AAL") });
aal.DownloadUrl.ShouldBe(new Uri("https://opensource.org/licenses/AAL"));

_sut.Index.TryGetEntry("AAL-test", out var aalTest).ShouldBeTrue();
aalTest.ShouldBe(aal);

_sut.Index.TryGetEntry("Apache-2.0", out var apache).ShouldBeTrue();
apache.ShouldNotBeNull();

apache.FullName.ShouldBe("Apache License, Version 2.0");
apache.Urls.ShouldBe(
new[]
{
new Uri("https://tldrlegal.com/license/apache-license-2.0-%28apache-2.0%29"),
new Uri("https://en.wikipedia.org/wiki/Apache_License"),
new Uri("https://opensource.org/licenses/Apache-2.0"),
new Uri("https://www.apache.org/licenses/LICENSE-2.0"),
new Uri("https://www.gnu.org/licenses/apache-2.0.txt")
},
ignoreOrder: true);
apache.DownloadUrl.ShouldBe(new Uri("https://www.gnu.org/licenses/apache-2.0.txt"));
_sut.Index.TryGetCode("apache-2-0", out var code).ShouldBeTrue();
code.ShouldBe("Apache-2.0");

_sut.Index.TryGetCode(new Uri("https://www.apache.org/licenses/license-2.0"), out code).ShouldBeTrue();
code.ShouldBe("Apache-2.0");

_sut.Index.TryGetCode("bsd-3-clause", out code).ShouldBeTrue();
code.ShouldBe("BSD-3-Clause");
}

[Test]
public async Task GetOrLoadIndexNotFoundAsync()
{
_mockHttp
.When(HttpMethod.Get, "https://api.opensource.org/licenses/")
.When(HttpMethod.Get, "https://opensource.org/api/license/")
.Respond(HttpStatusCode.NotFound);

await _sut.LoadIndexAsync(default).ConfigureAwait(false);

_sut.Index.ShouldNotBeNull();
}

[Test]
public void TryFindLicenseCodeByUrlFoundByCodeFromUrlPath()
{
var entry = new OpenSourceOrgLicenseEntry("BSD-3-clause", "dummy");

_sut.Index = new OpenSourceOrgIndex(1);
_sut.Index.Add(entry);
_sut.Index.TryAdd("BSD-3", entry);

_sut.TryFindLicenseCodeByUrl(new Uri("https://opensource.org/licenses/BSD-3"), out var actual).ShouldBeTrue();

actual.ShouldBe("BSD-3-clause");
_sut.Index.TryGetCode("apache-2-0", out _).ShouldBeFalse();
}

[Test]
public void TryFindLicenseCodeByUrlFoundByUrl()
[TestCase("https://opensource.org/license/apache-2.0")]
[TestCase("https://opensource.org/license/apache-2-0")]
[TestCase("https://opensource.org/licenses/apache-2-0")]
[TestCase("https://www.apache.org/licenses/license-2.0")]
[TestCase("https://opensource.org/api/licenses/apache-2-0")]
[TestCase("https://opensource.org/api/license/apache-2-0")]
[TestCase("https://api.opensource.org/license/apache-2-0")] // deprecated API
[TestCase("https://api.opensource.org/licenses/apache-2-0")]
[TestCase("https://api.opensource.org/license/apache-2.0")]
public void TryFindLicenseCodeByUrl(string url)
{
var entry = new OpenSourceOrgLicenseEntry("Apache-2.0", "dummy")
var entry = new OsiApprovedLicense
{
Urls = { new("https://www.gnu.org/licenses/apache-2.0.txt") }
Id = "apache-2-0",
SpdxId = "Apache-2.0",
LicenseStewardUrl = "https://www.apache.org/licenses/LICENSE-2.0"
};

_sut.Index = new OpenSourceOrgIndex(1);
_sut.Index.Add(entry);
_sut.Index = new OsiLicenseIndex(1, 1);
_sut.Index.Add(entry.Id, entry.SpdxId);
_sut.Index.Add(entry.SpdxId, new Uri(entry.LicenseStewardUrl));

_sut.TryFindLicenseCodeByUrl(new Uri("https://www.gnu.org/licenses/apache-2.0.txt"), out var actual).ShouldBeTrue();
_sut.TryFindLicenseCodeByUrl(new Uri(url), out var actual).ShouldBeTrue();

actual.ShouldBe("Apache-2.0");
}

[Test]
public async Task TryDownloadByCodeAsync()
[TestCase("apache-2.0")]
[TestCase("apache-2-0")]
[TestCase("Apache-2.0")]
public void TryFindLicenseCode(string code)
{
var entry = new OpenSourceOrgLicenseEntry("GPL-2.0", "GNU General Public License, Version 2.0")
var entry = new OsiApprovedLicense
{
DownloadUrl = new Uri("https://www.gnu.org/licenses/old-licenses/gpl-2.0.txt")
Id = "apache-2-0",
SpdxId = "Apache-2.0"
};

_sut.Index = new OpenSourceOrgIndex(1);
_sut.Index.Add(entry);
_sut.Index = new OsiLicenseIndex(1, 0);
_sut.Index.Add(entry.Id, entry.SpdxId);

_mockHttp
.When(HttpMethod.Get, "https://www.gnu.org/licenses/old-licenses/gpl-2.0.txt")
.Respond(
MediaTypeNames.Text.Plain,
TempFile.OpenResource(GetType(), "OpenSourceOrgRepositoryTest.gpl-2.0.txt"));

var actual = await _sut.TryDownloadByCodeAsync("gpl-2.0", default).ConfigureAwait(false);

actual.ShouldNotBeNull();
actual.Code.ShouldBe(entry.Code);
actual.FullName.ShouldBe(entry.FullName);
actual.HRef.ShouldBe(entry.DownloadUrl.ToString());
actual.FileExtension.ShouldBe(".txt");
actual.FileContent.ShouldNotBeEmpty();
actual.FileContent.AsText().ShouldContain("GNU GENERAL PUBLIC LICENSE");
_sut.TryFindLicenseCode(code, out var actual).ShouldBeTrue();

actual.ShouldBe("Apache-2.0");
}
}

This file was deleted.

Loading