Commit de1e0f89edbb761610eae84a0280352357b379c7
1 parent
97b3ef8b
Exists in
master
and in
1 other branch
Rename md5 to legacy fingerprint
Showing
4 changed files
with
63 additions
and
63 deletions
Show diff stats
... | ... | @@ -0,0 +1,20 @@ |
1 | +require 'digest/md5' | |
2 | + | |
3 | +class LegacyFingerprint < Fingerprint | |
4 | + def to_s | |
5 | + Digest::MD5.hexdigest(fingerprint_source) | |
6 | + end | |
7 | + | |
8 | + def fingerprint_source | |
9 | + location['method'] &&= sanitized_method_signature | |
10 | + end | |
11 | + | |
12 | + private | |
13 | + def sanitized_method_signature | |
14 | + location['method'].gsub(/[0-9]+|FRAGMENT/, '#').gsub(/_+#/, '_#') | |
15 | + end | |
16 | + | |
17 | + def location | |
18 | + notice.backtrace.lines.first | |
19 | + end | |
20 | +end | ... | ... |
app/models/fingerprints/md5_fingerprint.rb
... | ... | @@ -1,20 +0,0 @@ |
1 | -require 'digest/md5' | |
2 | - | |
3 | -class MD5Fingerprint < Fingerprint | |
4 | - def to_s | |
5 | - Digest::MD5.hexdigest(fingerprint_source) | |
6 | - end | |
7 | - | |
8 | - def fingerprint_source | |
9 | - location['method'] &&= sanitized_method_signature | |
10 | - end | |
11 | - | |
12 | - private | |
13 | - def sanitized_method_signature | |
14 | - location['method'].gsub(/[0-9]+|FRAGMENT/, '#').gsub(/_+#/, '_#') | |
15 | - end | |
16 | - | |
17 | - def location | |
18 | - notice.backtrace.lines.first | |
19 | - end | |
20 | -end |
... | ... | @@ -0,0 +1,43 @@ |
1 | +require 'spec_helper' | |
2 | + | |
3 | +describe LegacyFingerprint do | |
4 | + context 'being created' do | |
5 | + let(:backtrace) do | |
6 | + Backtrace.create(:raw => [ | |
7 | + { | |
8 | + "number"=>"17", | |
9 | + "file"=>"[GEM_ROOT]/gems/activesupport/lib/active_support/callbacks.rb", | |
10 | + "method"=>"_run__2497084960985961383__process_action__2062871603614456254__callbacks" | |
11 | + } | |
12 | + ]) | |
13 | + end | |
14 | + let(:notice1) { Fabricate.build(:notice, :backtrace => backtrace) } | |
15 | + let(:notice2) { Fabricate.build(:notice, :backtrace => backtrace_2) } | |
16 | + | |
17 | + context "with same backtrace" do | |
18 | + let(:backtrace_2) do | |
19 | + backtrace | |
20 | + backtrace.lines.last.method = '_run__FRAGMENT__process_action__FRAGMENT__callbacks' | |
21 | + backtrace.save | |
22 | + backtrace | |
23 | + end | |
24 | + | |
25 | + it "normalizes the fingerprint of generated methods" do | |
26 | + expect(LegacyFingerprint.generate(notice1, "api key")).to eql LegacyFingerprint.generate(notice2, "api key") | |
27 | + end | |
28 | + end | |
29 | + | |
30 | + context "with same backtrace where FRAGMENT has not been extracted" do | |
31 | + let(:backtrace_2) do | |
32 | + backtrace | |
33 | + backtrace.lines.last.method = '_run__998857585768765__process_action__1231231312321313__callbacks' | |
34 | + backtrace.save | |
35 | + backtrace | |
36 | + end | |
37 | + | |
38 | + it "normalizes the fingerprint of generated methods" do | |
39 | + expect(LegacyFingerprint.generate(notice1, "api key")).to eql LegacyFingerprint.generate(notice2, "api key") | |
40 | + end | |
41 | + end | |
42 | + end | |
43 | +end | ... | ... |
spec/models/fingerprints/md5_fingerprint_spec.rb
... | ... | @@ -1,43 +0,0 @@ |
1 | -require 'spec_helper' | |
2 | - | |
3 | -describe MD5Fingerprint do | |
4 | - context 'being created' do | |
5 | - let(:backtrace) do | |
6 | - Backtrace.create(:raw => [ | |
7 | - { | |
8 | - "number"=>"17", | |
9 | - "file"=>"[GEM_ROOT]/gems/activesupport/lib/active_support/callbacks.rb", | |
10 | - "method"=>"_run__2497084960985961383__process_action__2062871603614456254__callbacks" | |
11 | - } | |
12 | - ]) | |
13 | - end | |
14 | - let(:notice1) { Fabricate.build(:notice, :backtrace => backtrace) } | |
15 | - let(:notice2) { Fabricate.build(:notice, :backtrace => backtrace_2) } | |
16 | - | |
17 | - context "with same backtrace" do | |
18 | - let(:backtrace_2) do | |
19 | - backtrace | |
20 | - backtrace.lines.last.method = '_run__FRAGMENT__process_action__FRAGMENT__callbacks' | |
21 | - backtrace.save | |
22 | - backtrace | |
23 | - end | |
24 | - | |
25 | - it "normalizes the fingerprint of generated methods" do | |
26 | - expect(MD5Fingerprint.generate(notice1, "api key")).to eql MD5Fingerprint.generate(notice2, "api key") | |
27 | - end | |
28 | - end | |
29 | - | |
30 | - context "with same backtrace where FRAGMENT has not been extracted" do | |
31 | - let(:backtrace_2) do | |
32 | - backtrace | |
33 | - backtrace.lines.last.method = '_run__998857585768765__process_action__1231231312321313__callbacks' | |
34 | - backtrace.save | |
35 | - backtrace | |
36 | - end | |
37 | - | |
38 | - it "normalizes the fingerprint of generated methods" do | |
39 | - expect(MD5Fingerprint.generate(notice1, "api key")).to eql MD5Fingerprint.generate(notice2, "api key") | |
40 | - end | |
41 | - end | |
42 | - end | |
43 | -end |