fixes and patches n stuff

This commit is contained in:
tyuXX 2026-10-21 21:07:54 +00:00
parent 7c7ae8e051
commit 1af973d001
14 changed files with 571 additions and 268 deletions

View file

@ -694,7 +694,70 @@ async function runAllTests() {
assert(pwaContent.includes('btnSync'), 'pwa.js must manage sync buttons in offline mode');
});
// 6. Optional Live Portal Test (via environment variables only)
// 6. Security & Hardening Tests
await test('LocalDatabase: saveCredentials encrypts with AES-256-GCM and getRememberedCredentials decrypts', () => {
const fs = require('fs');
const path = require('path');
const db = LocalDatabase.getInstance();
const dbFile = path.resolve(process.cwd(), 'data', 'db.json');
const testId = 'audit_security_student';
const rawPass = 'SuperSecret123!';
db.saveCredentials(testId, rawPass);
// Verify stored format on disk is encrypted
const onDiskRaw = JSON.parse(fs.readFileSync(dbFile, 'utf-8'));
const storedCred = onDiskRaw.students[testId]?.rememberedCredentials;
assert(storedCred, 'Credentials must be saved');
assert(storedCred.password.startsWith('enc:'), 'Stored password must be encrypted with enc: prefix');
assert(!storedCred.password.includes(rawPass), 'Raw password must not be present in database file');
// Verify retrieval returns decrypted password
const retrieved = db.getRememberedCredentials(testId);
assert(retrieved !== null, 'Retrieved credentials must not be null');
assert.strictEqual(retrieved.password, rawPass, 'Decrypted password must match original raw password');
// Clean up
db.clearCredentials(testId);
});
await test('LocalDatabase: saveExamQuestions and getExamQuestions persists question review cache', () => {
const db = LocalDatabase.getInstance();
const testId = 'audit_exam_student';
const examKey = '3366_Y';
const sampleQuestions = [
{
questionNumber: 1,
correctAnswer: 'A',
studentAnswer: 'C',
imageUrl: 'https://panel.example.com/soru/1.png',
status: 'wrong' as const,
subjectId: '10',
subjectName: 'Türkçe'
}
];
db.saveExamQuestions(testId, examKey, sampleQuestions);
const cached = db.getExamQuestions(testId, examKey);
assert(cached !== null, 'Cached questions should exist');
assert.strictEqual(cached.length, 1);
assert.strictEqual(cached[0].questionNumber, 1);
assert.strictEqual(cached[0].correctAnswer, 'A');
});
await test('PWA: sw.js contains route-specific offline fallbacks and ignoreSearch', () => {
const fs = require('fs');
const path = require('path');
const swPath = path.resolve(__dirname, '../public/sw.js');
const swContent = fs.readFileSync(swPath, 'utf-8');
assert(swContent.includes('ignoreSearch: true'), 'sw.js must match cache ignoring query strings');
assert(swContent.includes("url.pathname.startsWith('/exams')"), 'sw.js must have route fallback for exams');
assert(swContent.includes("url.pathname.startsWith('/syllabus')"), 'sw.js must have route fallback for syllabus');
assert(swContent.includes("url.pathname.startsWith('/private-lessons')"), 'sw.js must have route fallback for private lessons');
});
// 7. Optional Live Portal Test (via environment variables only)
const testStudentId = process.env.TEST_STUDENT_ID;
const testPassword = process.env.TEST_PASSWORD;