Skip to content

armgit / E2B

Public Imported from GitHub
0

Open-source, secure environment with real-world tools for enterprise-grade agents.

Added skip if debug for some tests (#737)

Mish Ushakovbf7e862a0703
diff --git a/packages/js-sdk/tests/sandbox/commands/envVars.test.ts b/packages/js-sdk/tests/sandbox/commands/envVars.test.ts
index 4b9406ac3..87cd1864f 100644
--- a/packages/js-sdk/tests/sandbox/commands/envVars.test.ts
+++ b/packages/js-sdk/tests/sandbox/commands/envVars.test.ts
@@ -1,4 +1,4 @@
-import { assert } from 'vitest'
+import { assert, test } from 'vitest'
import { sandboxTest, isDebug, template } from '../../setup.js'
import { Sandbox } from '../../../src'
@@ -10,7 +10,7 @@ sandboxTest.skipIf(isDebug)('env vars', async ({ sandbox }) => {
assert.equal(cmd.stdout.trim(), 'bar')
})
-sandboxTest.skipIf(isDebug)('env vars on sandbox', async () => {
+test.skipIf(isDebug)('env vars on sandbox', async () => {
const sandbox = await Sandbox.create(template, { envs: { FOO: 'bar' } })
try {
diff --git a/packages/js-sdk/tests/sandbox/connect.test.ts b/packages/js-sdk/tests/sandbox/connect.test.ts
index cff3c8fef..b1efb9520 100644
--- a/packages/js-sdk/tests/sandbox/connect.test.ts
+++ b/packages/js-sdk/tests/sandbox/connect.test.ts
@@ -3,7 +3,7 @@ import { assert, test, expect } from 'vitest'
import { Sandbox } from '../../src'
import { isDebug, sandboxTest, template } from '../setup.js'
-test('connect', async () => {
+test.skipIf(isDebug)('connect', async () => {
const sbx = await Sandbox.create(template, { timeoutMs: 10_000 })
try {
@@ -29,7 +29,9 @@ sandboxTest.skipIf(isDebug)(
const connectPromise = Sandbox.connect(sandbox.sandboxId)
await expect(connectPromise).rejects.toThrowError(
- expect.objectContaining({ message: `404: sandbox "${sandbox.sandboxId}" doesn't exist or you don't have access to it` })
+ expect.objectContaining({
+ message: `404: sandbox "${sandbox.sandboxId}" doesn't exist or you don't have access to it`,
+ })
)
}
)
diff --git a/packages/js-sdk/tests/sandbox/create.test.ts b/packages/js-sdk/tests/sandbox/create.test.ts
index 47a9b371e..485e06264 100644
--- a/packages/js-sdk/tests/sandbox/create.test.ts
+++ b/packages/js-sdk/tests/sandbox/create.test.ts
@@ -1,4 +1,4 @@
-import { test, assert } from 'vitest'
+import { assert, test } from 'vitest'
import { Sandbox } from '../../src'
import { template, isDebug } from '../setup.js'
diff --git a/packages/js-sdk/tests/sandbox/files/rename.test.ts b/packages/js-sdk/tests/sandbox/files/rename.test.ts
index 1c23f7ccc..936162172 100644
--- a/packages/js-sdk/tests/sandbox/files/rename.test.ts
+++ b/packages/js-sdk/tests/sandbox/files/rename.test.ts
@@ -26,5 +26,7 @@ sandboxTest('rename non-existing file', async ({ sandbox }) => {
const oldFilename = 'non_existing_file.txt'
const newFilename = 'new_non_existing_file.txt'
- await expect(sandbox.files.rename(oldFilename, newFilename)).rejects.toThrowError(NotFoundError)
+ await expect(
+ sandbox.files.rename(oldFilename, newFilename)
+ ).rejects.toThrowError(NotFoundError)
})
diff --git a/packages/js-sdk/tests/sandbox/files/signing.test.ts b/packages/js-sdk/tests/sandbox/files/signing.test.ts
index 24fd2c183..7fbdd910d 100644
--- a/packages/js-sdk/tests/sandbox/files/signing.test.ts
+++ b/packages/js-sdk/tests/sandbox/files/signing.test.ts
@@ -1,97 +1,137 @@
-import {assert, test} from 'vitest'
-import {Sandbox} from '../../../src'
-import {template} from '../../setup'
+import { assert, test } from 'vitest'
-const timeout = 20 * 1000
-
-test('test access file with expired signing', async () => {
- const sbx = await Sandbox.create(template, { timeoutMs: timeout, secure: true })
- await sbx.files.write('hello.txt', 'hello world')
-
- const fileUrlWithSigning = sbx.downloadUrl('hello.txt', { useSignature: true, useSignatureExpiration: -10_000 })
-
- const res = await fetch(fileUrlWithSigning)
- const resBody = await res.text()
- const resStatus = res.status
+import { Sandbox } from '../../../src'
+import { template, isDebug } from '../../setup'
- assert.equal(resStatus, 401)
- assert.deepEqual(JSON.parse(resBody), {code: 401, message: 'signature is already expired'})
+const timeout = 20 * 1000
- await sbx.kill()
+test.skipIf(isDebug)('test access file with expired signing', async () => {
+ const sbx = await Sandbox.create(template, {
+ timeoutMs: timeout,
+ secure: true,
+ })
+ await sbx.files.write('hello.txt', 'hello world')
+
+ const fileUrlWithSigning = sbx.downloadUrl('hello.txt', {
+ useSignature: true,
+ useSignatureExpiration: -10_000,
+ })
+
+ const res = await fetch(fileUrlWithSigning)
+ const resBody = await res.text()
+ const resStatus = res.status
+
+ assert.equal(resStatus, 401)
+ assert.deepEqual(JSON.parse(resBody), {
+ code: 401,
+ message: 'signature is already expired',
+ })
+
+ await sbx.kill()
})
-test('test access file with valid signing', async () => {
- const sbx = await Sandbox.create(template, { timeoutMs: timeout, secure: true })
- await sbx.files.write('hello.txt', 'hello world')
+test.skipIf(isDebug)('test access file with valid signing', async () => {
+ const sbx = await Sandbox.create(template, {
+ timeoutMs: timeout,
+ secure: true,
+ })
+ await sbx.files.write('hello.txt', 'hello world')
- const fileUrlWithSigning = sbx.downloadUrl('hello.txt', { useSignature: true, useSignatureExpiration: 10_000 })
+ const fileUrlWithSigning = sbx.downloadUrl('hello.txt', {
+ useSignature: true,
+ useSignatureExpiration: 10_000,
+ })
- const res = await fetch(fileUrlWithSigning)
- const resBody = await res.text()
- const resStatus = res.status
+ const res = await fetch(fileUrlWithSigning)
+ const resBody = await res.text()
+ const resStatus = res.status
- assert.equal(resStatus, 200)
- assert.equal(resBody, 'hello world')
+ assert.equal(resStatus, 200)
+ assert.equal(resBody, 'hello world')
- await sbx.kill()
+ await sbx.kill()
})
-test('test upload file with valid signing', async () => {
- const sbx = await Sandbox.create(template, { timeoutMs: timeout, secure: true })
- const fileUrlWithSigning = sbx.uploadUrl('hello.txt', { useSignature: true, useSignatureExpiration: 10_000 })
-
- const form = new FormData()
- form.append('file', 'file content')
-
- const res = await fetch(fileUrlWithSigning, { method: 'POST', body: form })
- const resBody = await res.text()
- const resStatus = res.status
-
- assert.equal(resStatus, 200)
- assert.deepEqual(JSON.parse(resBody), [{name: 'hello.txt', path: '/home/user/hello.txt', type: 'file'}])
-
- await sbx.kill()
+test.skipIf(isDebug)('test upload file with valid signing', async () => {
+ const sbx = await Sandbox.create(template, {
+ timeoutMs: timeout,
+ secure: true,
+ })
+ const fileUrlWithSigning = sbx.uploadUrl('hello.txt', {
+ useSignature: true,
+ useSignatureExpiration: 10_000,
+ })
+
+ const form = new FormData()
+ form.append('file', 'file content')
+
+ const res = await fetch(fileUrlWithSigning, { method: 'POST', body: form })
+ const resBody = await res.text()
+ const resStatus = res.status
+
+ assert.equal(resStatus, 200)
+ assert.deepEqual(JSON.parse(resBody), [
+ { name: 'hello.txt', path: '/home/user/hello.txt', type: 'file' },
+ ])
+
+ await sbx.kill()
})
-test('test upload file with invalid signing', async () => {
- const sbx = await Sandbox.create(template, { timeoutMs: timeout, secure: true })
- const fileUrlWithSigning = sbx.uploadUrl('hello.txt', { useSignature: true, useSignatureExpiration: -10_000 })
-
- const form = new FormData()
- form.append('file', 'file content')
-
- const res = await fetch(fileUrlWithSigning, { method: 'POST', body: form })
- const resBody = await res.text()
- const resStatus = res.status
-
- assert.equal(resStatus, 401)
- assert.deepEqual(JSON.parse(resBody), {code: 401, message: 'signature is already expired'})
-
- await sbx.kill()
+test.skipIf(isDebug)('test upload file with invalid signing', async () => {
+ const sbx = await Sandbox.create(template, {
+ timeoutMs: timeout,
+ secure: true,
+ })
+ const fileUrlWithSigning = sbx.uploadUrl('hello.txt', {
+ useSignature: true,
+ useSignatureExpiration: -10_000,
+ })
+
+ const form = new FormData()
+ form.append('file', 'file content')
+
+ const res = await fetch(fileUrlWithSigning, { method: 'POST', body: form })
+ const resBody = await res.text()
+ const resStatus = res.status
+
+ assert.equal(resStatus, 401)
+ assert.deepEqual(JSON.parse(resBody), {
+ code: 401,
+ message: 'signature is already expired',
+ })
+
+ await sbx.kill()
})
-test('test upload file with missing signing', async () => {
- const sbx = await Sandbox.create(template, { timeoutMs: timeout, secure: true })
- const fileUrlWithSigning = sbx.uploadUrl('hello.txt')
+test.skipIf(isDebug)('test upload file with missing signing', async () => {
+ const sbx = await Sandbox.create(template, {
+ timeoutMs: timeout,
+ secure: true,
+ })
+ const fileUrlWithSigning = sbx.uploadUrl('hello.txt')
- const form = new FormData()
- form.append('file', 'file content')
+ const form = new FormData()
+ form.append('file', 'file content')
- const res = await fetch(fileUrlWithSigning, { method: 'POST', body: form })
- const resBody = await res.text()
- const resStatus = res.status
+ const res = await fetch(fileUrlWithSigning, { method: 'POST', body: form })
+ const resBody = await res.text()
+ const resStatus = res.status
- assert.equal(resStatus, 401)
- assert.deepEqual(JSON.parse(resBody), {code: 401, message: 'missing signature query parameter'})
+ assert.equal(resStatus, 401)
+ assert.deepEqual(JSON.parse(resBody), {
+ code: 401,
+ message: 'missing signature query parameter',
+ })
- await sbx.kill()
+ await sbx.kill()
})
-test('test command run with secured sbx', async () => {
- const sbx = await Sandbox.create(template, { timeoutMs: timeout, secure: true })
- const response = await sbx.commands.run('echo Hello World!')
+test.skipIf(isDebug)('test command run with secured sbx', async () => {
+ const sbx = await Sandbox.create(template, {
+ timeoutMs: timeout,
+ secure: true,
+ })
+ const response = await sbx.commands.run('echo Hello World!')
- assert.equal(response.stdout, 'Hello World!\n')
+ assert.equal(response.stdout, 'Hello World!\n')
})
-
-
diff --git a/packages/js-sdk/tests/sandbox/secure.test.ts b/packages/js-sdk/tests/sandbox/secure.test.ts
index f6578aee9..ceb5e87f4 100644
--- a/packages/js-sdk/tests/sandbox/secure.test.ts
+++ b/packages/js-sdk/tests/sandbox/secure.test.ts
@@ -1,104 +1,138 @@
import { assert, test } from 'vitest'
import { getSignature, Sandbox } from '../../src'
-import {template } from '../setup'
+import { isDebug, template } from '../setup'
import { randomUUID, createHash } from 'node:crypto'
const timeout = 20 * 1000
-test('test access file without signing', async () => {
- const sbx = await Sandbox.create(template, { timeoutMs: timeout, secure: true })
- await sbx.files.write('hello.txt', 'hello world')
+test.skipIf(isDebug)('test access file without signing', async () => {
+ const sbx = await Sandbox.create(template, {
+ timeoutMs: timeout,
+ secure: true,
+ })
+ await sbx.files.write('hello.txt', 'hello world')
- const fileUrlWithoutSigning = sbx.downloadUrl('hello.txt')
+ const fileUrlWithoutSigning = sbx.downloadUrl('hello.txt')
- const res = await fetch(fileUrlWithoutSigning)
- const resBody = await res.text()
- const resStatus = res.status
+ const res = await fetch(fileUrlWithoutSigning)
+ const resBody = await res.text()
+ const resStatus = res.status
- assert.equal(resStatus, 401)
- assert.deepEqual(JSON.parse(resBody), {code: 401, message: 'missing signature query parameter'})
+ assert.equal(resStatus, 401)
+ assert.deepEqual(JSON.parse(resBody), {
+ code: 401,
+ message: 'missing signature query parameter',
+ })
- await sbx.kill()
+ await sbx.kill()
})
-test('test access file with signing', async () => {
- const sbx = await Sandbox.create(template, { timeoutMs: timeout, secure: true })
- await sbx.files.write('hello.txt', 'hello world')
+test.skipIf(isDebug)('test access file with signing', async () => {
+ const sbx = await Sandbox.create(template, {
+ timeoutMs: timeout,
+ secure: true,
+ })
+ await sbx.files.write('hello.txt', 'hello world')
- const fileUrlWithSigning = sbx.downloadUrl('hello.txt', { useSignature: true })
+ const fileUrlWithSigning = sbx.downloadUrl('hello.txt', {
+ useSignature: true,
+ })
- const res = await fetch(fileUrlWithSigning)
- const resBody = await res.text()
- const resStatus = res.status
+ const res = await fetch(fileUrlWithSigning)
+ const resBody = await res.text()
+ const resStatus = res.status
- assert.equal(resStatus, 200)
- assert.equal(resBody, 'hello world')
+ assert.equal(resStatus, 200)
+ assert.equal(resBody, 'hello world')
- await sbx.kill()
+ await sbx.kill()
})
-test('try to re-connect to sandbox', async () => {
- const sbx = await Sandbox.create(template, { timeoutMs: timeout, secure: true })
- const sbxReconnect = await Sandbox.connect(sbx.sandboxId)
+test.skipIf(isDebug)('try to re-connect to sandbox', async () => {
+ const sbx = await Sandbox.create(template, {
+ timeoutMs: timeout,
+ secure: true,
+ })
+ const sbxReconnect = await Sandbox.connect(sbx.sandboxId)
- await sbxReconnect.files.write('hello.txt', 'hello world')
- await sbxReconnect.kill()
+ await sbxReconnect.files.write('hello.txt', 'hello world')
+ await sbxReconnect.kill()
})
-test('signing generation', async () => {
- const operation = 'read'
- const path = '/home/user/hello.txt'
- const user = 'root'
- const envdAccessToken = randomUUID()
+test.skipIf(isDebug)('signing generation', async () => {
+ const operation = 'read'
+ const path = '/home/user/hello.txt'
+ const user = 'root'
+ const envdAccessToken = randomUUID()
- const signatureRaw = `${path}:${operation}:${user}:${envdAccessToken}`
+ const signatureRaw = `${path}:${operation}:${user}:${envdAccessToken}`
- const buff = Buffer.from(signatureRaw, 'utf8')
- const hash = createHash('sha256').update(buff).digest()
- const signature = 'v1_' + hash.toString('base64').replace(/=+$/, '')
+ const buff = Buffer.from(signatureRaw, 'utf8')
+ const hash = createHash('sha256').update(buff).digest()
+ const signature = 'v1_' + hash.toString('base64').replace(/=+$/, '')
- const readSignatureExpected = {
- signature: signature,
- expiration: null
- }
+ const readSignatureExpected = {
+ signature: signature,
+ expiration: null,
+ }
- const readSignatureReceived = getSignature({ path, operation, user, envdAccessToken })
+ const readSignatureReceived = getSignature({
+ path,
+ operation,
+ user,
+ envdAccessToken,
+ })
- assert.deepEqual(readSignatureExpected, readSignatureReceived)
+ assert.deepEqual(readSignatureExpected, readSignatureReceived)
})
-test('signing generation with expiration', async () => {
- const operation = 'read'
- const path = '/home/user/hello.txt'
- const user = 'root'
- const envdAccessToken = randomUUID()
- const expirationInSeconds = 120
-
- const signatureExpiration = expirationInSeconds ? Math.floor(Date.now() / 1000) + expirationInSeconds : null
- const signatureRaw = `${path}:${operation}:${user}:${envdAccessToken}:${signatureExpiration.toString()}`
-
- const buff = Buffer.from(signatureRaw, 'utf8')
- const hash = createHash('sha256').update(buff).digest()
- const signature = 'v1_' + hash.toString('base64').replace(/=+$/, '')
-
- const readSignatureExpected = {
- signature: signature,
- expiration: signatureExpiration
- }
-
- const readSignatureReceived = getSignature({ path, operation, user, envdAccessToken, expirationInSeconds })
-
- assert.deepEqual(readSignatureExpected, readSignatureReceived)
+test.skipIf(isDebug)('signing generation with expiration', async () => {
+ const operation = 'read'
+ const path = '/home/user/hello.txt'
+ const user = 'root'
+ const envdAccessToken = randomUUID()
+ const expirationInSeconds = 120
+
+ const signatureExpiration = expirationInSeconds
+ ? Math.floor(Date.now() / 1000) + expirationInSeconds
+ : null
+ const signatureRaw = `${path}:${operation}:${user}:${envdAccessToken}:${signatureExpiration?.toString()}`
+
+ const buff = Buffer.from(signatureRaw, 'utf8')
+ const hash = createHash('sha256').update(buff).digest()
+ const signature = 'v1_' + hash.toString('base64').replace(/=+$/, '')
+
+ const readSignatureExpected = {
+ signature: signature,
+ expiration: signatureExpiration,
+ }
+
+ const readSignatureReceived = getSignature({
+ path,
+ operation,
+ user,
+ envdAccessToken,
+ expirationInSeconds,
+ })
+
+ assert.deepEqual(readSignatureExpected, readSignatureReceived)
})
-
-test('static signing key comparison', async () => {
- const operation = 'read'
- const path = 'hello.txt'
- const user = 'user'
- const envdAccessToken = '0tQG31xiMp0IOQfaz9dcwi72L1CPo8e0'
-
- const signatureReceived = getSignature({ path, operation, user, envdAccessToken })
-
- assert.equal('v1_gUtH/s9YCJWgCizjfUxuWfhFE4QSydOWEIIvfLwDr6E', signatureReceived.signature)
+test.skipIf(isDebug)('static signing key comparison', async () => {
+ const operation = 'read'
+ const path = 'hello.txt'
+ const user = 'user'
+ const envdAccessToken = '0tQG31xiMp0IOQfaz9dcwi72L1CPo8e0'
+
+ const signatureReceived = getSignature({
+ path,
+ operation,
+ user,
+ envdAccessToken,
+ })
+
+ assert.equal(
+ 'v1_gUtH/s9YCJWgCizjfUxuWfhFE4QSydOWEIIvfLwDr6E',
+ signatureReceived.signature
+ )
})
diff --git a/packages/python-sdk/tests/async/sandbox_async/files/test_secured.py b/packages/python-sdk/tests/async/sandbox_async/files/test_secured.py
index 98147444c..6e7dd2d23 100644
--- a/packages/python-sdk/tests/async/sandbox_async/files/test_secured.py
+++ b/packages/python-sdk/tests/async/sandbox_async/files/test_secured.py
@@ -7,7 +7,7 @@ from e2b import (
AsyncSandbox,
)
-
async def test_download_url_with_signing(template):
sbx = await AsyncSandbox.create(template, timeout=100, secure=True)
file_path = "test_download_url_with_signing.txt"
@@ -25,6 +25,7 @@ async def test_download_url_with_signing(template):
finally:
await sbx.kill()
async def test_download_url_with_signing_and_expiration(template):
sbx = await AsyncSandbox.create(template, timeout=100, secure=True)
file_path = "test_download_url_with_signing.txt"
@@ -42,6 +43,7 @@ async def test_download_url_with_signing_and_expiration(template):
finally:
await sbx.kill()
async def test_download_url_with_expired_signing(template):
sbx = await AsyncSandbox.create(template, timeout=100, secure=True)
file_path = "test_download_url_with_signing.txt"
diff --git a/packages/python-sdk/tests/async/sandbox_async/test_connect.py b/packages/python-sdk/tests/async/sandbox_async/test_connect.py
index b5f1d2b47..89a6d065d 100644
--- a/packages/python-sdk/tests/async/sandbox_async/test_connect.py
+++ b/packages/python-sdk/tests/async/sandbox_async/test_connect.py
@@ -1,8 +1,9 @@
import uuid
+import pytest
from e2b import AsyncSandbox
-
async def test_connect(template):
sbx = await AsyncSandbox.create(template, timeout=10)
try:
@@ -13,7 +14,7 @@ async def test_connect(template):
finally:
await sbx.kill()
-
async def test_connect_with_secure(template):
dir_name = f"test_directory_{uuid.uuid4()}"
diff --git a/packages/python-sdk/tests/async/sandbox_async/test_secure.py b/packages/python-sdk/tests/async/sandbox_async/test_secure.py
index 1fe2c46d1..8759a8b33 100644
--- a/packages/python-sdk/tests/async/sandbox_async/test_secure.py
+++ b/packages/python-sdk/tests/async/sandbox_async/test_secure.py
@@ -2,7 +2,7 @@ import pytest
from e2b import AsyncSandbox
-
async def test_start_secured(template):
sbx = await AsyncSandbox.create(template, timeout=5, secure=True)
try:
@@ -12,7 +12,7 @@ async def test_start_secured(template):
finally:
await sbx.kill()
-
async def test_connect_to_secured(template):
sbx = await AsyncSandbox.create(template, timeout=100, secure=True)
try:
diff --git a/packages/python-sdk/tests/sync/sandbox_sync/files/test_secured.py b/packages/python-sdk/tests/sync/sandbox_sync/files/test_secured.py
index 684074234..84b396ce8 100644
--- a/packages/python-sdk/tests/sync/sandbox_sync/files/test_secured.py
+++ b/packages/python-sdk/tests/sync/sandbox_sync/files/test_secured.py
@@ -5,6 +5,7 @@ import pytest
from e2b import Sandbox
async def test_download_url_with_signing(template):
sbx = Sandbox(template, timeout=100, secure=True)
file_path = "test_download_url_with_signing.txt"
@@ -22,6 +23,7 @@ async def test_download_url_with_signing(template):
finally:
sbx.kill()
async def test_download_url_with_signing_and_expiration(template):
sbx = Sandbox(template, timeout=100, secure=True)
file_path = "test_download_url_with_signing.txt"
@@ -39,6 +41,7 @@ async def test_download_url_with_signing_and_expiration(template):
finally:
sbx.kill()
async def test_download_url_with_expired_signing(template):
sbx = Sandbox(template, timeout=100, secure=True)
file_path = "test_download_url_with_signing.txt"
diff --git a/packages/python-sdk/tests/sync/sandbox_sync/test_connect.py b/packages/python-sdk/tests/sync/sandbox_sync/test_connect.py
index d2be9ed35..d6d965336 100644
--- a/packages/python-sdk/tests/sync/sandbox_sync/test_connect.py
+++ b/packages/python-sdk/tests/sync/sandbox_sync/test_connect.py
@@ -1,8 +1,10 @@
import uuid
+import pytest
from e2b import Sandbox
def test_connect(template):
sbx = Sandbox(template, timeout=10)
try:
@@ -14,6 +16,7 @@ def test_connect(template):
sbx.kill()
def test_connect_with_secure(template):
dir_name = f"test_directory_{uuid.uuid4()}"
diff --git a/packages/python-sdk/tests/sync/sandbox_sync/test_secure.py b/packages/python-sdk/tests/sync/sandbox_sync/test_secure.py
index 6e49a0afd..aad330d78 100644
--- a/packages/python-sdk/tests/sync/sandbox_sync/test_secure.py
+++ b/packages/python-sdk/tests/sync/sandbox_sync/test_secure.py
@@ -2,7 +2,7 @@ import pytest
from e2b import Sandbox
-
def test_start_secured(template):
sbx = Sandbox(template, timeout=5, secure=True)
try:
@@ -12,6 +12,7 @@ def test_start_secured(template):
finally:
sbx.kill()
def test_connect_to_secured(template):
sbx = Sandbox(template, timeout=5, secure=True)
try: