Skip to content

Commit 675f730

Browse files
committed
Added tests for publisher information.
1 parent 4e4deb6 commit 675f730

File tree

9 files changed

+80
-1
lines changed

9 files changed

+80
-1
lines changed

AuthenticodeLint/Rules/PublisherInformationRule.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.Security.Cryptography.Pkcs;
32

43
namespace AuthenticodeLint.Rules
54
{

AuthenticodeLintTests/AuthenticodeLintTests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
<ItemGroup>
3939
<Compile Include="CommandLineParsingTests.cs" />
4040
<Compile Include="Properties\AssemblyInfo.cs" />
41+
<Compile Include="Rules\PublisherInformationPresentRuleTests.cs" />
4142
<Compile Include="Rules\TimestampedRuleTests.cs" />
4243
<Compile Include="Rules\WinCertificatePaddingRuleTests.cs" />
4344
</ItemGroup>
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
using AuthenticodeLint;
2+
using AuthenticodeLint.Rules;
3+
using System.Collections.Generic;
4+
using Xunit;
5+
6+
namespace AuthenticodeLintTests.Rules
7+
{
8+
public class PublisherInformationPresentRuleTests
9+
{
10+
private static CheckConfiguration Configuration => new CheckConfiguration(new List<string>(), null, false, new HashSet<int>(), false, RevocationChecking.None);
11+
12+
private static Graph<Signature> GetGraphForFile(string file)
13+
{
14+
var extractor = new SignatureExtractor();
15+
return extractor.Extract(file);
16+
}
17+
18+
[Fact]
19+
public void ShouldFailWhenNoPublisherInformation()
20+
{
21+
var signature = GetGraphForFile("../../inputs/pubinfonoexist.ex_");
22+
var rule = new PublisherInformationPresentRule();
23+
var logger = new MemorySignatureLogger();
24+
25+
var result = rule.Validate(signature, logger, Configuration);
26+
Assert.Equal(RuleResult.Fail, result);
27+
Assert.Collection(logger.Messages, s => s.EndsWith("Signature does not have an accompanying description."), s => s.EndsWith("Signature does not have an accompanying URL."));
28+
}
29+
30+
[Fact]
31+
public void ShouldFailWhenNoPublisherURL()
32+
{
33+
var signature = GetGraphForFile("../../inputs/pubinfohasdescription.ex_");
34+
var rule = new PublisherInformationPresentRule();
35+
var logger = new MemorySignatureLogger();
36+
37+
var result = rule.Validate(signature, logger, Configuration);
38+
Assert.Equal(RuleResult.Fail, result);
39+
Assert.Collection(logger.Messages, s => s.EndsWith("Signature does not have an accompanying URL."));
40+
}
41+
42+
[Fact]
43+
public void ShouldFailWhenNoPublisherDescription()
44+
{
45+
var signature = GetGraphForFile("../../inputs/pubinfohasurl.ex_");
46+
var rule = new PublisherInformationPresentRule();
47+
var logger = new MemorySignatureLogger();
48+
49+
var result = rule.Validate(signature, logger, Configuration);
50+
Assert.Equal(RuleResult.Fail, result);
51+
Assert.Collection(logger.Messages, s => s.EndsWith("Signature does not have an accompanying description."));
52+
}
53+
54+
[Fact]
55+
public void ShouldFailWhenUrlIsBogus()
56+
{
57+
var signature = GetGraphForFile("../../inputs/pubinfohasbogusurl.ex_");
58+
var rule = new PublisherInformationPresentRule();
59+
var logger = new MemorySignatureLogger();
60+
61+
var result = rule.Validate(signature, logger, Configuration);
62+
Assert.Equal(RuleResult.Fail, result);
63+
Assert.Collection(logger.Messages, s => s.EndsWith("Signature's accompanying URL is not a valid URI."));
64+
}
65+
66+
67+
[Fact]
68+
public void ShouldPassWhenUrlAndDescriptionPresent()
69+
{
70+
var signature = GetGraphForFile("../../inputs/pubinfovalid.ex_");
71+
var rule = new PublisherInformationPresentRule();
72+
var logger = new MemorySignatureLogger();
73+
74+
var result = rule.Validate(signature, logger, Configuration);
75+
Assert.Equal(RuleResult.Pass, result);
76+
Assert.Empty(logger.Messages);
77+
}
78+
}
79+
}
Binary file not shown.
Binary file not shown.
40.5 KB
Binary file not shown.
36.7 KB
Binary file not shown.
40.5 KB
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)