UNPKG

smc-hub

Version:

CoCalc: Backend webserver component

99 lines (89 loc) 3.57 kB
// Generated by CoffeeScript 2.5.1 (function() { //######################################################################## // This file is part of CoCalc: Copyright © 2020 Sagemath, Inc. // License: AGPLv3 s.t. "Commons Clause" – see LICENSE.md for details //######################################################################## // Email Testing – this is for checking its various misc functions // pro tipp: to just run this file, cd to smc-hub and run // SMC_DB_RESET=true SMC_TEST=true npx mocha test/misc/email.coffee var email, expect; require('ts-node').register(); expect = require('expect'); email = require('../../email'); describe('test email blocking -- ', function() { it('tries one that works', function() { return expect(email.is_banned('a@b.c')).toBe(false); }); it('tries one that fails', function() { return expect(email.is_banned('a@qq.com')).toBe(true); }); it('tries one that fails', function() { return expect(email.is_banned('XX@QQ.com')).toBe(true); }); return it('tries one that fails', function() { return expect(email.is_banned('a@qq.com')).toBe(true); }); }); describe('email body escaping', function() { it('removes anchors', function() { var clean, html; html = 'test <a href="http://bad.com">good</a> foo'; clean = 'test good foo'; return expect(email.escape_email_body(html)).toBe(clean); }); it('keeps some tags as they are', function() { var html; html = '<h1>h1</h1><div>div<b>b</b></div><ul><li>li</li></ul>'; return expect(email.escape_email_body(html)).toBe(html); }); return it('fixes bad html', function() { var bad, fixed; bad = '<div>div</p><p>p<li>'; fixed = '<div>div<p></p><p>p<li></li></p></div>'; return expect(email.escape_email_body(bad)).toBe(fixed); }); }); describe('create_email_body', function() { var link2proj, message, proj_title, recipient, subject; subject = 'subject'; message = '<div>invite <b>message</ul>'; recipient = 'foo@bar.com'; proj_title = 'project-title'; link2proj = 'https://foo.bar/uuid/'; it('contains instructions what to do', function() { var body; body = email.create_email_body(subject, message, recipient, proj_title, link2proj, false); expect(body).toInclude('<div>invite <b>message</b></div>'); //sanitized expect(body).toInclude(`<code>${recipient}</code>`); expect(body).toInclude(`href=\'${link2proj}\'`); expect(body).toInclude("using <i>exactly</i> your email address"); return expect(body).toInclude(proj_title); }); it('blocks URLs in the message', function() { var err, err0; message = 'please goto <a href="http://bad.com">good.com</a> thank you'; err = ''; try { email.create_email_body(subject, message, recipient, proj_title, link2proj, false); } catch (error) { err0 = error; err = err0; } return expect(err.message).toInclude('not allowed'); }); return it('allow URLs in the message if told so', function() { var err, err0; message = 'please goto <a href="http://bad.com">good.com</a> thank you'; err = 'no-error'; try { email.create_email_body(subject, message, recipient, proj_title, link2proj, true); } catch (error) { err0 = error; err = err0; } return expect(err).toBe('no-error'); }); }); }).call(this); //# sourceMappingURL=email.js.map