Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
Remove closed port tests (#722)
Jakub Novák106d0a7715cb
diff --git a/packages/js-sdk/tests/sandbox/closed_port.test.ts b/packages/js-sdk/tests/sandbox/closed_port.test.tsdeleted file mode 100644index 914e844f0..000000000--- a/packages/js-sdk/tests/sandbox/closed_port.test.ts+++ /dev/null@@ -1,95 +0,0 @@-import { assert, test } from 'vitest'--import { Sandbox } from '../../src/index.js'-import { isDebug, template, wait } from '../setup.js'-import { catchCmdExitErrorInBackground } from '../cmdHelper.js'--test.skipIf(isDebug)('closed port in SDK', async () => {- const sbx = await Sandbox.create(template, { timeoutMs: 60_000 })- const goodPort = 8000-- const cmd = await sbx.commands.run(`python -m http.server ${goodPort}`, {- background: true,- })-- const disable = catchCmdExitErrorInBackground(cmd)-- const goodHost = sbx.getHost(goodPort)- // leave this here as a helper to visit host in browser- console.log('goodHost', 'https://' + goodHost)-- let res2 = await fetch(`${isDebug ? 'http' : 'https'}://${goodHost}`)-- for (let i = 0; i < 20; i++) {- if (res2.status === 200) {- break- }-- res2 = await fetch(`${isDebug ? 'http' : 'https'}://${goodHost}`)- await wait(500)- }- assert.equal(res2.status, 200)-- const badPort = 3000- const badHost = sbx.getHost(badPort)- // leave this here as a helper to visit host in browser- console.log('badHost', 'https://' + badHost)-- // Test as non-browser user agent- const res = await fetch(`${isDebug ? 'http' : 'https'}://${badHost}`)- assert.equal(res.status, 502)- const resp_text = await res.text()- const resp = JSON.parse(resp_text)- const [cleanedSbxId] = sbx.sandboxId.split('-')-- assert.equal(resp.message, 'The sandbox is running but port is not open')- assert.equal(cleanedSbxId, resp.sandboxId)- assert.equal(resp.port, badPort)- disable()-})--test.skipIf(isDebug)('closed port in browser ', async () => {- const sbx = await Sandbox.create(template, { timeoutMs: 60_000 })- const goodPort = 8000-- const cmd = await sbx.commands.run(`python -m http.server ${goodPort}`, {- background: true,- })-- const disable = catchCmdExitErrorInBackground(cmd)-- await wait(1000)-- const goodHost = sbx.getHost(goodPort)- // leave this here as a helper to visit host in browser- console.log('goodHost', 'https://' + goodHost)-- let res2 = await fetch(`${isDebug ? 'http' : 'https'}://${goodHost}`)-- for (let i = 0; i < 20; i++) {- if (res2.status === 200) {- break- }-- res2 = await fetch(`${isDebug ? 'http' : 'https'}://${goodHost}`)- await wait(500)- }- assert.equal(res2.status, 200)-- const badPort = 3000- const badHost = sbx.getHost(badPort)- // leave this here as a helper to visit host in browser- console.log('badHost', 'https://' + badHost)-- // Test as browser user agent- const res = await fetch(`${isDebug ? 'http' : 'https'}://${badHost}`, {- headers: {- 'User-Agent':- 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36',- },- })- assert.equal(res.status, 502)- const resp_text = await res.text()- assert(resp_text.includes('<title>Closed Port Error</title>'))- disable()-})diff --git a/packages/python-sdk/tests/async/sandbox_async/test_port_closed.py b/packages/python-sdk/tests/async/sandbox_async/test_port_closed.pydeleted file mode 100644index 96bc8476e..000000000--- a/packages/python-sdk/tests/async/sandbox_async/test_port_closed.py+++ /dev/null@@ -1,58 +0,0 @@-import pytest-import asyncio-import json-import httpx-from e2b import AsyncSandbox---async def test_port_closed(template, helpers):- sbx = await AsyncSandbox.create(template, timeout=60)- try:- assert await sbx.is_running()-- good_port = 8002- # Start a Python HTTP server on port 8002- cmd = await sbx.commands.run(- f"python -m http.server {good_port}",- background=True,- )-- disable = helpers.catch_cmd_exit_error_in_background(cmd)-- await asyncio.sleep(1) # Wait for server to start-- # Test good port (8002)- good_host = sbx.get_host(good_port)- async with httpx.AsyncClient() as client:- for _ in range(20):- try:- response = await client.get(f"https://{good_host}")- if response.status_code == 200:- break- except httpx.RequestError:- pass- await asyncio.sleep(0.5)- assert response.status_code == 200-- # Test bad port (3000)- bad_port = 3000- bad_host = sbx.get_host(bad_port)- async with httpx.AsyncClient() as client:- for _ in range(20):- try:- response = await client.get(f"https://{bad_host}")- if response.status_code == 502:- break- except httpx.RequestError:- pass- await asyncio.sleep(0.5)- assert response.status_code == 502- resp_text = response.text- resp = json.loads(resp_text)- cleaned_sbx_id = sbx.sandbox_id.split("-")[0]- assert resp["message"] == "The sandbox is running but port is not open"- assert cleaned_sbx_id == resp["sandboxId"]- assert resp["port"] == bad_port- disable()- finally:- await sbx.kill()diff --git a/packages/python-sdk/tests/sync/sandbox_sync/test_port_closed.py b/packages/python-sdk/tests/sync/sandbox_sync/test_port_closed.pydeleted file mode 100644index 7dd88bbcf..000000000--- a/packages/python-sdk/tests/sync/sandbox_sync/test_port_closed.py+++ /dev/null@@ -1,57 +0,0 @@-import pytest-import json-import httpx-import time-from e2b import Sandbox---def test_port_closed(template, helpers):- sbx = Sandbox(template, timeout=60)- try:- assert sbx.is_running()-- good_port = 8004- # Start a Python HTTP server on port 8004- cmd = sbx.commands.run(- f"python -m http.server {good_port}",- background=True,- )- time.sleep(1) # Wait for server to start-- # Test good port (8004)- good_host = sbx.get_host(good_port)- with httpx.Client() as client:- for _ in range(10):- try:- response = client.get(f"https://{good_host}")- if response.status_code == 200:- break- except httpx.RequestError:- pass- time.sleep(0.5)- assert response.status_code == 200-- # Test bad port (3000)- bad_port = 3000- bad_host = sbx.get_host(bad_port)- with httpx.Client() as client:- for _ in range(10):- try:- response = client.get(f"https://{bad_host}")- if response.status_code == 502:- break- except httpx.RequestError:- pass- time.sleep(0.5)- assert response.status_code == 502- resp_text = response.text- resp = json.loads(resp_text)- cleaned_sbx_id = sbx.sandbox_id.split("-")[0]- assert resp["message"] == "The sandbox is running but port is not open"- assert cleaned_sbx_id == resp["sandboxId"]- assert resp["port"] == bad_port- except Exception as e:- helpers.check_cmd_exit_error(cmd)- raise e- finally:- sbx.kill()