SpamSafeTests.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. const path = require('path')
  2. const modulePath = path.join(
  3. __dirname,
  4. '../../../../app/src/Features/Email/SpamSafe'
  5. )
  6. const SpamSafe = require(modulePath)
  7. const { expect } = require('chai')
  8. describe('SpamSafe', function () {
  9. it('should reject spammy names', function () {
  10. expect(SpamSafe.isSafeUserName('Charline Wałęsa')).to.equal(true)
  11. expect(
  12. SpamSafe.isSafeUserName(
  13. "hey come buy this product im selling it's really good for you and it'll make your latex 10x guaranteed"
  14. )
  15. ).to.equal(false)
  16. expect(SpamSafe.isSafeUserName('隆太郎 宮本')).to.equal(true)
  17. expect(SpamSafe.isSafeUserName('Visit haxx0red.com')).to.equal(false)
  18. expect(
  19. SpamSafe.isSafeUserName(
  20. '加美汝VX:hihi661,金沙2001005com the first deposit will be _100%_'
  21. )
  22. ).to.equal(false)
  23. expect(
  24. SpamSafe.isSafeProjectName(
  25. 'Neural Networks: good for your health and will solve all your problems'
  26. )
  27. ).to.equal(false)
  28. expect(
  29. SpamSafe.isSafeProjectName(
  30. 'An analysis of the questions of the universe!'
  31. )
  32. ).to.equal(true)
  33. expect(SpamSafe.isSafeProjectName("A'p'o's't'r'o'p'h'e gallore")).to.equal(
  34. true
  35. )
  36. expect(
  37. SpamSafe.isSafeProjectName(
  38. 'come buy this => http://www.dopeproduct.com/search/?q=user123'
  39. )
  40. ).to.equal(false)
  41. expect(
  42. SpamSafe.isSafeEmail('realistic-email+1@domain.sub-hyphen.com')
  43. ).to.equal(true)
  44. expect(SpamSafe.isSafeEmail('notquiteRight@evil$.com')).to.equal(false)
  45. expect(SpamSafe.safeUserName('Tammy Weinstįen', 'A User')).to.equal(
  46. 'Tammy Weinstįen'
  47. )
  48. expect(SpamSafe.safeUserName('haxx0red.com', 'A User')).to.equal('A User')
  49. expect(SpamSafe.safeUserName('What$ Upp', 'A User')).to.equal('A User')
  50. expect(SpamSafe.safeProjectName('Math-ematics!', 'A Project')).to.equal(
  51. 'Math-ematics!'
  52. )
  53. expect(
  54. SpamSafe.safeProjectName(
  55. `A Very long title for a very long book that will never be read${'a'.repeat(
  56. 250
  57. )}`,
  58. 'A Project'
  59. )
  60. ).to.equal('A Project')
  61. expect(
  62. SpamSafe.safeEmail('safe-ëmail@domain.com', 'A collaborator')
  63. ).to.equal('safe-ëmail@domain.com')
  64. expect(
  65. SpamSafe.safeEmail('Բարեւ@another.domain', 'A collaborator')
  66. ).to.equal('Բարեւ@another.domain')
  67. expect(
  68. SpamSafe.safeEmail(`me+${'a'.repeat(40)}@googoole.con`, 'A collaborator')
  69. ).to.equal('A collaborator')
  70. expect(
  71. SpamSafe.safeEmail('sendME$$$@iAmAprince.com', 'A collaborator')
  72. ).to.equal('A collaborator')
  73. })
  74. })