SpamSafeTests.js 2.9 KB

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