mirror of
https://github.com/velopack/velopack.git
synced 2025-10-25 15:19:22 +00:00
Fix azure signing tests
This commit is contained in:
@@ -114,7 +114,7 @@ public class WindowsPackCommandRunner : PackageBuilder<WindowsPackOptions>
|
|||||||
return "";
|
return "";
|
||||||
|
|
||||||
var providedRuntimes = Options.Runtimes.ToLower()
|
var providedRuntimes = Options.Runtimes.ToLower()
|
||||||
.Split(new[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries);
|
.Split(new[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
|
||||||
var valid = new string[] {
|
var valid = new string[] {
|
||||||
"webview2",
|
"webview2",
|
||||||
@@ -163,7 +163,8 @@ public class WindowsPackCommandRunner : PackageBuilder<WindowsPackOptions>
|
|||||||
}
|
}
|
||||||
#pragma warning restore CS0618 // Type or member is obsolete
|
#pragma warning restore CS0618 // Type or member is obsolete
|
||||||
|
|
||||||
throw new UserInfoException($"The framework/runtime dependency '{str}' is not valid. See https://github.com/velopack/velopack/blob/master/docs/bootstrapping.md");
|
throw new UserInfoException(
|
||||||
|
$"The framework/runtime dependency '{str}' is not valid. See https://github.com/velopack/velopack/blob/master/docs/bootstrapping.md");
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var str in validated) {
|
foreach (var str in validated) {
|
||||||
@@ -184,6 +185,7 @@ public class WindowsPackCommandRunner : PackageBuilder<WindowsPackOptions>
|
|||||||
if (Options.Icon != null) {
|
if (Options.Icon != null) {
|
||||||
editor.SetExeIcon(Options.Icon);
|
editor.SetExeIcon(Options.Icon);
|
||||||
}
|
}
|
||||||
|
|
||||||
editor.Commit();
|
editor.Commit();
|
||||||
|
|
||||||
progress(25);
|
progress(25);
|
||||||
@@ -207,7 +209,8 @@ public class WindowsPackCommandRunner : PackageBuilder<WindowsPackOptions>
|
|||||||
File.Delete(Path.Combine(current.FullName, "Squirrel.exe"));
|
File.Delete(Path.Combine(current.FullName, "Squirrel.exe"));
|
||||||
|
|
||||||
// move the stub to the root of the portable package
|
// move the stub to the root of the portable package
|
||||||
var stubPath = Path.Combine(current.FullName,
|
var stubPath = Path.Combine(
|
||||||
|
current.FullName,
|
||||||
Path.GetFileNameWithoutExtension(Options.EntryExecutableName) + "_ExecutionStub.exe");
|
Path.GetFileNameWithoutExtension(Options.EntryExecutableName) + "_ExecutionStub.exe");
|
||||||
var stubName = (Options.PackTitle ?? Options.PackId) + ".exe";
|
var stubName = (Options.PackTitle ?? Options.PackId) + ".exe";
|
||||||
File.Move(stubPath, Path.Combine(dir.FullName, stubName));
|
File.Move(stubPath, Path.Combine(dir.FullName, stubName));
|
||||||
@@ -285,24 +288,26 @@ public class WindowsPackCommandRunner : PackageBuilder<WindowsPackOptions>
|
|||||||
if (File.Exists(dlibPath)) {
|
if (File.Exists(dlibPath)) {
|
||||||
return dlibPath;
|
return dlibPath;
|
||||||
}
|
}
|
||||||
Log.Info($"Downloading Azure Trusted Signing dlib to '{dlibPath}'");
|
|
||||||
var dl = new NuGetDownloader();
|
|
||||||
|
|
||||||
using MemoryStream nupkgStream = new();
|
throw new NotSupportedException("Azure Trusted Signing is not supported in this version of Velopack.");
|
||||||
await dl.DownloadPackageToStream("Microsoft.Trusted.Signing.Client", "1.*", nupkgStream, cancellationToken);
|
|
||||||
|
|
||||||
nupkgStream.Position = 0;
|
// Log.Info($"Downloading Azure Trusted Signing dlib to '{dlibPath}'");
|
||||||
|
// var dl = new NuGetDownloader();
|
||||||
string parentDir = NugetUtil.BinDirectory + Path.AltDirectorySeparatorChar + "x64" + Path.AltDirectorySeparatorChar;
|
//
|
||||||
|
// using MemoryStream nupkgStream = new();
|
||||||
ZipArchive zipPackage = new(nupkgStream);
|
// await dl.DownloadPackageToStream("Microsoft.Trusted.Signing.Client", "1.*", nupkgStream, cancellationToken);
|
||||||
var entries = zipPackage.Entries.Where(x => x.FullName.StartsWith(parentDir, StringComparison.OrdinalIgnoreCase));
|
//
|
||||||
foreach (var entry in entries) {
|
// nupkgStream.Position = 0;
|
||||||
var relativePath = entry.FullName.Substring(parentDir.Length);
|
//
|
||||||
entry.ExtractToFile(Path.Combine(signToolDirectory, relativePath), true);
|
// string parentDir = NugetUtil.BinDirectory + Path.AltDirectorySeparatorChar + "x64" + Path.AltDirectorySeparatorChar;
|
||||||
}
|
//
|
||||||
|
// ZipArchive zipPackage = new(nupkgStream);
|
||||||
return dlibPath;
|
// var entries = zipPackage.Entries.Where(x => x.FullName.StartsWith(parentDir, StringComparison.OrdinalIgnoreCase));
|
||||||
|
// foreach (var entry in entries) {
|
||||||
|
// var relativePath = entry.FullName.Substring(parentDir.Length);
|
||||||
|
// entry.ExtractToFile(Path.Combine(signToolDirectory, relativePath), true);
|
||||||
|
// }
|
||||||
|
// return dlibPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override string[] GetMainExeSearchPaths(string packDirectory, string mainExeName)
|
protected override string[] GetMainExeSearchPaths(string packDirectory, string mainExeName)
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ public static class HelperFile
|
|||||||
public static string StubExecutablePath => FindHelperFile("stub.exe");
|
public static string StubExecutablePath => FindHelperFile("stub.exe");
|
||||||
|
|
||||||
[SupportedOSPlatform("windows")]
|
[SupportedOSPlatform("windows")]
|
||||||
public static string SignToolPath => FindHelperFile("signtool.exe");
|
public static string SignToolPath => FindHelperFile("signing\\signtool.exe");
|
||||||
|
|
||||||
[SupportedOSPlatform("windows")]
|
[SupportedOSPlatform("windows")]
|
||||||
public const string AzureDlibFileName = "Azure.CodeSigning.Dlib.dll";
|
public const string AzureDlibFileName = "Azure.CodeSigning.Dlib.dll";
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
using System.Security.Cryptography.X509Certificates;
|
|
||||||
using Azure.Core;
|
using Azure.Core;
|
||||||
using Azure.Identity;
|
using Azure.Identity;
|
||||||
using Velopack.Packaging.Windows;
|
using Velopack.Packaging.Windows;
|
||||||
@@ -28,20 +27,20 @@ public class TrustedSigningTests
|
|||||||
var creds = new ChainedTokenCredential(
|
var creds = new ChainedTokenCredential(
|
||||||
new AzureCliCredential(),
|
new AzureCliCredential(),
|
||||||
new EnvironmentCredential());
|
new EnvironmentCredential());
|
||||||
|
// var creds = new DefaultAzureCredential();
|
||||||
try {
|
try {
|
||||||
var token = await creds.GetTokenAsync(new TokenRequestContext([$"{CodeSigningEndpoint}/.default"]));
|
var token = await creds.GetTokenAsync(new TokenRequestContext([$"https://codesigning.azure.net/.default"]));
|
||||||
return token.Token != null;
|
return token.Token != null;
|
||||||
} catch (Exception) {
|
} catch (Exception) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[SkippableFact]
|
[SkippableFact]
|
||||||
public async void CanSignWithTrustedSigning()
|
public async void CanSignWithTrustedSigning()
|
||||||
{
|
{
|
||||||
Skip.If(!VelopackRuntimeInfo.IsWindows);
|
Skip.IfNot(VelopackRuntimeInfo.IsWindows, "Only supported on Windows");
|
||||||
Skip.If(!await IsAuthenticatedForCodeSigningAsync());
|
Skip.IfNot(await IsAuthenticatedForCodeSigningAsync(), "Sign in with az login first");
|
||||||
|
|
||||||
using var logger = _output.BuildLoggerFor<TrustedSigningTests>();
|
using var logger = _output.BuildLoggerFor<TrustedSigningTests>();
|
||||||
using var _ = TempUtil.GetTempDirectory(out var releaseDir);
|
using var _ = TempUtil.GetTempDirectory(out var releaseDir);
|
||||||
@@ -51,7 +50,9 @@ public class TrustedSigningTests
|
|||||||
: "ci-" + VelopackRuntimeInfo.SystemOs.GetOsShortName();
|
: "ci-" + VelopackRuntimeInfo.SystemOs.GetOsShortName();
|
||||||
|
|
||||||
string metadataFile = Path.Combine(releaseDir, "metadata.json");
|
string metadataFile = Path.Combine(releaseDir, "metadata.json");
|
||||||
File.WriteAllText(metadataFile, $$"""
|
File.WriteAllText(
|
||||||
|
metadataFile,
|
||||||
|
$$"""
|
||||||
{
|
{
|
||||||
"Endpoint": "{{CodeSigningEndpoint}}",
|
"Endpoint": "{{CodeSigningEndpoint}}",
|
||||||
"CodeSigningAccountName": "velopack-signing-account",
|
"CodeSigningAccountName": "velopack-signing-account",
|
||||||
@@ -60,7 +61,14 @@ public class TrustedSigningTests
|
|||||||
""");
|
""");
|
||||||
|
|
||||||
var id = "AZTrustedSigningApp";
|
var id = "AZTrustedSigningApp";
|
||||||
TestApp.PackTestApp(id, "1.0.0", $"aztrusted-{DateTime.UtcNow.ToLongDateString()}", releaseDir, logger, channel: channel, azureTrustedSignFile: metadataFile);
|
TestApp.PackTestApp(
|
||||||
|
id,
|
||||||
|
"1.0.0",
|
||||||
|
$"aztrusted-{DateTime.UtcNow.ToLongDateString()}",
|
||||||
|
releaseDir,
|
||||||
|
logger,
|
||||||
|
channel: channel,
|
||||||
|
azureTrustedSignFile: metadataFile);
|
||||||
|
|
||||||
var files = Directory.EnumerateFiles(releaseDir)
|
var files = Directory.EnumerateFiles(releaseDir)
|
||||||
.Where(x => PathUtil.FileIsLikelyPEImage(x))
|
.Where(x => PathUtil.FileIsLikelyPEImage(x))
|
||||||
@@ -71,4 +79,4 @@ public class TrustedSigningTests
|
|||||||
Assert.All(files, x => Assert.True(AuthenticodeTools.IsTrusted(x)));
|
Assert.All(files, x => Assert.True(AuthenticodeTools.IsTrusted(x)));
|
||||||
#pragma warning restore CA1416 // Validate platform compatibility
|
#pragma warning restore CA1416 // Validate platform compatibility
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user