Skip to content
Browse files

test for UTF8 job failure sanitization

thanks to @myronmarston
  • Loading branch information...
1 parent 5a0651d commit 575cc410085834f9598e9d58b4700d24b25e3374 @hone hone committed
Showing with 21 additions and 0 deletions.
  1. +21 −0 test/resque_failure_redis_test.rb
View
21 test/resque_failure_redis_test.rb
@@ -0,0 +1,21 @@
+require 'test_helper'
+require 'resque/failure/redis'
+
+describe Resque::Failure::Redis do
+ let(:bad_string) { [39, 250, 141, 168, 138, 191, 52, 211, 159, 86, 93, 95, 39].map { |c| c.chr }.join }
+ let(:exception) { StandardError.exception(bad_string) }
+ let(:worker) { Resque::Worker.new(:test) }
+ let(:queue) { "queue" }
+ let(:payload) { { "class" => Object, "args" => 3 } }
+ let(:redis_backend) { Resque::Failure::Redis.new(exception, worker, queue, payload) }
+
+ it 'cleans up bad strings before saving the failure, in order to prevent errors on the resque UI' do
+ # test assumption: the bad string should not be able to round trip though JSON
+ assert_raises(MultiJson::DecodeError) {
+ MultiJson.decode(MultiJson.encode(bad_string))
+ }
+
+ redis_backend.save
+ Resque::Failure::Redis.all # should not raise an error
+ end
+end

0 comments on commit 575cc41

Please sign in to comment.
Something went wrong with that request. Please try again.