customembed: drop <object> and <embed>
This commit is contained in:
parent
9e5a63d880
commit
182e6f0816
2 changed files with 34 additions and 73 deletions
|
|
@ -1,21 +1,47 @@
|
|||
const customembed = require('../lib/customembed');
|
||||
const assert = require('assert');
|
||||
const crypto = require("crypto");
|
||||
|
||||
function sha256(input) {
|
||||
let hash = crypto.createHash('sha256');
|
||||
hash.update(input);
|
||||
return hash.digest('base64');
|
||||
}
|
||||
|
||||
describe('customembed', () => {
|
||||
describe('#filter', () => {
|
||||
it('rejects plain-HTTP <embed> inputs', () => {
|
||||
const input = '<embed src="http://foo.bar/baz.swf" type="application/x-shockwave-flash"></embed>';
|
||||
assert.throws(() => { customembed.filter(input) }, /must be HTTPS/);
|
||||
it('rejects <embed> inputs', () => {
|
||||
const input = '<embed src="https://example.com/baz.swf" type="application/x-shockwave-flash"></embed>';
|
||||
assert.throws(() => { customembed.filter(input) }, /must be an <iframe>/);
|
||||
});
|
||||
|
||||
it('rejects plain-HTTP <object> inputs', () => {
|
||||
const input = '<object data="http://foo.bar/baz.swf" type="application/x-shockwave-flash"></object>';
|
||||
assert.throws(() => { customembed.filter(input) }, /must be HTTPS/);
|
||||
it('rejects <object> inputs', () => {
|
||||
const input = '<object data="https://example.com/baz.swf" type="application/x-shockwave-flash"></object>';
|
||||
assert.throws(() => { customembed.filter(input) }, /must be an <iframe>/);
|
||||
});
|
||||
|
||||
it('rejects plain-HTTP <iframe> inputs', () => {
|
||||
const input = '<iframe src="http://foo.bar/baz.swf"></iframe>';
|
||||
assert.throws(() => { customembed.filter(input) }, /must be HTTPS/);
|
||||
});
|
||||
|
||||
it('accepts a valid iframe', () => {
|
||||
let input = '<iframe src="https://example.com/video.html"</iframe>';
|
||||
const { id, title, seconds, duration, type, meta } = customembed.filter(input).pack();
|
||||
const { embed } = meta;
|
||||
|
||||
assert.strictEqual(id, `cu:${sha256(input)}`);
|
||||
assert.strictEqual(title, 'Custom Media');
|
||||
assert.strictEqual(seconds, 0);
|
||||
assert.strictEqual(duration, '--:--');
|
||||
assert.strictEqual(type, 'cu');
|
||||
assert.deepStrictEqual(
|
||||
embed,
|
||||
{
|
||||
tag: 'iframe',
|
||||
src: 'https://example.com/video.html'
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue