8000 fixup! chore: tests for authenticode and version checks · coder/coder-desktop-windows@bc09aa2 · GitHub
[go: up one dir, main page]

Skip to content

Commit bc09aa2

Browse files
committed
fixup! chore: tests for authenticode and version checks
1 parent 81e645c commit bc09aa2

File tree

4 files changed

+35
-24
lines changed

4 files changed

+35
-24
lines changed

Tests.Vpn.Service/DownloaderTest.cs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,22 @@ public void Unsigned(CancellationToken ct)
3030
var testBinaryPath = Path.Combine(TestContext.CurrentContext.TestDirectory, "testdata", "hello.exe");
3131
var ex = Assert.ThrowsAsync<Exception>(() =>
3232
AuthenticodeDownloadValidator.Coder.ValidateAsync(testBinaryPath, ct));
33-
Assert.That(ex.Message, Does.Contain("File is not signed and trusted with an Authenticode signature: State=Unsigned, StateReason=None"));
33+
Assert.That(ex.Message,
34+
Does.Contain(
35+
"File is not signed and trusted with an Authenticode signature: State=Unsigned, StateReason=None"));
3436
}
3537

3638
[Test(Description = "Test an untrusted binary")]
3739
[CancelAfter(30_000)]
3840
public void Untrusted(CancellationToken ct)
3941
{
40-
var testBinaryPath = Path.Combine(TestContext.CurrentContext.TestDirectory, "testdata", "hello-self-signed.exe");
42+
var testBinaryPath =
43+
Path.Combine(TestContext.CurrentContext.TestDirectory, "testdata", "hello-self-signed.exe");
4144
var ex = Assert.ThrowsAsync<Exception>(() =>
4245
AuthenticodeDownloadValidator.Coder.ValidateAsync(testBinaryPath, ct));
43-
Assert.That(ex.Message, Does.Contain("File is not signed and trusted with an Authenticode signature: State=Unsigned, StateReason=UntrustedRoot"));
46+
Assert.That(ex.Message,
47+
Does.Contain(
48+
"File is not signed and trusted with an Authenticode signature: State=Unsigned, StateReason=UntrustedRoot"));
4449
}
4550

4651
[Test(Description = "Test an binary with a detached signature (catalog file)")]
@@ -62,14 +67,17 @@ public void DifferentCertUntrusted(CancellationToken ct)
6267
// this is installed.
6368
var ex = Assert.ThrowsAsync<Exception>(() =>
6469
AuthenticodeDownloadValidator.Coder.ValidateAsync(@"C:\Program Files\dotnet\dotnet.exe", ct));
65-
Assert.That(ex.Message, Does.Contain("File is signed by an unexpected certificate: ExpectedName='Coder Technologies Inc.', ActualName='.NET"));
70+
Assert.That(ex.Message,
71+
Does.Contain(
72+
"File is signed by an unexpected certificate: ExpectedName='Coder Technologies Inc.', ActualName='.NET"));
6673
}
6774

