chore: 保存工作副本——客户端授权新契约(双端点/验签/令牌/周检)与桌面会话可靠性改进
This commit is contained in:
1 parent
f71eef0eba
commit
ae6093c9b3
163 files changed
+4911
-2494
No files matched your search
@@ -0,0 +1,60 @@
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import { startNativeForward, stopNativeForward } from '../../../src/components/connection/forwardRuntime'
|
||||
import type { ForwardRule } from '../../../src/components/connection/forwardRules'
|
||||
|
||||
const localRule: ForwardRule = {
|
||||
id: 'pf-local',
|
||||
type: 'local',
|
||||
name: 'db',
|
||||
localPort: 3306,
|
||||
localBindHost: '127.0.0.1',
|
||||
remoteHost: '127.0.0.1',
|
||||
remotePort: 3306,
|
||||
}
|
||||
|
||||
describe('forwardRuntime', () => {
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks()
|
||||
})
|
||||
|
||||
it('starts a local forward through the native API', async () => {
|
||||
const sshForwardLocal = vi
|
||||
.spyOn(window.opsxApi, 'sshForwardLocal')
|
||||
.mockResolvedValue({ success: true, forwardId: 'pf-local' })
|
||||
|
||||
await expect(startNativeForward('conn-1', localRule)).resolves.toEqual({
|
||||
success: true,
|
||||
error: undefined,
|
||||
errorCode: undefined,
|
||||
})
|
||||
expect(sshForwardLocal).toHaveBeenCalledWith('conn-1', 3306, '127.0.0.1', 3306, 'pf-local', '127.0.0.1')
|
||||
})
|
||||
|
||||
it('stops by runtime tunnel id when the persisted rule id misses', async () => {
|
||||
const sshForwardStop = vi
|
||||
.spyOn(window.opsxApi, 'sshForwardStop')
|
||||
.mockResolvedValueOnce({ success: false, error: 'missing' })
|
||||
.mockResolvedValueOnce({ success: true })
|
||||
vi.spyOn(window.opsxApi, 'sshForwardList').mockResolvedValue({
|
||||
success: true,
|
||||
tunnels: [
|
||||
{
|
||||
forwardId: 'runtime-9',
|
||||
connectionId: 'conn-1',
|
||||
kind: 'local',
|
||||
bindHost: '127.0.0.1',
|
||||
boundPort: 3306,
|
||||
startedAt: 1,
|
||||
running: true,
|
||||
activeConnections: 0,
|
||||
bytesUp: 0,
|
||||
bytesDown: 0,
|
||||
},
|
||||
],
|
||||
})
|
||||
|
||||
await expect(stopNativeForward('conn-1', localRule)).resolves.toMatchObject({ success: true })
|
||||
expect(sshForwardStop).toHaveBeenNthCalledWith(1, 'pf-local')
|
||||
expect(sshForwardStop).toHaveBeenNthCalledWith(2, 'runtime-9')
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user