From 44dad927fb6c5346ee3549a587782b42b5b2df68 Mon Sep 17 00:00:00 2001 From: Alexander Holstrup <117829001+aholstrup1@users.noreply.github.com> Date: Wed, 2 Dec 2026 13:50:23 +0100 Subject: [PATCH] Fail signing when the native signing tool returns an error --- Actions/Sign/Sign.psm1 | 5 +++ RELEASENOTES.md | 2 ++ Scenarios/Codesigning.md | 2 ++ Tests/Sign.Test.ps1 | 68 +++++++++++++++++++++++++++++++++++++++- 4 files changed, 76 insertions(+), 1 deletion(-) diff --git a/Actions/Sign/Sign.psm1 b/Actions/Sign/Sign.psm1 index 6ec3890be1..004a13ab20 100644 --- a/Actions/Sign/Sign.psm1 +++ b/Actions/Sign/Sign.psm1 @@ -157,6 +157,11 @@ function Invoke-SigningTool() { $FilesToSign } } + + $signingExitCode = $LASTEXITCODE + if ($signingExitCode -ne 0) { + throw "Signing tool failed with exit code $signingExitCode." + } } Export-ModuleMember -Function Invoke-SigningTool diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 65efbb7a15..c7500378d5 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -1,5 +1,7 @@ ### Issues +- Issue 2452 - Fail the signing action when the signing tool returns a nonzero exit code for Trusted Signing or Azure Key Vault signing. + - Issue 2405 - Fix AppSource publishing failures reporting duplicate extension IDs when multiple versions of the same dependency are included. Only the highest included version is submitted. ## v10.1 diff --git a/Scenarios/Codesigning.md b/Scenarios/Codesigning.md index b3b8eebf68..f7ab95fd78 100644 --- a/Scenarios/Codesigning.md +++ b/Scenarios/Codesigning.md @@ -4,6 +4,8 @@ On June 1st 2023 the industry standards for storing code signing certificates ch This guide will take you through how to set up your AL-Go project with an Azure Key Vault and how to use a certificate in the Key Vault to perform code signing. Before you get started, please make sure you've set up your AL-Go project with an Azure Key Vault by following [Scenario 7: Use Azure KeyVault for secrets with AL-Go](./UseAzureKeyVault.md). +For both Azure Key Vault and Trusted Signing, a nonzero signing-tool exit code fails the signing action and is included in the error message. Individual diagnostic log messages do not determine whether signing succeeded. + > [!NOTE] > If your code signing certificate was issued after June 1st 2023 you will most likely need to create a Premium SKU Key Vault. You can [learn more about the differences between Standard and Premium SKU here](https://azure.microsoft.com/en-us/pricing/details/key-vault/) diff --git a/Tests/Sign.Test.ps1 b/Tests/Sign.Test.ps1 index 5fd757918d..3b6b6ea1c9 100644 --- a/Tests/Sign.Test.ps1 +++ b/Tests/Sign.Test.ps1 @@ -1,7 +1,12 @@ -Get-Module TestActionsHelper | Remove-Module -Force +[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSReviewUnusedParameter', '', Justification = 'Test case parameters are used inside Pester assertion scriptblocks')] +param() + +Get-Module TestActionsHelper | Remove-Module -Force Import-Module (Join-Path $PSScriptRoot 'TestActionsHelper.psm1') $errorActionPreference = "Stop"; $ProgressPreference = "SilentlyContinue"; Set-StrictMode -Version 2.0 +Import-Module (Join-Path $PSScriptRoot '..\Actions\Sign\Sign.psm1') -Force -DisableNameChecking + Describe "Sign Action Tests" { BeforeAll { $actionName = "Sign" @@ -26,3 +31,64 @@ Describe "Sign Action Tests" { # Call action } + +InModuleScope Sign { + $signingTestCases = @( + @{ + Name = 'Trusted Signing' + SigningParameters = @{ + SigningEndpoint = 'https://example.com' + SigningAccount = 'test-account' + SigningCertificateProfile = 'test-profile' + } + }, + @{ + Name = 'Key Vault client secret' + SigningParameters = @{ + KeyVaultName = 'test-vault' + CertificateName = 'test-certificate' + ClientId = 'test-client' + ClientSecret = 'test-secret' + TenantId = 'test-tenant' + } + }, + @{ + Name = 'Key Vault managed identity' + SigningParameters = @{ + KeyVaultName = 'test-vault' + CertificateName = 'test-certificate' + } + } + ) + + Describe 'Signing tool exit status' { + BeforeEach { + $script:signingExitCode = 0 + Mock Install-SigningTool { + return { + # Exercise native exit codes without installing the signer or contacting Azure. + $PSNativeCommandUseErrorActionPreference = $false + & (Get-Process -Id $PID).Path -NoProfile -NonInteractive -Command "exit $script:signingExitCode" + } + } + } + + It 'Fails with the native exit code for ' -TestCases $signingTestCases { + param($Name, $SigningParameters) + + $script:signingExitCode = 23 + + { + Invoke-SigningTool @SigningParameters -FilesToSign '*.app' -Description $Name -DescriptionUrl 'https://example.com' + } | Should -Throw 'Signing tool failed with exit code 23.' + } + + It 'Succeeds with a zero native exit code for ' -TestCases $signingTestCases { + param($Name, $SigningParameters) + + { + Invoke-SigningTool @SigningParameters -FilesToSign '*.app' -Description $Name -DescriptionUrl 'https://example.com' + } | Should -Not -Throw + } + } +}