跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

浏览文件

claude-desktop-windows.tests.ps1

101 行 · 4.8 KB历史下载
1#requires -Version 5.1
2# Run on any platform with PowerShell. The tests never call Windows deployment APIs.
3$ErrorActionPreference = 'Stop'
4. (Join-Path $PSScriptRoot 'claude-desktop-windows.ps1')
5
6function Expect-Failure([scriptblock]$action, [string]$reason) {
7 try { & $action } catch {
8 if ($_.Exception.Message.Contains($reason)) { return }
9 throw
10 }
11 throw "Expected rejection: $reason"
12}
13
14$subject = [Security.Cryptography.X509Certificates.X500DistinguishedName]::new($publisher)
15$signature = [pscustomobject]@{ Status = 'Valid'; SignerCertificate = @{ SubjectName = $subject } }
16Assert-ClaudeSignature $signature
17$signature.Status = 'HashMismatch'
18Expect-Failure { Assert-ClaudeSignature $signature } 'did not validate'
19$signature.Status = 'Valid'
20$lookalike = $publisher.Replace('4860621', '1234567')
21$signature.SignerCertificate.SubjectName = [Security.Cryptography.X509Certificates.X500DistinguishedName]::new($lookalike)
22Expect-Failure { Assert-ClaudeSignature $signature } 'does not match'
23
24$manifest = [xml]@'
25<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10">
26 <Identity Name="Claude" Version="4.23118.0.0" ProcessorArchitecture="x64"/>
27 <Applications>
28 <Application Id="SshProxy" Executable="app\resources\claude-ssh-proxy.exe"/>
29 <Application Id="Claude" Executable="app\Claude.exe" EntryPoint="Windows.FullTrustApplication"/>
30 </Applications>
31</Package>
32'@
33$manifest.Package.Identity.SetAttribute('Publisher', $publisher)
34if ((Assert-ClaudeManifest $manifest) -ne [version]'4.23118.0.0') { throw 'Version mismatch.' }
35$wrongApp = $manifest.Clone()
36$wrongApp.Package.Applications.Application[1].SetAttribute('Executable', 'app\helper.exe')
37Expect-Failure { Assert-ClaudeManifest $wrongApp } 'entry point'
38
39function Get-AppxPackage { $pkg }
40function Get-AppxPackageManifest { $manifest }
41$pkg = [pscustomobject]@{
42 PackageFamilyName = 'OtherFamily'; IsDevelopmentMode = $false; IsPartiallyStaged = $false
43 SignatureKind = 'Developer'; Status = 'Ok'; Publisher = $publisher
44 PackageFullName = 'test-fixture'; InstallLocation = $PSScriptRoot
45}
46if (Get-RegisteredClaude) { throw 'An unrelated package was accepted.' }
47$pkg.PackageFamilyName = $packageFamily
48if ((Get-RegisteredClaude).Aumid -cne 'Claude_pzs8sxrjxfjjc!Claude') { throw 'Incorrect AUMID.' }
49$pkg.IsDevelopmentMode = $true
50Expect-Failure { Get-RegisteredClaude } 'registered Claude package'
51
52# Execute the actual install path against a local archive. Mock just the
53# operating-system signature and registration results, never deploy this fixture.
54$fixture = Join-Path ([IO.Path]::GetTempPath()) (([Guid]::NewGuid().ToString()) + '.msix')
55$installedCount = 0
56function Get-AuthenticodeSignature { $signature }
57function Add-AppxPackage {
58 if ($deploymentError) { throw $deploymentError }
59 $script:installedCount++
60 $script:pkg.PackageFamilyName = $packageFamily
61}
62try {
63 Add-Type -AssemblyName System.IO.Compression
64 $handle = [IO.File]::Open($fixture, 'CreateNew', 'Write', 'None')
65 try {
66 $zip = [IO.Compression.ZipArchive]::new($handle, 'Create', $true)
67 try {
68 $stream = $zip.CreateEntry('AppxManifest.xml').Open()
69 try { $manifest.Save($stream) } finally { $stream.Dispose() }
70 } finally { $zip.Dispose() }
71 } finally { $handle.Dispose() }
72 $signature.Status = 'NotSigned'
73 Expect-Failure { Install-ClaudeMsix $fixture } 'did not validate'
74 $signature.Status = 'Valid'
75 Expect-Failure { Install-ClaudeMsix $fixture } 'does not match'
76 if ($installedCount -ne 0) { throw 'An untrusted package reached Add-AppxPackage.' }
77 $signature.SignerCertificate.SubjectName = $subject
78 $pkg.IsDevelopmentMode = $false
79 $pkg.PackageFamilyName = 'absent'
80 $deploymentError = 'Deployment failed: 0x80073D28'
81 Expect-Failure { Install-ClaudeMsix $fixture } 'requires guest administrator rights'
82 $deploymentError = 'Deployment failed: 0x80073CF6'
83 Expect-Failure { Install-ClaudeMsix $fixture } '0x80073CF6'
84 $deploymentError = $null
85 $first = Install-ClaudeMsix $fixture
86 $again = Install-ClaudeMsix $fixture
87 if (!$first.Registered -or !$again.Registered -or $installedCount -ne 1) {
88 throw 'Expected exactly one registration after two Install actions.'
89 }
90} finally { if ([IO.File]::Exists($fixture)) { [IO.File]::Delete($fixture) } }
91
92$target = [Guid]::NewGuid()
93$kvpId = $target.ToString()
94$computer = @{ Manufacturer = 'Microsoft Corporation'; Model = 'Virtual Machine' }
95function Get-CimInstance { $computer }
96function Get-ItemProperty { @{ VirtualMachineId = $kvpId } }
97Assert-TargetGuest $target
98Expect-Failure { Assert-TargetGuest ([Guid]::NewGuid()) } 'does not match'
99$computer.Model = 'Surface'
100Expect-Failure { Assert-TargetGuest $target } 'requires a Hyper-V guest'
101Write-Output 'Passed Claude manifest, signing, repeat install, registration and Hyper-V guest identity checks (simulated).'