Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions sentry-ruby/lib/sentry/transport/http_transport.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,10 @@ def faraday_opts
end

def ssl_configuration
(@transport_configuration.ssl || {}).merge(
:verify => @transport_configuration.ssl_verification,
:ca_file => @transport_configuration.ssl_ca_file
)
{
verify: @transport_configuration.ssl_verification,
ca_file: @transport_configuration.ssl_ca_file
}.merge(@transport_configuration.ssl || {})
end
end
end
4 changes: 2 additions & 2 deletions sentry-ruby/spec/contexts/with_request_mock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ def setsockopt(*args); end
end

def stub_request(fake_response, &block)
allow_any_instance_of(Net::HTTP).to receive(:transport_request) do |_, request|
block.call(request) if block
allow_any_instance_of(Net::HTTP).to receive(:transport_request) do |http_obj, request|
block.call(request, http_obj) if block
end.and_return(fake_response)
end

Expand Down
90 changes: 88 additions & 2 deletions sentry-ruby/spec/sentry/transport/http_transport_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,14 @@
end

describe "customizations" do
it 'sets a custom User-Agent' do
expect(subject.conn.headers[:user_agent]).to eq("sentry-ruby/#{Sentry::VERSION}")
let(:fake_response) { build_fake_response("200") }

it 'sets default User-Agent' do
stub_request(fake_response) do |request|
expect(request["User-Agent"]).to eq("sentry-ruby/#{Sentry::VERSION}")
end

subject.send_data(data)
end

it 'allows to customise faraday' do
Expand All @@ -41,6 +47,86 @@

expect(builder).to have_received(:request).with(:instrumentation)
end

it "accepts custom proxy" do
configuration.transport.proxy = { uri: URI("https://example.com"), user: "stan", password: "foobar" }

stub_request(fake_response) do |_, http_obj|
expect(http_obj.proxy_address).to eq("example.com")
expect(http_obj.proxy_user).to eq("stan")
expect(http_obj.proxy_pass).to eq("foobar")
end

subject.send_data(data)
end

it "accepts custom timeout" do
configuration.transport.timeout = 10

stub_request(fake_response) do |_, http_obj|
expect(http_obj.read_timeout).to eq(10)

if RUBY_VERSION >= "2.6"
expect(http_obj.write_timeout).to eq(10)
end
end

subject.send_data(data)
end

it "accepts custom open_timeout" do
configuration.transport.open_timeout = 10

stub_request(fake_response) do |_, http_obj|
expect(http_obj.open_timeout).to eq(10)
end

subject.send_data(data)
end

describe "ssl configurations" do
it "has the corrent default" do
stub_request(fake_response) do |_, http_obj|
expect(http_obj.verify_mode).to eq(1)
expect(http_obj.ca_file).to eq(nil)
end

subject.send_data(data)
end

it "accepts custom ssl_verification configuration" do
configuration.transport.ssl_verification = false

stub_request(fake_response) do |_, http_obj|
expect(http_obj.verify_mode).to eq(0)
expect(http_obj.ca_file).to eq(nil)
end

subject.send_data(data)
end

it "accepts custom ssl_ca_file configuration" do
configuration.transport.ssl_ca_file = "/tmp/foo"

stub_request(fake_response) do |_, http_obj|
expect(http_obj.verify_mode).to eq(1)
expect(http_obj.ca_file).to eq("/tmp/foo")
end

subject.send_data(data)
end

it "accepts custom ssl configuration" do
configuration.transport.ssl = { verify: false, ca_file: "/tmp/foo" }

stub_request(fake_response) do |_, http_obj|
expect(http_obj.verify_mode).to eq(0)
expect(http_obj.ca_file).to eq("/tmp/foo")
end

subject.send_data(data)
end
end
end

describe "request payload" do
Expand Down