Personal Telegram developer console for GitHub

test: define Worker route and CSP for Workspace Mini App

davoodmehraban89 committed Oct 4, 2026 at 11:28 UTC b651766b5e411227f192eb697ef1f795eeeb7b98
1 file changed +30
test/workspace-editor-worker.test.js new
+30
@@ -0,0 +1,30 @@
1 +import test from 'node:test';
2 +import assert from 'node:assert/strict';
3 +import worker from '../src/index.js';
4 +
5 +test('Worker serves Workspace Mini App with no-store and a restrictive CSP', async () => {
6 + const response = await worker.fetch(new Request('https://example.com/workspace/editor'), {}, {});
7 + assert.equal(response.status, 200);
8 + assert.match(response.headers.get('content-type') || '', /text\/html/i);
9 + assert.equal(response.headers.get('cache-control'), 'no-store');
10 + const csp = response.headers.get('content-security-policy') || '';
11 + assert.match(csp, /default-src 'none'/i);
12 + assert.match(csp, /script-src[^;]*telegram\.org/i);
13 + assert.match(csp, /connect-src 'self'/i);
14 + const html = await response.text();
15 + assert.match(html, /<textarea/i);
16 + assert.match(html, /telegram-web-app\.js/i);
17 +});
18 +
19 +test('Worker editor API rejects requests that do not carry valid Telegram initData', async () => {
20 + const response = await worker.fetch(
21 + new Request('https://example.com/workspace/api/editor?workspaceId=W000000001'),
22 + { TELEGRAM_BOT_TOKEN: '123456:TEST_ONLY_TOKEN', OWNER_TELEGRAM_ID: '42' },
23 + {}
24 + );
25 + assert.equal(response.status, 403);
26 + assert.equal(response.headers.get('cache-control'), 'no-store');
27 + const body = await response.json();
28 + assert.equal(body.ok, false);
29 + assert.match(body.error, /hash|initData|signature/i);
30 +});