public void Validate_ReturnsErrorIssue_IfPackageNotSigned() { if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { // PackageSign verification only works on desktop return; } // Arrange var context = TestPackageAnalysisContext.CreateContext( _output, new[] { "lib/netstandard2.0/Test.dll", "tools/MyScript.psd1" }); using (context) { var rule = GetRule(); // Act var issues = rule.Validate(context); // Assert Assert.Collection( issues, issue => { Assert.Equal(TestPackageAnalysisContext.PackageId, issue.Instance); Assert.Equal("PACKAGE_SIGN_VERIFICATION_FAILED", issue.IssueId); Assert.Equal(PackageIssueLevel.Error, issue.Level); Assert.StartsWith($"Sign verification for package {TestPackageAnalysisContext.PackageId} failed:", issue.Issue); }); } }
public void ItFailsWhenPackageContainsUnlistedFiles() { var signRequest = @" <SignRequest> <Nupkg Path=""TestPackage.1.0.0.nupkg""> </Nupkg> </SignRequest>"; var context = TestPackageAnalysisContext.CreateContext( _output, new[] { "lib/netstandard2.0/Test.dll", "tools/MyScript.psd1" }, signRequest: signRequest); using (context) { var rule = new SignRequestListsAllSignableFiles(); var errors = rule.Validate(context); Assert.NotEmpty(errors); Assert.Contains(errors, e => e.Instance.Equals("lib/netstandard2.0/Test.dll", StringComparison.Ordinal) && e.IssueId.Equals("FILE_MISSING_FROM_SIGN_REQUEST", StringComparison.Ordinal)); Assert.Contains(errors, e => e.Instance.Equals("tools/MyScript.psd1", StringComparison.Ordinal) && e.IssueId.Equals("FILE_MISSING_FROM_SIGN_REQUEST", StringComparison.Ordinal)); } }
public void ItWarnsAboutMissingMetadata() { var metadata = new ManifestMetadata { Repository = new RepositoryMetadata { }, }; var rule = new PackageRepoMetadataRule(); using (var context = TestPackageAnalysisContext.Create(_output, metadata)) { Assert.Contains(rule.Validate(context), r => string.Equals(r.IssueId, "PACKAGE_MISSING_REPO_TYPE", StringComparison.Ordinal)); Assert.Contains(rule.Validate(context), r => string.Equals(r.IssueId, "PACKAGE_MISSING_REPO_URL", StringComparison.Ordinal)); Assert.Contains(rule.Validate(context), r => string.Equals(r.IssueId, "PACKAGE_MISSING_REPO_COMMIT", StringComparison.Ordinal)); } }
public void DoesNotFailWhenSignRequestListsAllFiles() { var signRequest = @" <SignRequest> <Nupkg Path=""TestPackage.1.0.0.nupkg""> <ExcludedFile Path=""lib/netstandard2.0/Test.dll"" /> <ExcludedFile Path=""tools/MyScript.psd1"" /> </Nupkg> </SignRequest>"; var context = TestPackageAnalysisContext.CreateContext( _output, new[] { "lib/netstandard2.0/Test.dll", "tools/MyScript.psd1" }, signRequest: signRequest); using (context) { var rule = new SignRequestListsAllSignableFiles(); var errors = rule.Validate(context); Assert.Empty(errors); } }