1 const customembed
= require('../lib/customembed');
2 const assert
= require('assert');
3 const crypto
= require("crypto");
5 function sha256(input
) {
6 let hash
= crypto
.createHash('sha256');
8 return hash
.digest('base64');
11 describe('customembed', () => {
12 describe('#filter', () => {
13 it('rejects <embed> inputs', () => {
14 const input
= '<embed src="https://example.com/baz.swf" type="application/x-shockwave-flash"></embed>';
15 assert
.throws(() => { customembed
.filter(input
) }, /must be an <iframe>/);
18 it('rejects <object> inputs', () => {
19 const input
= '<object data="https://example.com/baz.swf" type="application/x-shockwave-flash"></object>';
20 assert
.throws(() => { customembed
.filter(input
) }, /must be an <iframe>/);
23 it('rejects plain-HTTP <iframe> inputs', () => {
24 const input
= '<iframe src="http://foo.bar/baz.swf"></iframe>';
25 assert
.throws(() => { customembed
.filter(input
) }, /must be HTTPS/);
28 it('accepts a valid iframe', () => {
29 let input
= '<iframe src="https://example.com/video.html"</iframe>';
30 const { id
, title
, seconds
, duration
, type
, meta
} = customembed
.filter(input
).pack();
31 const { embed
} = meta
;
33 assert
.strictEqual(id
, `cu:${sha256(input)}`);
34 assert
.strictEqual(title
, 'Custom Media');
35 assert
.strictEqual(seconds
, 0);
36 assert
.strictEqual(duration
, '--:--');
37 assert
.strictEqual(type
, 'cu');
38 assert
.deepStrictEqual(
42 src
: 'https://example.com/video.html'