test/unit/client_test.rb in raygun4ruby-1.5.0 vs test/unit/client_test.rb in raygun4ruby-2.0.0
- old
+ new
@@ -27,10 +27,11 @@
end
def setup
super
@client = Raygun::Client.new
+ Raygun.configuration.record_raw_data = true
fake_successful_entry
# Force NZ time zone for utcOffset tests
ENV['TZ'] = 'UTC-13'
end
@@ -220,21 +221,42 @@
def test_getting_request_information_with_nil_env
assert_equal({}, @client.send(:request_information, nil))
end
- def test_non_form_parameters
- put_body_env_hash = sample_env_hash.merge({
- "REQUEST_METHOD"=>"PUT",
- "action_dispatch.request.parameters"=> { "a" => "b", "c" => "4945438", "password" => "swordfish" }
+ def test_raw_post_body
+ env_hash = sample_env_hash.merge({
+ "CONTENT_TYPE" => "application/json",
+ "REQUEST_METHOD" => "POST",
+ "rack.input" => StringIO.new('{"foo": "bar"}')
})
- expected_form_hash = { "a" => "b", "c" => "4945438", "password" => "[FILTERED]" }
+ assert_equal '{"foo": "bar"}', @client.send(:request_information, env_hash)[:rawData]
+ end
- assert_equal expected_form_hash, @client.send(:request_information, put_body_env_hash)[:rawData]
+ def test_raw_post_body_with_more_than_4096_chars
+ input = "0" * 5000;
+ env_hash = sample_env_hash.merge({
+ "CONTENT_TYPE" => "application/json",
+ "REQUEST_METHOD" => "POST",
+ "rack.input" => StringIO.new(input)
+ })
+
+ assert_equal input.slice(0, 4096), @client.send(:request_information, env_hash)[:rawData]
end
+ def test_raw_post_body_with_config_disabled
+ Raygun.configuration.record_raw_data = false
+ env_hash = sample_env_hash.merge({
+ "CONTENT_TYPE" => "application/json",
+ "REQUEST_METHOD" => "POST",
+ "rack.input" => StringIO.new('{"foo": "bar"}')
+ })
+
+ assert_equal(nil, @client.send(:request_information, env_hash)[:rawData])
+ end
+
def test_error_raygun_custom_data
custom_data = { "kappa" => "keepo" }
e = Raygun::Error.new("A test message", custom_data)
test_env = {}
expected_form_hash = test_env.merge(custom_data)
@@ -459,10 +481,11 @@
def test_filter_payload_with_whitelist_default_request_post
Raygun.configuration.filter_payload_with_whitelist = true
post_body_env_hash = sample_env_hash.merge(
+ "CONTENT_TYPE" => 'application/x-www-form-urlencoded',
"REQUEST_METHOD" => "POST",
"rack.input"=>StringIO.new("a=b&c=4945438&password=swordfish")
)
details = @client.send(:build_payload_hash, test_exception, post_body_env_hash)[:details]
@@ -473,11 +496,11 @@
httpMethod: "POST",
iPAddress: "127.0.0.1",
queryString: { },
headers: { "Version"=>"HTTP/1.1", "Host"=>"localhost:3000", "Cookie"=>"cookieval" },
form: { "a" => "[FILTERED]", "c" => "[FILTERED]", "password" => "[FILTERED]" },
- rawData: nil
+ rawData: {}
}
assert_equal expected_hash, details[:request]
end
@@ -504,10 +527,10 @@
httpMethod: "POST",
iPAddress: "127.0.0.1",
queryString: { },
headers: { "Version"=>"HTTP/1.1", "Host"=>"localhost:3000", "Cookie"=>"cookieval" },
form: { "username" => "foo", "password" => "[FILTERED]" },
- rawData: nil
+ rawData: {}
}
assert_equal expected_hash, details[:request]
end