Skip to content

Commit

Permalink
Test install.exe
Browse files Browse the repository at this point in the history
  • Loading branch information
ricaun committed Dec 6, 2024
1 parent 3b2fdb2 commit 108d63d
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 7 deletions.
6 changes: 5 additions & 1 deletion Build/INuGetKeyVaultSign.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ public interface INuGetKeyVaultSign : IClean, ICompile
.Before(Compile)
.Executes(() =>
{
new AzureSignToolTests().SetupEnvironmentToolPath();
Serilog.Log.Information(AzureSignToolTasks.AzureSignToolPath);

new NuGetKeyVaultSignToolTests().SetupEnvironmentToolPath();
Serilog.Log.Information(NuGetKeyVaultSignToolTasks.NuGetKeyVaultSignToolPath);

if (string.IsNullOrEmpty(AZURE_KEY_VAULT_FILE))
Expand All @@ -34,7 +38,7 @@ public interface INuGetKeyVaultSign : IClean, ICompile
return;
}

var azureKeyVaultFile = JsonConvert.DeserializeObject<AzureKeyVaultConfig>(AZURE_KEY_VAULT_FILE);
var azureKeyVaultFile = AzureKeyVaultConfig.Create(AZURE_KEY_VAULT_FILE);
var azureKeyVaultClientSecret = AZURE_KEY_VAULT_PASSWORD;

if (azureKeyVaultFile is null)
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Test `AzureKeyVaultConfig` with `AZURE_KEY_VAULT_FILE` environment variable.
- Test `NuGetKeyVaultSignTool` in a package.
- Test `AzureSignTool` in a assembly file, show subject with `GetSignedFileSubject`.
- Test `AzureSignTool` in a install.exe file.

[vNext]: ../../compare/1.0.0...HEAD
[1.0.0]: ../../compare/1.0.0
45 changes: 45 additions & 0 deletions Nuke.NuGetKeyVaultSignTool/AzureKeyVaultConfig.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,59 @@
namespace Nuke.NuGetKeyVaultSignTool
{
/// <summary>
/// Represents the configuration for Azure Key Vault.
/// </summary>
public class AzureKeyVaultConfig
{
/// <summary>
/// Gets or sets the Azure Key Vault certificate.
/// </summary>
public string AzureKeyVaultCertificate { get; set; }

/// <summary>
/// Gets or sets the Azure Key Vault URL.
/// </summary>
public string AzureKeyVaultUrl { get; set; }

/// <summary>
/// Gets or sets the Azure Key Vault client ID.
/// </summary>
public string AzureKeyVaultClientId { get; set; }

/// <summary>
/// Gets or sets the Azure Key Vault tenant ID.
/// </summary>
public string AzureKeyVaultTenantId { get; set; }

/// <summary>
/// Gets or sets the timestamp URL.
/// </summary>
public string TimestampUrl { get; set; }

/// <summary>
/// Gets or sets the timestamp digest.
/// </summary>
public string TimestampDigest { get; set; }

/// <summary>
/// Creates an instance of <see cref="AzureKeyVaultConfig"/> from the specified JSON content.
/// </summary>
/// <param name="jsonContent">The JSON content representing the Azure Key Vault configuration.</param>
/// <returns>An instance of <see cref="AzureKeyVaultConfig"/>.</returns>
public static AzureKeyVaultConfig Create(string jsonContent)
{
try
{
return Newtonsoft.Json.JsonConvert.DeserializeObject<AzureKeyVaultConfig>(jsonContent);
}
catch { }
return default;
}

/// <summary>
/// Checks if the Azure Key Vault configuration is valid.
/// </summary>
/// <returns><c>true</c> if the configuration is valid; otherwise, <c>false</c>.</returns>
public bool IsValid()
{
return !string.IsNullOrEmpty(AzureKeyVaultCertificate) &&
Expand Down
14 changes: 11 additions & 3 deletions Nuke.NuGetKeyVaultSignTool/AzureKeyVaultConfigTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using NUnit.Framework;
using Newtonsoft.Json;

namespace Nuke.NuGetKeyVaultSignTool
{
Expand All @@ -17,11 +16,20 @@ public void JsonIsNotValidTest()
}
""";

var azureKeyVaultFile = JsonConvert.DeserializeObject<AzureKeyVaultConfig>(content);
var azureKeyVaultFile = AzureKeyVaultConfig.Create(content);
Assert.IsNotNull(azureKeyVaultFile);
Assert.IsFalse(azureKeyVaultFile.IsValid());
}

[Test]
public void JsonIsNullTest()
{
var content = "";

var azureKeyVaultFile = AzureKeyVaultConfig.Create(content);
Assert.IsNull(azureKeyVaultFile);
}

[Test]
public void JsonIsValidTest()
{
Expand All @@ -34,7 +42,7 @@ public void JsonIsValidTest()
}
""";

var azureKeyVaultFile = JsonConvert.DeserializeObject<AzureKeyVaultConfig>(content);
var azureKeyVaultFile = AzureKeyVaultConfig.Create(content);
Assert.IsNotNull(azureKeyVaultFile);
Assert.IsTrue(azureKeyVaultFile.IsValid());
Assert.AreEqual("AzureKeyVaultCertificate", azureKeyVaultFile.AzureKeyVaultCertificate);
Expand Down
4 changes: 2 additions & 2 deletions Nuke.NuGetKeyVaultSignTool/AzureSignToolTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using NUnit.Framework;
using System.IO;
using System.Reflection;
using Nuke.Common.Tools.NuGetKeyVaultSignTool;
using Nuke.Common.Tools.AzureSignTool;
using Nuke.CodeGeneration;
using Newtonsoft.Json;
Expand Down Expand Up @@ -51,6 +50,7 @@ public void SetUpAzureSignToolTasks()
}

[TestCase("Files/assembly.dll")]
[TestCase("Files/install.exe")]
public void SignFile(string fileName)
{
if (string.IsNullOrEmpty(AZURE_KEY_VAULT_FILE))
Expand All @@ -59,7 +59,7 @@ public void SignFile(string fileName)
if (string.IsNullOrEmpty(AZURE_KEY_VAULT_PASSWORD))
Assert.Ignore("AZURE_KEY_VAULT_PASSWORD is null.");

var azureKeyVaultFile = JsonConvert.DeserializeObject<AzureKeyVaultConfig>(AZURE_KEY_VAULT_FILE);
var azureKeyVaultFile = AzureKeyVaultConfig.Create(AZURE_KEY_VAULT_FILE);
var azureKeyVaultClientSecret = AZURE_KEY_VAULT_PASSWORD;

if (azureKeyVaultFile.IsValid() == false)
Expand Down
Binary file added Nuke.NuGetKeyVaultSignTool/Files/install.exe
Binary file not shown.
2 changes: 1 addition & 1 deletion Nuke.NuGetKeyVaultSignTool/NuGetKeyVaultSignToolTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void SignPackage(string fileName)
if (string.IsNullOrEmpty(AZURE_KEY_VAULT_PASSWORD))
Assert.Ignore("AZURE_KEY_VAULT_PASSWORD is null.");

var azureKeyVaultFile = JsonConvert.DeserializeObject<AzureKeyVaultConfig>(AZURE_KEY_VAULT_FILE);
var azureKeyVaultFile = AzureKeyVaultConfig.Create(AZURE_KEY_VAULT_FILE);
var azureKeyVaultClientSecret = AZURE_KEY_VAULT_PASSWORD;

if (azureKeyVaultFile.IsValid() == false)
Expand Down
3 changes: 3 additions & 0 deletions Nuke.NuGetKeyVaultSignTool/Nuke.NuGetKeyVaultSignTool.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
<None Update="Files\assembly.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Files\install.exe">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Files\package.nupkg">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down

0 comments on commit 108d63d

Please sign in to comment.