跳到主要内容

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

浏览文件

hyperv_instance.ps1

55 行 · 3.4 KB历史下载
1# Exercise the bundled read-only query. No Hyper-V service or real VM is used.
2param([Parameter(Mandatory)][string]$Query)
3$ErrorActionPreference = 'Stop'
4$targetId = [Guid]::NewGuid()
5$global:hypervTestId = $targetId
6$global:hypervCase = 'single'
7function Get-CimInstance {
8 param($Namespace,$ClassName,$Filter)
9 if ($Namespace -ne 'root/virtualization/v2' -or $ClassName -ne 'Msvm_ComputerSystem' -or $Filter -ne "Name='$global:hypervTestId'") { throw 'Unscoped VM lookup.' }
10 if ($global:hypervCase -eq 'denied') { throw 'test management access denied' }
11 if ($global:hypervCase -ne 'absent') { [pscustomobject]@{Name=$global:hypervTestId} }
12}
13$fake = New-Module -Name Hyper-V -ScriptBlock {
14 function Get-VM {
15 param($Id)
16 if ($id -ne $global:hypervTestId) { throw 'Unscoped management lookup' }
17 $returned = if ($global:hypervCase -eq 'swapped') { [Guid]::NewGuid() } else { $id }
18 $generation = if ($global:hypervCase -eq 'legacy') { 1 } else { 2 }
19 $state = if ($global:hypervCase -eq 'connected') { 'Running' } else { 'Off' }
20 [pscustomobject]@{Id=$returned; Generation=$generation; State=$state}
21 }
22 function Get-VMHardDiskDrive {
23 param($VM)
24 [pscustomobject]@{Path='C:\private-qa\system.vhdx'}
25 if ($global:hypervCase -eq 'connected') { [pscustomobject]@{Path='C:\private-qa\second.vhdx'} }
26 }
27 function Get-VMNetworkAdapter { param($VM) if ($global:hypervCase -eq 'connected') { [pscustomobject]@{Name='adapter'} } }
28 function Get-VHD {
29 param($Path)
30 if ($global:hypervCase -eq 'disk-denied') { throw 'test disk metadata unavailable' }
31 if ($Path -cne 'C:\private-qa\system.vhdx') { throw 'Unexpected disk lookup' }
32 [pscustomobject]@{VhdFormat='VHDX'; VhdType='Dynamic'}
33 }
34 function Get-VMFirmware {param($VM) if ($VM.Generation -ne 2) { throw 'Legacy VM firmware query' }; [pscustomobject]@{SecureBoot='On'; SecureBootTemplate='MicrosoftWindows'} }
35 function Get-VMSecurity {param($VM) if ($VM.Generation -ne 2) { throw 'Legacy VM security query' }; [pscustomobject]@{TpmEnabled=$true} }
36 Export-ModuleMember -Function 'Get-*'
37}
38Import-Module $fake -Force
39function Result { (& $Query) | ConvertFrom-Json }
40$found = Result
41if ($found.state -ne 'Off' -or $found.generation -ne 2 -or $found.diskCount -ne 1 -or !$found.singleLocalVhdx -or $found.diskType -ne 'Dynamic' -or !$found.secureBoot -or !$found.virtualTpm -or $found.networkAdapterCount -ne 0) { throw 'Invalid offline VM observation' }
42if (($found | ConvertTo-Json -Compress).Contains('private-qa')) { throw 'Host disk path exposed' }
43$global:hypervCase='connected'; $running=Result
44if ($running.state -ne 'Running' -or $running.networkAdapterCount -ne 1 -or $running.diskCount -ne 2 -or $running.singleLocalVhdx) { throw 'Connected or multiple-disk VM misreported' }
45$global:hypervCase='disk-denied'
46if ($null -ne (Result).singleLocalVhdx) { throw 'Denied disk metadata reported as verified' }
47$global:hypervCase='legacy'; $legacy = Result
48if ($legacy.secureBoot -or $legacy.virtualTpm) { throw 'Legacy VM reported as secure boot/vTPM capable' }
49$global:hypervCase='absent'; if ($null -ne (Result)) { throw 'Unexpected VM for missing ID' }
50foreach ($testCase in @('denied', 'swapped')) {
51 $global:hypervCase = $testCase
52 $rejected = $false
53 try { $null = Result } catch { $rejected = $true }
54 if (!$rejected) { throw 'Access failure or changed VM identity treated as a valid lookup' }
55}