From 50c1cfcb0ad79a8c3be4f8f38196f0cc68550850 Mon Sep 17 00:00:00 2001 From: Ryan Lue Date: Fri, 4 Jan 2019 16:29:56 +0100 Subject: [PATCH] Refactoring: Migrate ticket_null_byte_test.rb to RSpec. --- spec/factories/ticket/article.rb | 1 + spec/models/ticket/article_spec.rb | 7 +++++++ spec/models/ticket_spec.rb | 7 +++++++ test/unit/ticket_null_byte_test.rb | 33 ------------------------------ 4 files changed, 15 insertions(+), 33 deletions(-) delete mode 100644 test/unit/ticket_null_byte_test.rb diff --git a/spec/factories/ticket/article.rb b/spec/factories/ticket/article.rb index f7e18d416..e2cf23e70 100644 --- a/spec/factories/ticket/article.rb +++ b/spec/factories/ticket/article.rb @@ -5,6 +5,7 @@ FactoryBot.define do sender_name 'Customer' end + ticket from 'factory-customer-1@example.com' to 'factory-customer-1@example.com' subject 'factory article' diff --git a/spec/models/ticket/article_spec.rb b/spec/models/ticket/article_spec.rb index 54f20b943..15254f0cf 100644 --- a/spec/models/ticket/article_spec.rb +++ b/spec/models/ticket/article_spec.rb @@ -1,6 +1,13 @@ require 'rails_helper' RSpec.describe Ticket::Article do + describe '.create' do + it 'handles NULL byte in subject or body' do + expect(create(:ticket_article, subject: "com test 1\u0000", body: "some\u0000message 123")) + .to be_persisted + end + end + describe 'hooks on creation' do context 'of outgoing article' do context 'over Twitter' do diff --git a/spec/models/ticket_spec.rb b/spec/models/ticket_spec.rb index 8c175e359..06f0beb2d 100644 --- a/spec/models/ticket_spec.rb +++ b/spec/models/ticket_spec.rb @@ -65,6 +65,13 @@ RSpec.describe Ticket do end + describe '.create' do + it 'handles NULL byte in title' do + expect(create(:ticket, title: "some title \u0000 123")) + .to be_persisted + end + end + describe '#destroy' do it 'deletes all related objects before destroy' do diff --git a/test/unit/ticket_null_byte_test.rb b/test/unit/ticket_null_byte_test.rb deleted file mode 100644 index df9e91f4b..000000000 --- a/test/unit/ticket_null_byte_test.rb +++ /dev/null @@ -1,33 +0,0 @@ -require 'test_helper' - -class TicketNullByteTest < ActiveSupport::TestCase - test 'null byte test' do - ticket1 = Ticket.create!( - title: "some title \u0000 123", - group: Group.lookup(name: 'Users'), - customer_id: 2, - updated_by_id: 1, - created_by_id: 1, - ) - assert(ticket1, 'ticket created') - - article1 = Ticket::Article.create!( - ticket_id: ticket1.id, - from: 'some_customer_com-1@example.com', - to: 'some_zammad_com-1@example.com', - subject: "com test 1\u0000", - message_id: 'some@id_com_1', - body: "some\u0000message 123", - internal: false, - sender: Ticket::Article::Sender.find_by(name: 'Customer'), - type: Ticket::Article::Type.find_by(name: 'email'), - updated_by_id: 1, - created_by_id: 1, - ) - assert(article1, 'ticket created') - - ticket1.destroy! - article1.destroy! - - end -end