fix: harden backend stability and test production utilities

This commit is contained in:
237899745
2026-07-27 12:17:57 +08:00
parent 2c5a22fad8
commit f90311e68c
20 changed files with 803 additions and 1388 deletions

View File

@@ -199,6 +199,17 @@ async function run() {
assert.ok(jar.get('csrf_token'));
});
test('malformed JSON receives the global JSON error response', async () => {
const malformed = await request(baseUrl, new CookieJar(), 'POST', '/api/login', {
csrf: false,
headers: { 'Content-Type': 'application/json' },
body: '{"invalid":}'
});
assert.strictEqual(malformed.status, 400);
assert.strictEqual(malformed.data.success, false);
assert.strictEqual(typeof malformed.data.message, 'string');
});
test('auth endpoints login with real cookies and enforce CSRF after authentication', async () => {
const login = await request(baseUrl, jar, 'POST', '/api/login', {
json: { username: 'admin', password: adminPassword }