Skip to content

Commit 575cc41

Browse files
committed
test for UTF8 job failure sanitization
thanks to @myronmarston
1 parent 5a0651d commit 575cc41

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

test/resque_failure_redis_test.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
require 'test_helper'
2+
require 'resque/failure/redis'
3+
4+
describe Resque::Failure::Redis do
5+
let(:bad_string) { [39, 250, 141, 168, 138, 191, 52, 211, 159, 86, 93, 95, 39].map { |c| c.chr }.join }
6+
let(:exception) { StandardError.exception(bad_string) }
7+
let(:worker) { Resque::Worker.new(:test) }
8+
let(:queue) { "queue" }
9+
let(:payload) { { "class" => Object, "args" => 3 } }
10+
let(:redis_backend) { Resque::Failure::Redis.new(exception, worker, queue, payload) }
11+
12+
it 'cleans up bad strings before saving the failure, in order to prevent errors on the resque UI' do
13+
# test assumption: the bad string should not be able to round trip though JSON
14+
assert_raises(MultiJson::DecodeError) {
15+
MultiJson.decode(MultiJson.encode(bad_string))
16+
}
17+
18+
redis_backend.save
19+
Resque::Failure::Redis.all # should not raise an error
20+
end
21+
end

0 commit comments

Comments
 (0)