Permalink
Browse files

Merge branch 'develop' of https://git.znuny.com/zammad/zammad into de…

…velop
  • Loading branch information...
SummerStorm committed Jul 12, 2018
2 parents 09313ed + f041fef commit f1b7639467ef801d5f3640423b3d3275651b61be
@@ -4,6 +4,9 @@ class HttpLog < ApplicationModel
store :request
store :response
# See https://github.com/zammad/zammad/issues/2100
before_save :messages_to_utf8
=begin
cleanup old http logs
@@ -21,4 +24,10 @@ def self.cleanup(diff = 1.month)
true
end
private
def messages_to_utf8
request.transform_values! { |v| v.try(:utf8_encode) || v }
response.transform_values! { |v| v.try(:utf8_encode) || v }
end
end
@@ -0,0 +1,11 @@
class Issue2100Utf8EncodeHttpLogs < ActiveRecord::Migration[5.1]
def up
HttpLog.where('request LIKE :enctag OR response LIKE :enctag', enctag: '%content: !binary |%')
.limit(100_000)
.order(created_at: :desc)
.find_each do |log|
log.update(request: log.request.transform_values(&:utf8_encode),
response: log.response.transform_values(&:utf8_encode))
end
end
end
@@ -0,0 +1,12 @@
FactoryBot.define do
factory :http_log do
direction 'in'
facility 'cti'
add_attribute(:method) { 'post' }
url 'https://zammad.fqdn.com/api/v1/integration/cti/log'
request { { content: 'foo' } }
response { { content: 'bar' } }
created_by_id 1
updated_by_id 1
end
end
@@ -0,0 +1,19 @@
require 'rails_helper'
RSpec.describe HttpLog do
let(:subject) { build(:http_log) }
describe 'callbacks' do
# See https://github.com/zammad/zammad/issues/2100
it 'converts request/response message data to UTF-8 before saving' do
subject.request[:content] = 'foo'.force_encoding('ascii-8bit')
subject.response[:content] = 'bar'.force_encoding('ascii-8bit')
# rubocop:disable Layout/MultilineMethodCallIndentation
expect { subject.save }
.to change { subject.request[:content].encoding.name }.from('ASCII-8BIT').to('UTF-8')
.and change { subject.response[:content].encoding.name }.from('ASCII-8BIT').to('UTF-8')
# rubocop:enable Layout/MultilineMethodCallIndentation
end
end
end

0 comments on commit f1b7639

Please sign in to comment.