fix: reject unconfirmed Telegram tests and invalid update responses

This commit is contained in:
2026-09-06 14:55:05 +03:00
parent 37fb7b0366
commit 120657758c
8 changed files with 57 additions and 6 deletions
+14 -1
View File
@@ -7,6 +7,7 @@ import {join} from 'node:path';
import {randomBytes} from 'node:crypto';
import {createServer} from 'node:net';
const dir=mkdtempSync(join(tmpdir(),'ihaleist-http-'));
process.env.IHALEIST_USER_DATA_DIR=dir;
process.env.AUTH_SECRET=randomBytes(32).toString('hex');
const {signToken}=await import('../server/auth.mjs');
const token=signToken({email:'qa@example.test',name:'QA'});
@@ -19,7 +20,7 @@ const request=async(path,method='GET',body,auth=token)=>{
before(async()=>{
const socket=createServer();await new Promise(r=>socket.listen(0,'127.0.0.1',r));const port=socket.address().port;await new Promise(r=>socket.close(r));
base='http://127.0.0.1:'+port;
child=spawn(process.execPath,['server/index.js'],{cwd:new URL('..',import.meta.url),env:{...process.env,NODE_ENV:'test',PORT:String(port),IHALEIST_USER_DATA_DIR:dir,IHALEIST_SHARED_DATA_DIR:join(dir,'shared'),UYUM_GOMME:'0'},stdio:'ignore'});
child=spawn(process.execPath,['server/index.js'],{cwd:new URL('..',import.meta.url),env:{...process.env,NODE_ENV:'test',TELEGRAM_BOT_TOKEN:'',PORT:String(port),IHALEIST_USER_DATA_DIR:dir,IHALEIST_SHARED_DATA_DIR:join(dir,'shared'),UYUM_GOMME:'0'},stdio:'ignore'});
for(let i=0;i<100;i++){try{await fetch(base+'/api/auth/google/config');return;}catch{await new Promise(r=>setTimeout(r,50));}}
throw new Error('QA API did not start');
});
@@ -294,3 +295,15 @@ test('Telegram cannot be linked through generic data writes or legacy client cod
assert.equal((await request('/api/me/telegram','PATCH',{})).status,405);
assert.equal((await request('/api/me/telegram','POST',{islem:'kod'},null)).status,401);
});
test('saved Telegram link does not imply an unconfigured test message was sent',async()=>{
const {createTelegramLinker}=await import('../server/telegram-link.mjs');
// Parent and HTTP child use the same disposable database; no real provider credentials.
const tgStore=await import('../server/user-store.mjs');
const linker=createTelegramLinker(tgStore),email='telegram-http@example.test';
const challenge=linker.issue(email);await linker.link(email,challenge.kod,async()=>({chatId:'123',ad:'Synthetic'}));
const session=signToken({email,name:'Telegram Test'});
const result=await request('/api/me/telegram','POST',{islem:'test'},session);
assert.equal(result.status,503);assert.equal(result.data.success,false);
assert.equal(result.data.id,undefined);
});