// LOCAL UI TEST ONLY. This returns fabricated XML and MUST NOT be used to // authenticate users or be exposed publicly. const express = require('express'); const crypto = require('node:crypto'); const app = express(); app.use(express.json()); const sessions = new Map(); app.post('/v1/egov/sessions', (req, res) => { const id = crypto.randomUUID(); const source = req.body?.documentsToSign?.[0]?.documentXml || ''; const challenge = source.match(/([^<]+)<\/challenge>/)?.[1] || 'MISSING_CHALLENGE'; const nonce = source.match(/([^<]+)<\/nonce>/)?.[1] || 'MISSING_NONCE'; sessions.set(id, { createdAt: Date.now(), polls: 0, challenge, nonce }); res.status(201).json({ session_id: id, qr_content: `mobileSign:https://example.invalid/mgovSign/${id}`, deeplink: `https://m.egov.kz/mobileSign?link=https%3A%2F%2Fexample.invalid%2FmgovSign%2F${id}`, expires_at: new Date(Date.now() + 5 * 60_000).toISOString(), }); }); app.get('/v1/egov/:id/status', (req, res) => { const session = sessions.get(req.params.id); if (!session) return res.status(404).json({ error: 'Mock session not found' }); session.polls += 1; if (session.polls < 3) return res.json({ status: session.polls === 1 ? 'scanned' : 'pending', expires_in: 290 }); sessions.delete(req.params.id); const signed = `${session.challenge}${session.nonce}NOT_A_SIGNATURENOT_A_CERTIFICATE`; return res.json({ status: 'completed', // Deliberately fabricated: only exercises UI plumbing; not a valid signature. signedDocuments: [{ id: 1, nameRu: 'Mock response (not signed)', documentXml: signed }], }); }); const port = Number(process.env.MOCK_PORT || 3103); app.listen(port, '127.0.0.1', () => console.log(`TEST MOCK ONLY at http://127.0.0.1:${port}/v1`));