overleaf/services/web/test/unit/coffee/Email/SpamSafeTests.coffee
Timothée Alby 429709dfcb Merge pull request #1621 from sharelatex/ns-update-spam-regexes
allow hyphen in email hostname and ' in project name

GitOrigin-RevId: d108b7d42372dee4250157e2830cbc800851afc1
2019-03-14 16:02:45 +00:00

29 lines
2.2 KiB
CoffeeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

path = require('path')
modulePath = path.join __dirname, "../../../../app/js/Features/Email/SpamSafe"
SpamSafe = require(modulePath)
expect = require("chai").expect
describe "SpamSafe", ->
it 'should reject spammy names', ->
expect(SpamSafe.isSafeUserName("Charline Wałęsa")).to.equal true
expect(SpamSafe.isSafeUserName("hey come buy this product im selling it's really good for you and it'll make your latex 10x guaranteed")).to.equal false
expect(SpamSafe.isSafeUserName("隆太郎 宮本")).to.equal true
expect(SpamSafe.isSafeUserName("Visit haxx0red.com")).to.equal false
expect(SpamSafe.isSafeUserName('加美汝VXhihi661金沙2001005com the first deposit will be _100%_')).to.equal false
expect(SpamSafe.isSafeProjectName('Neural Networks: good for your health and will solve all your problems')).to.equal false
expect(SpamSafe.isSafeProjectName("An analysis of the questions of the universe!")).to.equal true
expect(SpamSafe.isSafeProjectName("A'p'o's't'r'o'p'h'e gallore")).to.equal true
expect(SpamSafe.isSafeProjectName('come buy this => http://www.dopeproduct.com/search/?q=user123')).to.equal false
expect(SpamSafe.isSafeEmail("realistic-email+1@domain.sub-hyphen.com")).to.equal true
expect(SpamSafe.isSafeEmail("notquiteRight\@evil$.com")).to.equal false
expect(SpamSafe.safeUserName("Tammy Weinstįen", "A User")).to.equal "Tammy Weinstįen"
expect(SpamSafe.safeUserName("haxx0red.com", "A User")).to.equal "A User"
expect(SpamSafe.safeUserName("What$ Upp", "A User")).to.equal "A User"
expect(SpamSafe.safeProjectName("Math-ematics!", "A Project")).to.equal "Math-ematics!"
expect(SpamSafe.safeProjectName("A Very long title for a very long book that will never be read" + "a".repeat(250), "A Project")).to.equal "A Project"
expect(SpamSafe.safeEmail("safe-ëmail@domain.com", "A collaborator")).to.equal "safe-ëmail@domain.com"
expect(SpamSafe.safeEmail("Բարեւ@another.domain", "A collaborator")).to.equal "Բարեւ@another.domain"
expect(SpamSafe.safeEmail("me+" + "a".repeat(40) + "@googoole.con", "A collaborator")).to.equal "A collaborator"
expect(SpamSafe.safeEmail("sendME$$$@iAmAprince.com", "A collaborator")).to.equal "A collaborator"