mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-25 23:17:58 +00:00
fix(agent): remove port from sandbox pendingDomains to match allowedDomains format
This commit is contained in:
@@ -114,7 +114,7 @@ describe('Sandbox Network isolation integration', () => {
|
||||
const sandbox = await prisma.sandbox.findUnique({
|
||||
where: { teamId: team.id },
|
||||
})
|
||||
expect(sandbox?.pendingDomains).toContain('blocked-api.com:443')
|
||||
expect(sandbox?.pendingDomains).toContain('blocked-api.com')
|
||||
|
||||
// 7. Verify that if the bash tool is run while a domain is blocked, it rejects with correct error
|
||||
const sandboxState = { blockedHost: '' }
|
||||
@@ -131,7 +131,7 @@ describe('Sandbox Network isolation integration', () => {
|
||||
|
||||
// Mock spawn to simulate process exit and trigger network block
|
||||
mockSpawn = () => {
|
||||
sandboxState.blockedHost = 'blocked-api.com:443'
|
||||
sandboxState.blockedHost = 'blocked-api.com'
|
||||
const mockChild = {
|
||||
pid: 123,
|
||||
stdout: { on: vi.fn() },
|
||||
@@ -149,7 +149,7 @@ describe('Sandbox Network isolation integration', () => {
|
||||
|
||||
try {
|
||||
await expect(bashPromise).rejects.toThrow(
|
||||
'Network request to blocked-api.com:443 is blocked, please ask admin to allow it in sandbox settings.',
|
||||
'Network request to blocked-api.com is blocked, please ask admin to allow it in sandbox settings.',
|
||||
)
|
||||
} finally {
|
||||
mockSpawn = null
|
||||
@@ -249,7 +249,7 @@ describe('Sandbox Network isolation integration', () => {
|
||||
const sandbox2 = await prisma.sandbox.findUnique({
|
||||
where: { teamId: team2.id },
|
||||
})
|
||||
expect(sandbox2?.pendingDomains).toContain('blocked-for-session-2.com:443')
|
||||
expect(sandbox2?.pendingDomains).toContain('blocked-for-session-2.com')
|
||||
} finally {
|
||||
initializeSpy.mockRestore()
|
||||
resetSpy.mockRestore()
|
||||
|
||||
@@ -122,24 +122,22 @@ export async function createAgentSession(params: CreateAgentSessionParams) {
|
||||
blockedHost: '',
|
||||
}
|
||||
|
||||
const sandboxAskCallback = async ({ host, port }: { host: string; port?: number }) => {
|
||||
const hostPort = port ? `${host}:${port}` : host
|
||||
|
||||
const sandboxAskCallback = async ({ host }: { host: string; port?: number }) => {
|
||||
try {
|
||||
const sandbox = await prisma.sandbox.findUnique({
|
||||
where: { teamId },
|
||||
})
|
||||
const pendingDomains = sandbox?.pendingDomains || []
|
||||
if (!pendingDomains.includes(hostPort)) {
|
||||
if (!pendingDomains.includes(host)) {
|
||||
await prisma.sandbox.upsert({
|
||||
where: { teamId },
|
||||
create: {
|
||||
teamId,
|
||||
pendingDomains: [hostPort],
|
||||
pendingDomains: [host],
|
||||
},
|
||||
update: {
|
||||
pendingDomains: {
|
||||
push: hostPort,
|
||||
push: host,
|
||||
},
|
||||
},
|
||||
})
|
||||
@@ -148,7 +146,7 @@ export async function createAgentSession(params: CreateAgentSessionParams) {
|
||||
console.error('Failed to update sandbox pending domains:', err)
|
||||
}
|
||||
|
||||
sandboxState.blockedHost = hostPort
|
||||
sandboxState.blockedHost = host
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user