blob: c582e7362a5345c52b23979b83eec6ea106a1ccd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
require 'spec_helper'
require 'raven/base'
require 'raven/transports/dummy'
require_relative '../../../../lib/gitaly_server/sentry.rb'
describe GitalyServer::Sentry::URLSanitizer do
let(:meth) { GitalyServer::RefService.instance_method(:create_branch) }
let(:ex) { StandardError.new("error: failed to push some refs to 'https://fO0BA7:HunTer!@github.com/ruby/ruby.git'") }
let(:ex_sanitized_message) { "error: failed to push some refs to 'https://[FILTERED]@github.com/ruby/ruby.git'" }
let(:call) { double(metadata: {}) }
before do
Raven.configure do |config|
config.dsn = "dummy://12345:67890@sentry.localdomain:3000/sentry/42"
config.encoding = 'json'
end
allow(GitalyServer::Sentry).to receive(:enabled?).and_return(true)
end
it 'sanitizes exception data' do
begin
GitalyServer::SentryInterceptor.new.server_streamer(call: call, method: meth) { raise ex }
rescue
nil
end
data = JSON.parse(last_sentry_event[1])
expect(data['message']).to eq("StandardError: #{ex_sanitized_message}")
expect(data['logentry']['message']).to eq("StandardError: #{ex_sanitized_message}")
expect(data['fingerprint'].last).to eq(ex_sanitized_message)
expect(data['exception']['values'][0]['value']).to eq(ex_sanitized_message)
end
context 'muliple exception causes' do
it 'sanitizes all exceptions' do
cause = StandardError.new("Authorization failed for 'https://fA0TAQ:h2nTer!@github.com/ruby/ruby.git', sorry!")
cause_sanitized_message = "Authorization failed for 'https://[FILTERED]@github.com/ruby/ruby.git', sorry!"
begin
GitalyServer::SentryInterceptor.new.server_streamer(call: call, method: meth) do
begin
raise cause
rescue
raise ex
end
end
rescue
nil
end
data = JSON.parse(last_sentry_event[1])
expect(data['exception']['values'][0]['value']).to eq(cause_sanitized_message)
expect(data['exception']['values'][1]['value']).to eq(ex_sanitized_message)
end
end
def last_sentry_event
Raven.instance.client.transport.events.last
end
end
|