Refine school script diagnostics and document-state capture
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs');
|
||||
const vm = require('node:vm');
|
||||
const path = require('node:path');
|
||||
const src = fs.readFileSync(path.join(__dirname, '../../lib/features/school/school_browser_diagnostics.dart'), 'utf8');
|
||||
const script = src.match(/schoolPageDiagnosticsScript = r'''([\s\S]*?)''';/)[1];
|
||||
const url = 'https://eams.uestc.edu.cn/eams/home.action';
|
||||
function state({redirect = false, password = false} = {}) {
|
||||
const document = {
|
||||
querySelector(s) { assert.equal(s, 'input[type="password"]'); return password ? {} : null; },
|
||||
querySelectorAll(s) { assert.equal(s, 'link[rel~="stylesheet"]'); return [{sheet: {}}, {sheet: null}]; },
|
||||
scripts: Array(4), styleSheets: Array(1),
|
||||
};
|
||||
// Reading private data or resource URLs must never be necessary.
|
||||
for (const key of ['cookie', 'body', 'forms']) Object.defineProperty(document, key, {get() { throw Error('PRIVATE_DATA_READ'); }});
|
||||
const resources = [
|
||||
{initiatorType: 'script', responseStatus: 202},
|
||||
{initiatorType: 'link', responseStatus: 202},
|
||||
{initiatorType: 'script', responseStatus: 200},
|
||||
{initiatorType: 'fetch', responseStatus: 202},
|
||||
];
|
||||
for (const r of resources) Object.defineProperty(r, 'name', {get() { throw Error('PRIVATE_RESOURCE_URL_READ'); }});
|
||||
return JSON.parse(vm.runInNewContext(script.replace('__EXPECTED_URL__', JSON.stringify(url)), {
|
||||
document, location: {href: redirect ? 'https://idas.uestc.edu.cn/authserver/login' : url},
|
||||
window: {jQuery() {}, require: {}, beangle: null}, performance: {getEntriesByType(type) { assert.equal(type, 'resource'); return resources; }},
|
||||
}));
|
||||
}
|
||||
assert.equal(state({redirect: true}), null);
|
||||
assert.equal(state({password: true}), null);
|
||||
assert.deepEqual(state(), {scripts: 4, styles: 1, links: 2, loaded: 1, jquery: true, beangle: false, require: false, script202: 1, style202: 1});
|
||||
console.log('Browser diagnostics: actual counts, fixed library flags, redirect/password guards, no private data reads passed.');
|
||||
Reference in New Issue
Block a user