Bump path-parse from 1.0.6 to 1.0.7
[KisSync.git] / test / customembed.js
blob2ca59ef0f03748b65ff9ff7db26c53429d7edb3c
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');
7 hash.update(input);
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>/);
16 });
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>/);
21 });
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/);
26 });
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(
39 embed,
41 tag: 'iframe',
42 src: 'https://example.com/video.html'
45 });
46 });
47 });