6875
[Test(Description = "Test a binary signed by Coder's certificate")]
6976
[CancelAfter(30_000)]
7077
public async Task CoderSigned(CancellationToken ct)
7178
{
72-
var testBinaryPath = Path.Combine(TestContext.CurrentContext.TestDirectory, "testdata", "hello-versioned-signed.exe");
79+
var testBinaryPath = Path.Combine(TestContext.CurrentContext.TestDirectory, "testdata",
80+
"hello-versioned-signed.exe");
7381
await AuthenticodeDownloadValidator.Coder.ValidateAsync(testBinaryPath, ct);
7482
}
7583
}
@@ -91,7 +99,8 @@ public void NoVersion(CancellationToken ct)
9199
[CancelAfter(30_000)]
92100
public void InvalidVersion(CancellationToken ct)
93101
{
94-
var testBinaryPath = Path.Combine(TestContext.CurrentContext.TestDirectory, "testdata", "hello-invalid-version.exe");
102+
var testBinaryPath =
103+
Path.Combine(TestContext.CurrentContext.TestDirectory, "testdata", "hello-invalid-version.exe");
95104
var ex = Assert.ThrowsAsync<Exception>(() =>
96105
new AssemblyVersionDownloadValidator(1, 2, 3, 4).ValidateAsync(testBinaryPath, ct));
97106
Assert.That(ex.Message, Does.Contain("File ProductVersion '1-2-3-4' is not a valid version string"));
@@ -101,7 +110,8 @@ public void InvalidVersion(CancellationToken ct)
101110
[CancelAfter(30_000)]
102111
public void VersionMismatchFull(CancellationToken ct)
103112
{
104-
var testBinaryPath = Path.Combine(TestContext.CurrentContext.TestDirectory, "testdata", "hello-versioned-signed.exe");
113+
var testBinaryPath = Path.Combine(TestContext.CurrentContext.TestDirectory, "testdata",
114+
"hello-versioned-signed.exe");
105115

106116
// Try changing each version component one at a time
107117
var expectedVersions = new[] { 1, 2, 3, 4 };
@@ -124,7 +134,8 @@ public void VersionMismatchFull(CancellationToken ct)
124134
[CancelAfter(30_000)]
125135
public async Task VersionMatch(CancellationToken ct)
126136
{
127-
var testBinaryPath = Path.Combine(TestContext.CurrentContext.TestDirectory, "testdata", "hello-versioned-signed.exe");
137+
var testBinaryPath = Path.Combine(TestContext.CurrentContext.TestDirectory, "testdata",
138+
"hello-versioned-signed.exe");
128139

129140
// Test with just major.minor
130141
await new AssemblyVersionDownloadValidator(1, 2).ValidateAsync(testBinaryPath, ct);

Tests.Vpn.Service/Tests.Vpn.Service.csproj

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,20 @@
1313
</PropertyGroup>
1414

1515
<ItemGroup>
16-
<None Remove="testdata\hello.go" />
17-
<None Remove="testdata\winres.json" />
18-
<None Update="testdata\hello.exe">
19-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
20-
</None>
21-
<None Update="testdata\hello-invalid-version.exe">
22-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
23-
</None>
24-
<None Update="testdata\hello-self-signed.exe">
25-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
26-
</None>
27-
<None Update="testdata\hello-versioned-signed.exe">
28-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
29-
</None>
16+
<None Remove="testdata\hello.go" />
17+
<None Remove="testdata\winres.json" />
18+
<None Update="testdata\hello.exe">
19+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
20+
</None>
21+
<None Update="testdata\hello-invalid-version.exe">
22+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
23+
</None>
24+
<None Update="testdata\hello-self-signed.exe">
25+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
26+
</None>
27+
<None Update="testdata\hello-versioned-signed.exe">
28+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
29+
</None>
3030
</ItemGroup>
3131

3232
<ItemGroup>

Tests.Vpn.Service/testdata/Build-Assets.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ try {
5555
}
5656
}
5757

58-
# hello-versioned-signed.exe is used for testing versioned binariess and
58+
# hello-versioned-signed.exe is used for testing versioned binaries and
5959
# binaries signed by a real EV certificate.
6060
Copy-Item hello.exe hello-versioned-signed.exe
6161

Vpn.Service/Manager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ private async Task DownloadTunnelBinaryAsync(string baseUrl, SemVersion expected
434434
{
435435
_logger.LogDebug("Adding version validator for version '{ExpectedVersion}'", expectedVersion);
436436
validators.Add(new AssemblyVersionDownloadValidator((int)expectedVersion.Major, (int)expectedVersion.Minor,
437-
(int)expectedVersion.Patch, -1));
437+
(int)expectedVersion.Patch));
438438
}
439439
else
440440
{

0 commit comments

Comments
 (0)
0