public void LicenseDefaultNotAllowed_InternalProject_NoViolation() { var config = new Config { DiskCache = new DiskCacheConfig { ResolvedLicenses = new DiskCacheItem { DoCache = false } } }; var packagePolicies = new PackagePolicies(new PackagePolicy[] { }); var licensePolicies = new[] { new LicensePolicy { License = "no-distribution-allowed", Allow = false, AllowInternal = true } }; var pd = new PackageDetails { Id = "test-id", Version = "1.0.4", License = "no-distribution-allowed", }; var package = new AnalyzedPackage(pd.Id, pd.Version, "path-to-origin-project"); var dependencies = DependencyChain <AnalyzedPackage> .EmptyList; var packages = new[] { new DependencyChain <AnalyzedPackage>(package, dependencies) }; var scanner = new LicenseScanner(_ => Task.FromResult(new PackageDetailsResult(pd)), packagePolicies, config); var licensedDependencies = scanner.FindLicenses(packages); LicensePolicies licensing = new LicensePolicies(licensePolicies, packagePolicies, new Projects(new[] { "path-to-origin-project" })); var result = licensing.Apply(licensedDependencies); Assert.Equal(1, result.Count); Assert.Equal(Evaluation.Ok, result.First().Package.Result); }
private void TestGetLicenseUrl(string url, string expectedResult) { var projectUrl = new Uri(url); var expected = new Uri(expectedResult); var result = LicenseScanner.GetPotentialLicenseUrls(projectUrl).First(); Assert.Equal(expected, result); }
public static Task <(IDependencyScanner, ILicenseScanner)> Create(IFileAccess fileSystem, Config config) { var npm = new Npm(); var packagePolicies = PackagePolicies.LoadFrom(config.PackagePolicies); IDependencyScanner scanner = new DependencyScanner(npm, fileSystem, packagePolicies, config.DiskCache); Func <IPackage, Task <PackageDetailsResult> > getDetails = p => npm.GetPackage(p).ContinueWith(ConvertPackageDetails); ILicenseScanner licenseScanner = new LicenseScanner(getDetails, packagePolicies, config); return(Task.FromResult((scanner, licenseScanner))); }
public static async Task <(IDependencyScanner, ILicenseScanner)> Create(IFileAccess fileSystem, Config config) { var packagePolicies = PackagePolicies.LoadFrom(config.PackagePolicies); var scanner = await DependencyScanner.Create(config, fileSystem, packagePolicies); var catalog = new NuGetCatalog(config.DiskCache); var index = await catalog.GetIndex(); var registry = new NuGetDependencies(index, config); Func <IPackage, Task <PackageDetailsResult> > getDetails = p => registry.GetPackageDetails(p).ContinueWith(ConvertPackageDetails); ILicenseScanner licenseScanner = new LicenseScanner(getDetails, packagePolicies, config); return(scanner, licenseScanner); }
public void NoPackageFound_HasValidPackagePolicy_GivesCorrectLicense() { var config = new Config(); var packagePolicies = new PackagePolicies(new[] { new PackagePolicy { Package = "test-id", License = "test-license" } }); var scanner = new LicenseScanner(_ => Task.FromResult(new PackageDetailsResult(PackageDetailsResultEnum.NoPackageFound)), packagePolicies, config); var package = new AnalyzedPackage("test-id", "1.0.4", string.Empty, AnalysisState.Error, "test error"); var dependencies = DependencyChain <AnalyzedPackage> .EmptyList; var packages = new[] { new DependencyChain <AnalyzedPackage>(package, dependencies) }; var result = scanner.FindLicenses(packages); Assert.Equal(1, result.Count); Assert.Equal("test-license", result.First().Package.License); }