Răsfoiți Sursa

fix: 迁移授权资料前核对托管网络身份

Samien 1 lună în urmă
părinte
comite
ae5cd221a2

+ 4 - 0
src/runner/computers/container.ts

@@ -300,6 +300,10 @@ export class ContainerComputerProvider implements ComputerProvider {
       if(!detail)return false
       this.assertOwned(spec,detail)
       if(this.hasUserData(detail)){if(!await this.userData.existing(spec))throw new Error('电脑用户资料缺失');return false}
+      if(spec.network==='managed-proxy'){
+        const gateway=await this.inspectRaw(this.name(spec)+'-network')
+        this.assertNetwork(spec,gateway);this.networkIds.set(spec.id,gateway.Id)
+      }
       this.assertConfiguration(spec,detail,await this.workspace(spec),true)
       await this.stopOwned(spec,detail.Id)
       await this.userData.capture(spec,detail.Id,true)

+ 5 - 1
tests/live/computerAuth.live.test.ts

@@ -10,7 +10,7 @@ import {ComputerMaintenance} from '../../src/runner/computers/maintenance'
 it.skipIf(!process.env.YAOYAO_COMPUTER_IMAGE)('migrates a legacy home and keeps real browser and encrypted application authorization through rebuild and restore',async()=>{
   const home=await mkdtemp(join(tmpdir(),'yaoyao-auth-live-'))
   const provider=new ContainerComputerProvider('docker',randomUUID(),home)
-  const spec:ComputerSpecification={id:randomUUID(),ownerKey:randomUUID(),imageId:process.env.YAOYAO_COMPUTER_IMAGE!}
+  const spec:ComputerSpecification={id:randomUUID(),ownerKey:randomUUID(),imageId:process.env.YAOYAO_COMPUTER_IMAGE!,network:process.env.YAOYAO_COMPUTER_NETWORK==='managed-proxy'?'managed-proxy':'none'}
   const script=await readFile(new URL('../fixtures/computer_auth.mjs',import.meta.url),'utf8')
   const execute=(argv:string[],user:'cua'|'root'='cua')=>provider.execute(spec,argv,{authorize:()=>{},user,timeout:60000}).catch(error=>{throw new Error(`${argv[0]} ${argv.at(-1)}: ${error.stderr??error.message}`)})
   const maintenance=new ComputerMaintenance({status:()=>[{environmentId:spec.id,status:'free'}]} as any,provider,home)
@@ -18,11 +18,15 @@ it.skipIf(!process.env.YAOYAO_COMPUTER_IMAGE)('migrates a legacy home and keeps
   try{
     // Exercise the real upgrade path from the old workspace-only container.
     const workspace=await (provider as any).workspace(provider.validateSpecification(spec))
+    if(spec.network==='managed-proxy')await (provider as any).ensureNetwork(provider.validateSpecification(spec),()=>{})
     const created=await provider.run('docker',(provider as any).args(provider.validateSpecification(spec),workspace))
     const legacyId=created.stdout.trim();await provider.run('docker',['start',legacyId])
     expect(JSON.parse((await execute(['node','--input-type=module','-e',script,'login'])).stdout)).toEqual({browser:true,encryptedApplicationToken:true})
     await execute(['sh','-c','mkdir -p /root/.config; printf root-fixture > /root/.config/authorization'],'root')
     const identity=(await execute(['cat','/var/lib/dbus/machine-id'])).stdout
+    // The updater uses a fresh provider without a cached gateway identity.
+    const migration=new ContainerComputerProvider('docker',provider.runnerId,home)
+    expect(await migration.preserveUserData(spec)).toBe(true)
     await provider.remove(spec)
     const migrated=await provider.ensure(spec,()=>{})
     expect(migrated.containerId).not.toBe(legacyId)