|
6 | 6 | RSpec.describe Sentry::HTTPTransport do
|
7 | 7 | include_context "with request mock"
|
8 | 8 |
|
| 9 | + around do |example| |
| 10 | + WebMock.disable! |
| 11 | + example.run |
| 12 | + WebMock.enable! |
| 13 | + end |
| 14 | + |
9 | 15 | let(:configuration) do
|
10 | 16 | Sentry::Configuration.new.tap do |config|
|
11 | 17 | config.dsn = Sentry::TestHelper::DUMMY_DSN
|
|
22 | 28 | subject { client.transport }
|
23 | 29 |
|
24 | 30 | it "logs a debug message only during initialization" do
|
25 |
| - stub_request(build_fake_response("200")) |
| 31 | + sentry_stub_request(build_fake_response("200")) |
26 | 32 | string_io = StringIO.new
|
27 | 33 | configuration.logger = Logger.new(string_io)
|
28 | 34 |
|
|
39 | 45 | end
|
40 | 46 |
|
41 | 47 | it "initializes new Net::HTTP instance for every request" do
|
42 |
| - stub_request(build_fake_response("200")) do |request| |
| 48 | + sentry_stub_request(build_fake_response("200")) do |request| |
43 | 49 | expect(request["User-Agent"]).to eq("sentry-ruby/#{Sentry::VERSION}")
|
44 | 50 | end
|
45 | 51 |
|
|
87 | 93 | let(:fake_response) { build_fake_response("200") }
|
88 | 94 |
|
89 | 95 | it 'sets default User-Agent' do
|
90 |
| - stub_request(fake_response) do |request| |
| 96 | + sentry_stub_request(fake_response) do |request| |
91 | 97 | expect(request["User-Agent"]).to eq("sentry-ruby/#{Sentry::VERSION}")
|
92 | 98 | end
|
93 | 99 |
|
|
97 | 103 | it "accepts custom proxy" do
|
98 | 104 | configuration.transport.proxy = { uri: URI("https://example.com"), user: "stan", password: "foobar" }
|
99 | 105 |
|
100 |
| - stub_request(fake_response) do |_, http_obj| |
| 106 | + sentry_stub_request(fake_response) do |_, http_obj| |
101 | 107 | expect(http_obj.proxy_address).to eq("example.com")
|
102 | 108 | expect(http_obj.proxy_user).to eq("stan")
|
103 | 109 | expect(http_obj.proxy_pass).to eq("foobar")
|
|
109 | 115 | it "accepts a custom proxy string" do
|
110 | 116 | configuration.transport.proxy = "https://stan:[email protected]:8080"
|
111 | 117 |
|
112 |
| - stub_request(fake_response) do |_, http_obj| |
| 118 | + sentry_stub_request(fake_response) do |_, http_obj| |
113 | 119 | expect(http_obj.proxy_address).to eq("example.com")
|
114 | 120 | expect(http_obj.proxy_user).to eq("stan")
|
115 | 121 | expect(http_obj.proxy_pass).to eq("foobar")
|
|
122 | 128 | it "accepts a custom proxy URI" do
|
123 | 129 | configuration.transport.proxy = URI("https://stan:[email protected]:8080")
|
124 | 130 |
|
125 |
| - stub_request(fake_response) do |_, http_obj| |
| 131 | + sentry_stub_request(fake_response) do |_, http_obj| |
126 | 132 | expect(http_obj.proxy_address).to eq("example.com")
|
127 | 133 | expect(http_obj.proxy_user).to eq("stan")
|
128 | 134 | expect(http_obj.proxy_pass).to eq("foobar")
|
|
136 | 142 | begin
|
137 | 143 | ENV["http_proxy"] = "https://stan:[email protected]:8080"
|
138 | 144 |
|
139 |
| - stub_request(fake_response) do |_, http_obj| |
| 145 | + sentry_stub_request(fake_response) do |_, http_obj| |
140 | 146 | expect(http_obj.proxy_address).to eq("example.com")
|
141 | 147 | expect(http_obj.proxy_port).to eq(8080)
|
142 | 148 |
|
|
155 | 161 | it "accepts custom timeout" do
|
156 | 162 | configuration.transport.timeout = 10
|
157 | 163 |
|
158 |
| - stub_request(fake_response) do |_, http_obj| |
| 164 | + sentry_stub_request(fake_response) do |_, http_obj| |
159 | 165 | expect(http_obj.read_timeout).to eq(10)
|
160 | 166 |
|
161 | 167 | if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.6")
|
|
169 | 175 | it "accepts custom open_timeout" do
|
170 | 176 | configuration.transport.open_timeout = 10
|
171 | 177 |
|
172 |
| - stub_request(fake_response) do |_, http_obj| |
| 178 | + sentry_stub_request(fake_response) do |_, http_obj| |
173 | 179 | expect(http_obj.open_timeout).to eq(10)
|
174 | 180 | end
|
175 | 181 |
|
|
178 | 184 |
|
179 | 185 | describe "ssl configurations" do
|
180 | 186 | it "has the corrent default" do
|
181 |
| - stub_request(fake_response) do |_, http_obj| |
| 187 | + sentry_stub_request(fake_response) do |_, http_obj| |
182 | 188 | expect(http_obj.verify_mode).to eq(1)
|
183 | 189 | expect(http_obj.ca_file).to eq(nil)
|
184 | 190 | end
|
|
189 | 195 | it "accepts custom ssl_verification configuration" do
|
190 | 196 | configuration.transport.ssl_verification = false
|
191 | 197 |
|
192 |
| - stub_request(fake_response) do |_, http_obj| |
| 198 | + sentry_stub_request(fake_response) do |_, http_obj| |
193 | 199 | expect(http_obj.verify_mode).to eq(0)
|
194 | 200 | expect(http_obj.ca_file).to eq(nil)
|
195 | 201 | end
|
|
200 | 206 | it "accepts custom ssl_ca_file configuration" do
|
201 | 207 | configuration.transport.ssl_ca_file = "/tmp/foo"
|
202 | 208 |
|
203 |
| - stub_request(fake_response) do |_, http_obj| |
| 209 | + sentry_stub_request(fake_response) do |_, http_obj| |
204 | 210 | expect(http_obj.verify_mode).to eq(1)
|
205 | 211 | expect(http_obj.ca_file).to eq("/tmp/foo")
|
206 | 212 | end
|
|
211 | 217 | it "accepts custom ssl configuration" do
|
212 | 218 | configuration.transport.ssl = { verify: false, ca_file: "/tmp/foo" }
|
213 | 219 |
|
214 |
| - stub_request(fake_response) do |_, http_obj| |
| 220 | + sentry_stub_request(fake_response) do |_, http_obj| |
215 | 221 | expect(http_obj.verify_mode).to eq(0)
|
216 | 222 | expect(http_obj.ca_file).to eq("/tmp/foo")
|
217 | 223 | end
|
|
225 | 231 | let(:fake_response) { build_fake_response("200") }
|
226 | 232 |
|
227 | 233 | it "compresses data by default" do
|
228 |
| - stub_request(fake_response) do |request| |
| 234 | + sentry_stub_request(fake_response) do |request| |
229 | 235 | expect(request["Content-Type"]).to eq("application/x-sentry-envelope")
|
230 | 236 | expect(request["Content-Encoding"]).to eq("gzip")
|
231 | 237 |
|
|
238 | 244 | end
|
239 | 245 |
|
240 | 246 | it "doesn't compress small event" do
|
241 |
| - stub_request(fake_response) do |request| |
| 247 | + sentry_stub_request(fake_response) do |request| |
242 | 248 | expect(request["Content-Type"]).to eq("application/x-sentry-envelope")
|
243 | 249 | expect(request["Content-Encoding"]).to eq("")
|
244 | 250 |
|
|
255 | 261 | it "doesn't compress data if the encoding is not gzip" do
|
256 | 262 | configuration.transport.encoding = "json"
|
257 | 263 |
|
258 |
| - stub_request(fake_response) do |request| |
| 264 | + sentry_stub_request(fake_response) do |request| |
259 | 265 | expect(request["Content-Type"]).to eq("application/x-sentry-envelope")
|
260 | 266 | expect(request["Content-Encoding"]).to eq("")
|
261 | 267 |
|
|
296 | 302 | let(:fake_response) { build_fake_response("404") }
|
297 | 303 |
|
298 | 304 | it "raises an error" do
|
299 |
| - stub_request(fake_response) |
| 305 | + sentry_stub_request(fake_response) |
300 | 306 |
|
301 | 307 | expect { subject.send_data(data) }.to raise_error(Sentry::ExternalError, /the server responded with status 404/)
|
302 | 308 | end
|
|
306 | 312 | let(:fake_response) { build_fake_response("500") }
|
307 | 313 |
|
308 | 314 | it "raises an error" do
|
309 |
| - stub_request(fake_response) |
| 315 | + sentry_stub_request(fake_response) |
310 | 316 |
|
311 | 317 | expect { subject.send_data(data) }.to raise_error(Sentry::ExternalError, /the server responded with status 500/)
|
312 | 318 | end
|
|
318 | 324 | end
|
319 | 325 |
|
320 | 326 | it "raises an error with header" do
|
321 |
| - stub_request(error_response) |
| 327 | + sentry_stub_request(error_response) |
322 | 328 |
|
323 | 329 | expect { subject.send_data(data) }.to raise_error(Sentry::ExternalError, /error_in_header/)
|
324 | 330 | end
|
|
0 commit comments