|
1 | | -import {assert, test} from 'vitest' |
2 | | -import {Sandbox} from '../../../src' |
3 | | -import {template} from '../../setup' |
| 1 | +import { assert, test } from 'vitest' |
4 | 2 |
|
5 | | -const timeout = 20 * 1000 |
6 | | - |
7 | | -test('test access file with expired signing', async () => { |
8 | | - const sbx = await Sandbox.create(template, { timeoutMs: timeout, secure: true }) |
9 | | - await sbx.files.write('hello.txt', 'hello world') |
10 | | - |
11 | | - const fileUrlWithSigning = sbx.downloadUrl('hello.txt', { useSignature: true, useSignatureExpiration: -10_000 }) |
12 | | - |
13 | | - const res = await fetch(fileUrlWithSigning) |
14 | | - const resBody = await res.text() |
15 | | - const resStatus = res.status |
| 3 | +import { Sandbox } from '../../../src' |
| 4 | +import { template, isDebug } from '../../setup' |
16 | 5 |
|
17 | | - assert.equal(resStatus, 401) |
18 | | - assert.deepEqual(JSON.parse(resBody), {code: 401, message: 'signature is already expired'}) |
| 6 | +const timeout = 20 * 1000 |
19 | 7 |
|
20 | | - await sbx.kill() |
| 8 | +test.skipIf(isDebug)('test access file with expired signing', async () => { |
| 9 | + const sbx = await Sandbox.create(template, { |
| 10 | + timeoutMs: timeout, |
| 11 | + secure: true, |
| 12 | + }) |
| 13 | + await sbx.files.write('hello.txt', 'hello world') |
| 14 | + |
| 15 | + const fileUrlWithSigning = sbx.downloadUrl('hello.txt', { |
| 16 | + useSignature: true, |
| 17 | + useSignatureExpiration: -10_000, |
| 18 | + }) |
| 19 | + |
| 20 | + const res = await fetch(fileUrlWithSigning) |
| 21 | + const resBody = await res.text() |
| 22 | + const resStatus = res.status |
| 23 | + |
| 24 | + assert.equal(resStatus, 401) |
| 25 | + assert.deepEqual(JSON.parse(resBody), { |
| 26 | + code: 401, |
| 27 | + message: 'signature is already expired', |
| 28 | + }) |
| 29 | + |
| 30 | + await sbx.kill() |
21 | 31 | }) |
22 | 32 |
|
23 | | -test('test access file with valid signing', async () => { |
24 | | - const sbx = await Sandbox.create(template, { timeoutMs: timeout, secure: true }) |
25 | | - await sbx.files.write('hello.txt', 'hello world') |
| 33 | +test.skipIf(isDebug)('test access file with valid signing', async () => { |
| 34 | + const sbx = await Sandbox.create(template, { |
| 35 | + timeoutMs: timeout, |
| 36 | + secure: true, |
| 37 | + }) |
| 38 | + await sbx.files.write('hello.txt', 'hello world') |
26 | 39 |
|
27 | | - const fileUrlWithSigning = sbx.downloadUrl('hello.txt', { useSignature: true, useSignatureExpiration: 10_000 }) |
| 40 | + const fileUrlWithSigning = sbx.downloadUrl('hello.txt', { |
| 41 | + useSignature: true, |
| 42 | + useSignatureExpiration: 10_000, |
| 43 | + }) |
28 | 44 |
|
29 | | - const res = await fetch(fileUrlWithSigning) |
30 | | - const resBody = await res.text() |
31 | | - const resStatus = res.status |
| 45 | + const res = await fetch(fileUrlWithSigning) |
| 46 | + const resBody = await res.text() |
| 47 | + const resStatus = res.status |
32 | 48 |
|
33 | | - assert.equal(resStatus, 200) |
34 | | - assert.equal(resBody, 'hello world') |
| 49 | + assert.equal(resStatus, 200) |
| 50 | + assert.equal(resBody, 'hello world') |
35 | 51 |
|
36 | | - await sbx.kill() |
| 52 | + await sbx.kill() |
37 | 53 | }) |
38 | 54 |
|
39 | | -test('test upload file with valid signing', async () => { |
40 | | - const sbx = await Sandbox.create(template, { timeoutMs: timeout, secure: true }) |
41 | | - const fileUrlWithSigning = sbx.uploadUrl('hello.txt', { useSignature: true, useSignatureExpiration: 10_000 }) |
42 | | - |
43 | | - const form = new FormData() |
44 | | - form.append('file', 'file content') |
45 | | - |
46 | | - const res = await fetch(fileUrlWithSigning, { method: 'POST', body: form }) |
47 | | - const resBody = await res.text() |
48 | | - const resStatus = res.status |
49 | | - |
50 | | - assert.equal(resStatus, 200) |
51 | | - assert.deepEqual(JSON.parse(resBody), [{name: 'hello.txt', path: '/home/user/hello.txt', type: 'file'}]) |
52 | | - |
53 | | - await sbx.kill() |
| 55 | +test.skipIf(isDebug)('test upload file with valid signing', async () => { |
| 56 | + const sbx = await Sandbox.create(template, { |
| 57 | + timeoutMs: timeout, |
| 58 | + secure: true, |
| 59 | + }) |
| 60 | + const fileUrlWithSigning = sbx.uploadUrl('hello.txt', { |
| 61 | + useSignature: true, |
| 62 | + useSignatureExpiration: 10_000, |
| 63 | + }) |
| 64 | + |
| 65 | + const form = new FormData() |
| 66 | + form.append('file', 'file content') |
| 67 | + |
| 68 | + const res = await fetch(fileUrlWithSigning, { method: 'POST', body: form }) |
| 69 | + const resBody = await res.text() |
| 70 | + const resStatus = res.status |
| 71 | + |
| 72 | + assert.equal(resStatus, 200) |
| 73 | + assert.deepEqual(JSON.parse(resBody), [ |
| 74 | + { name: 'hello.txt', path: '/home/user/hello.txt', type: 'file' }, |
| 75 | + ]) |
| 76 | + |
| 77 | + await sbx.kill() |
54 | 78 | }) |
55 | 79 |
|
56 | | -test('test upload file with invalid signing', async () => { |
57 | | - const sbx = await Sandbox.create(template, { timeoutMs: timeout, secure: true }) |
58 | | - const fileUrlWithSigning = sbx.uploadUrl('hello.txt', { useSignature: true, useSignatureExpiration: -10_000 }) |
59 | | - |
60 | | - const form = new FormData() |
61 | | - form.append('file', 'file content') |
62 | | - |
63 | | - const res = await fetch(fileUrlWithSigning, { method: 'POST', body: form }) |
64 | | - const resBody = await res.text() |
65 | | - const resStatus = res.status |
66 | | - |
67 | | - assert.equal(resStatus, 401) |
68 | | - assert.deepEqual(JSON.parse(resBody), {code: 401, message: 'signature is already expired'}) |
69 | | - |
70 | | - await sbx.kill() |
| 80 | +test.skipIf(isDebug)('test upload file with invalid signing', async () => { |
| 81 | + const sbx = await Sandbox.create(template, { |
| 82 | + timeoutMs: timeout, |
| 83 | + secure: true, |
| 84 | + }) |
| 85 | + const fileUrlWithSigning = sbx.uploadUrl('hello.txt', { |
| 86 | + useSignature: true, |
| 87 | + useSignatureExpiration: -10_000, |
| 88 | + }) |
| 89 | + |
| 90 | + const form = new FormData() |
| 91 | + form.append('file', 'file content') |
| 92 | + |
| 93 | + const res = await fetch(fileUrlWithSigning, { method: 'POST', body: form }) |
| 94 | + const resBody = await res.text() |
| 95 | + const resStatus = res.status |
| 96 | + |
| 97 | + assert.equal(resStatus, 401) |
| 98 | + assert.deepEqual(JSON.parse(resBody), { |
| 99 | + code: 401, |
| 100 | + message: 'signature is already expired', |
| 101 | + }) |
| 102 | + |
| 103 | + await sbx.kill() |
71 | 104 | }) |
72 | 105 |
|
73 | | -test('test upload file with missing signing', async () => { |
74 | | - const sbx = await Sandbox.create(template, { timeoutMs: timeout, secure: true }) |
75 | | - const fileUrlWithSigning = sbx.uploadUrl('hello.txt') |
| 106 | +test.skipIf(isDebug)('test upload file with missing signing', async () => { |
| 107 | + const sbx = await Sandbox.create(template, { |
| 108 | + timeoutMs: timeout, |
| 109 | + secure: true, |
| 110 | + }) |
| 111 | + const fileUrlWithSigning = sbx.uploadUrl('hello.txt') |
76 | 112 |
|
77 | | - const form = new FormData() |
78 | | - form.append('file', 'file content') |
| 113 | + const form = new FormData() |
| 114 | + form.append('file', 'file content') |
79 | 115 |
|
80 | | - const res = await fetch(fileUrlWithSigning, { method: 'POST', body: form }) |
81 | | - const resBody = await res.text() |
82 | | - const resStatus = res.status |
| 116 | + const res = await fetch(fileUrlWithSigning, { method: 'POST', body: form }) |
| 117 | + const resBody = await res.text() |
| 118 | + const resStatus = res.status |
83 | 119 |
|
84 | | - assert.equal(resStatus, 401) |
85 | | - assert.deepEqual(JSON.parse(resBody), {code: 401, message: 'missing signature query parameter'}) |
| 120 | + assert.equal(resStatus, 401) |
| 121 | + assert.deepEqual(JSON.parse(resBody), { |
| 122 | + code: 401, |
| 123 | + message: 'missing signature query parameter', |
| 124 | + }) |
86 | 125 |
|
87 | | - await sbx.kill() |
| 126 | + await sbx.kill() |
88 | 127 | }) |
89 | 128 |
|
90 | | -test('test command run with secured sbx', async () => { |
91 | | - const sbx = await Sandbox.create(template, { timeoutMs: timeout, secure: true }) |
92 | | - const response = await sbx.commands.run('echo Hello World!') |
| 129 | +test.skipIf(isDebug)('test command run with secured sbx', async () => { |
| 130 | + const sbx = await Sandbox.create(template, { |
| 131 | + timeoutMs: timeout, |
| 132 | + secure: true, |
| 133 | + }) |
| 134 | + const response = await sbx.commands.run('echo Hello World!') |
93 | 135 |
|
94 | | - assert.equal(response.stdout, 'Hello World!\n') |
| 136 | + assert.equal(response.stdout, 'Hello World!\n') |
95 | 137 | }) |
96 | | - |
97 | | - |
|
0 commit comments