ticket_article_dos_test.rb 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. require 'test_helper'
  2. class TicketArticleDos < ActiveSupport::TestCase
  3. def two_mio_random_chars
  4. @two_mio_random_chars ||= Array.new(2_000_000) { [*'0'..'9', *'a'..'z', ' ', ' ', ' ', '. '].sample }.join
  5. end
  6. test 'check body size' do
  7. org_community = Organization.create_if_not_exists(
  8. name: 'Zammad Foundation',
  9. )
  10. user_community = User.create_or_update(
  11. login: 'article.dos@example.org',
  12. firstname: 'Article',
  13. lastname: 'Dos',
  14. email: 'article.dos@example.org',
  15. password: '',
  16. active: true,
  17. roles: [ Role.find_by(name: 'Customer') ],
  18. organization_id: org_community.id,
  19. updated_by_id: 1,
  20. created_by_id: 1,
  21. )
  22. UserInfo.current_user_id = user_community.id
  23. ApplicationHandleInfo.current = 'test.postmaster'
  24. ticket1 = Ticket.create!(
  25. group_id: Group.first.id,
  26. customer_id: user_community.id,
  27. title: 'DoS 1!',
  28. updated_by_id: 1,
  29. created_by_id: 1,
  30. )
  31. article1 = Ticket::Article.create!(
  32. ticket_id: ticket1.id,
  33. type_id: Ticket::Article::Type.find_by(name: 'phone').id,
  34. sender_id: Ticket::Article::Sender.find_by(name: 'Customer').id,
  35. from: 'Zammad Feedback <feedback@example.org>',
  36. body: two_mio_random_chars,
  37. internal: false,
  38. updated_by_id: 1,
  39. created_by_id: 1,
  40. )
  41. assert_equal(1_500_000, article1.body.length)
  42. ticket2 = Ticket.create!(
  43. group_id: Group.first.id,
  44. customer_id: user_community.id,
  45. title: 'DoS 2!',
  46. updated_by_id: 1,
  47. created_by_id: 1,
  48. )
  49. article2 = Ticket::Article.create!(
  50. ticket_id: ticket2.id,
  51. type_id: Ticket::Article::Type.find_by(name: 'phone').id,
  52. sender_id: Ticket::Article::Sender.find_by(name: 'Customer').id,
  53. from: 'Zammad Feedback <feedback@example.org>',
  54. body: "\u0000#{two_mio_random_chars}",
  55. internal: false,
  56. updated_by_id: 1,
  57. created_by_id: 1,
  58. )
  59. assert_equal(1_500_000, article2.body.length)
  60. ApplicationHandleInfo.current = 'web'
  61. ticket3 = Ticket.create!(
  62. group_id: Group.first.id,
  63. customer_id: user_community.id,
  64. title: 'DoS 3!',
  65. updated_by_id: 1,
  66. created_by_id: 1,
  67. )
  68. assert_raises(Exceptions::UnprocessableEntity) do
  69. article3 = Ticket::Article.create!(
  70. ticket_id: ticket3.id,
  71. type_id: Ticket::Article::Type.find_by(name: 'phone').id,
  72. sender_id: Ticket::Article::Sender.find_by(name: 'Customer').id,
  73. from: 'Zammad Feedback <feedback@example.org>',
  74. body: "\u0000#{two_mio_random_chars}",
  75. internal: false,
  76. updated_by_id: 1,
  77. created_by_id: 1,
  78. )
  79. end
  80. end
  81. test 'check body size / cut if email' do
  82. email_raw_string = <<-MAIL.strip_indent
  83. From: me@example.com
  84. To: customer@example.com
  85. Subject: some new subject
  86. Some Text#{two_mio_random_chars}
  87. MAIL
  88. ticket_p, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
  89. assert_equal(1_500_000, article_p.body.length)
  90. end
  91. end