This repository was archived by the owner on Mar 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 179
Expand file tree
/
Copy pathKeyTests.cs
More file actions
82 lines (75 loc) · 2.84 KB
/
KeyTests.cs
File metadata and controls
82 lines (75 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using System;
using System.IO;
using System.Reflection;
using System.Security.Cryptography;
using TestTools.Helpers;
using TestTools;
using NUnit.Framework;
using System.Diagnostics.CodeAnalysis;
namespace ILMerging.Tests
{
[ExcludeFromCodeCoverage]
[TestFixture]
public sealed class KeyTests
{
[Test]
public void Can_sign_using_keyfile()
{
using (var outputFile = TempFile.WithExtension(".dll"))
{
var ilMerge = new ILMerge { KeyFile = TestFiles.TestSnk, OutputFile = outputFile };
ilMerge.SetUpInputAssemblyForTest(Assembly.GetExecutingAssembly());
ilMerge.Merge();
Assert.That(
AssemblyName.GetAssemblyName(outputFile).GetPublicKey(),
Is.EqualTo(new StrongNameKeyPair(File.ReadAllBytes(TestFiles.TestSnk)).PublicKey));
}
}
[Test]
public void Can_sign_using_keycontainer()
{
var keyContainerName = Guid.NewGuid().ToString();
CspContainerUtils.ImportBlob(true, keyContainerName, KeyNumber.Signature, File.ReadAllBytes(TestFiles.TestSnk));
try
{
using (var outputFile = TempFile.WithExtension(".dll"))
{
var ilMerge = new ILMerge
{
KeyContainer = keyContainerName,
OutputFile = outputFile
};
ilMerge.SetUpInputAssemblyForTest(Assembly.GetExecutingAssembly());
ilMerge.Merge();
Assert.That(
AssemblyName.GetAssemblyName(outputFile).GetPublicKey(),
Is.EqualTo(new StrongNameKeyPair(File.ReadAllBytes(TestFiles.TestSnk)).PublicKey));
}
}
finally
{
CspContainerUtils.Delete(true, keyContainerName, KeyNumber.Signature);
}
}
[Test]
public void Bad_keyfile_gives_diagnostic_warning()
{
using (var logFile = new TempFile())
using (var outputFile = TempFile.WithExtension(".dll"))
{
var ilMerge = new ILMerge
{
KeyFile = TestFiles.TestPfx,
OutputFile = outputFile,
LogFile = logFile
};
ilMerge.SetUpInputAssemblyForTest(Assembly.GetExecutingAssembly());
ilMerge.Merge();
var logText = File.ReadAllText(logFile);
Assert.That(logText, Contains.Substring("Unable to obtain public key for StrongNameKeyPair."));
Assert.That(logText, Contains.Substring("PFX"));
Assert.That(logText, Contains.Substring("key container"));
}
}
}
}