From 48dc4a7479ccffbf6ec98a41f47086af04285bc6 Mon Sep 17 00:00:00 2001 From: margrop <1731827+margrop@users.noreply.github.com> Date: Tue, 3 Nov 2026 20:42:43 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E6=B5=8B=E8=AF=95=E8=AF=81=E4=B9=A6?= =?UTF-8?q?=E7=94=A8=E4=BE=8B=E7=9A=84=E7=AD=BE=E5=90=8D=E5=89=8D=E5=90=8E?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E6=94=B9=E7=94=A8=E5=90=8C=E4=B8=80=E7=A8=8B?= =?UTF-8?q?=E5=BA=8F=E9=9B=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 原件与签名件元数据不同,验证脚本按设计拦截,导致用例失败。 Co-Authored-By: Claude Opus 5.5 --- tests/packaging/test-windows-signatures.ps1 | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/tests/packaging/test-windows-signatures.ps1 b/tests/packaging/test-windows-signatures.ps1 index a38b4849..5bdf0893 100644 --- a/tests/packaging/test-windows-signatures.ps1 +++ b/tests/packaging/test-windows-signatures.ps1 @@ -71,8 +71,16 @@ try { Assert-Rejected '签名后文件被篡改' $paths # 测试证书模式:用临时自签名证书模拟 SignPath 测试证书。 + # 签名前后须为同一文件,并带有产品名和版本,才能通过元数据比对。 + $unsignedFixture = Join-Path $taskDir 'unsigned.dll' $selfSignedFixture = Join-Path $taskDir 'self-signed.dll' - Add-Type -TypeDefinition 'public static class WrongNotebookSigningFixture {}' -OutputAssembly $selfSignedFixture -OutputType Library + $fixtureSource = @' +[assembly: System.Reflection.AssemblyProduct("WrongNotebook")] +[assembly: System.Reflection.AssemblyInformationalVersion("1.0.0")] +public static class WrongNotebookSigningFixture {} +'@ + Add-Type -TypeDefinition $fixtureSource -OutputAssembly $unsignedFixture -OutputType Library + Copy-Item -LiteralPath $unsignedFixture -Destination $selfSignedFixture $testCert = New-SelfSignedCertificate -Type CodeSigningCert -Subject 'CN=WrongNotebook Signing Test' -CertStoreLocation Cert:\CurrentUser\My try { $result = Set-AuthenticodeSignature -LiteralPath $selfSignedFixture -Certificate $testCert @@ -82,12 +90,15 @@ try { } $paths = New-FixtureSet 'test-certificate' - foreach ($name in $names) { Copy-Item -LiteralPath $selfSignedFixture -Destination (Join-Path $paths.SignedDirectory $name) -Force } + foreach ($name in $names) { + Copy-Item -LiteralPath $unsignedFixture -Destination (Join-Path $paths.UnsignedDirectory $name) -Force + Copy-Item -LiteralPath $selfSignedFixture -Destination (Join-Path $paths.SignedDirectory $name) -Force + } $production = @{ UnsignedDirectory = $paths.UnsignedDirectory; SignedDirectory = $paths.SignedDirectory } Assert-Rejected '生产模式拒绝测试证书' $production & $verify @paths -TestCertificate foreach ($name in $names) { - if ((Get-FileHash -LiteralPath (Join-Path $paths.UnsignedDirectory $name)).Hash -ne (Get-FileHash -LiteralPath $fixture).Hash) { + if ((Get-FileHash -LiteralPath (Join-Path $paths.UnsignedDirectory $name)).Hash -ne (Get-FileHash -LiteralPath $unsignedFixture).Hash) { throw '测试证书模式不得覆盖发布文件' } }