SpamSafe.test.mjs 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import SpamSafe from '../../../../app/src/Features/Email/SpamSafe.mjs'
  2. import { expect } from 'vitest'
  3. describe('SpamSafe', function () {
  4. it('should reject spammy names', function () {
  5. expect(SpamSafe.isSafeUserName('Charline Wałęsa')).to.equal(true)
  6. expect(
  7. SpamSafe.isSafeUserName(
  8. "hey come buy this product im selling it's really good for you and it'll make your latex 10x guaranteed"
  9. )
  10. ).to.equal(false)
  11. expect(SpamSafe.isSafeUserName('隆太郎 宮本')).to.equal(true)
  12. expect(SpamSafe.isSafeUserName('Visit haxx0red.com')).to.equal(false)
  13. expect(
  14. SpamSafe.isSafeUserName(
  15. '加美汝VX:hihi661,金沙2001005com the first deposit will be _100%_'
  16. )
  17. ).to.equal(false)
  18. expect(
  19. SpamSafe.isSafeProjectName(
  20. 'Neural Networks: good for your health and will solve all your problems'
  21. )
  22. ).to.equal(false)
  23. expect(
  24. SpamSafe.isSafeProjectName(
  25. 'An analysis of the questions of the universe!'
  26. )
  27. ).to.equal(true)
  28. expect(SpamSafe.isSafeProjectName("A'p'o's't'r'o'p'h'e gallore")).to.equal(
  29. true
  30. )
  31. expect(
  32. SpamSafe.isSafeProjectName(
  33. 'come buy this => http://www.dopeproduct.com/search/?q=user123'
  34. )
  35. ).to.equal(false)
  36. expect(
  37. SpamSafe.isSafeEmail('realistic-email+1@domain.sub-hyphen.com')
  38. ).to.equal(true)
  39. expect(SpamSafe.isSafeEmail('jnd-9807408-1oos68@@example.com')).to.equal(
  40. false
  41. )
  42. expect(SpamSafe.isSafeEmail('123456789@example.com')).to.equal(true)
  43. expect(SpamSafe.isSafeEmail('abcdefghi@example.com')).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(SpamSafe.safeProjectName(`JND-123456-100s68`, 'A Project')).to.equal(
  62. 'A Project'
  63. )
  64. expect(
  65. SpamSafe.safeProjectName(`JiAqun123456s100sf68`, 'A Project')
  66. ).to.equal('A Project')
  67. expect(
  68. SpamSafe.safeEmail('safe-ëmail@domain.com', 'A collaborator')
  69. ).to.equal('safe-ëmail@domain.com')
  70. expect(
  71. SpamSafe.safeEmail('Բարեւ@another.domain', 'A collaborator')
  72. ).to.equal('Բարեւ@another.domain')
  73. expect(
  74. SpamSafe.safeEmail(`me+${'a'.repeat(40)}@googoole.con`, 'A collaborator')
  75. ).to.equal('A collaborator')
  76. expect(
  77. SpamSafe.safeEmail('sendME$$$@iAmAprince.com', 'A collaborator')
  78. ).to.equal('A collaborator')
  79. })
  80. })