Personal Telegram developer console for GitHub
test: require temporary webhook setup endpoint to be disabled
davoodmehraban89 committed
Oct 2, 2026 at 18:40 UTC
5e52d220388d78a5db679f51fcf528eebd658f60
1 file changed
+7
-18
test/security.test.js
+7
-18
@@ -81,21 +81,15 @@ test("unauthorized Telegram users receive no bot response", async () => {
81
assert.equal(calls, 0);
82
});
83
84
-test("temporary setup endpoint registers Telegram webhook to this worker", async () => {
84
+test("temporary setup endpoint is disabled after webhook registration", async () => {
85
const req = new Request("https://nexa-dev-bot.example.workers.dev/telegram/setup", {
86
method: "GET",
87
});
88
89
- let captured;
90
- globalThis.fetch = async (url, init) => {
91
- captured = {
92
- url: String(url),
93
- body: JSON.parse(init.body),
94
- };
95
- return new Response(JSON.stringify({ ok: true, result: true }), {
96
- status: 200,
97
- headers: { "content-type": "application/json" },
98
- });
89
+ let calls = 0;
90
+ globalThis.fetch = async () => {
91
+ calls += 1;
92
+ throw new Error("setup endpoint must not call Telegram after registration");
93
};
94
95
const res = await worker.fetch(req, {
@@ -103,11 +97,6 @@ test("temporary setup endpoint registers Telegram webhook to this worker", async
97
TELEGRAM_BOT_TOKEN: "token",
98
});
99
106
- assert.equal(res.status, 200);
107
- assert.equal(captured.url, "https://api.telegram.org/bottoken/setWebhook");
108
- assert.deepEqual(captured.body, {
109
- url: "https://nexa-dev-bot.example.workers.dev/telegram/webhook",
110
- secret_token: "secret",
111
- allowed_updates: ["message"],
112
- });
100
+ assert.equal(res.status, 404);
101
+ assert.equal(calls, 0);
102
});