Files
miem_courses_links/tests/browser-policy.test.ts

11 lines
970 B
TypeScript

import assert from 'node:assert/strict';
import {test} from 'node:test';
import {browserRequestAllowed} from '../lib/browser.ts';
test('browser policy blocks other providers, internal targets, writes and heavy resources',()=>{
for(const url of ['http://127.0.0.1/','https://127.0.0.1/','https://[::1]/','http://e.lanbook.com/','https://e.lanbook.com.evil.org/','https://urait.ru/','file:///etc/passwd','https://user:pass@e.lanbook.com/'])assert.equal(browserRequestAllowed(url,'lanbook.com','GET','document'),false,url);
assert.equal(browserRequestAllowed('https://e.lanbook.com/book/111431','lanbook.com','POST','fetch'),false);
assert.equal(browserRequestAllowed('https://e.lanbook.com/cover.jpg','lanbook.com','GET','image'),false);
assert.equal(browserRequestAllowed('https://e.lanbook.com/main.js','lanbook.com','GET','script'),true);
assert.equal(browserRequestAllowed('https://link.springernature.com/book/a','springer.com','GET','document'),true);
});