Skip to content

Commit

Permalink
Fix unit test to support Logstash 8 nano timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
kaisecheng committed May 3, 2022
1 parent 1d8b089 commit 0dee360
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions spec/filters/fingerprint_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -273,31 +273,35 @@
end

context 'Timestamps' do
epoch_time = Time.at(0).gmtime
let(:epoch_time) { Time.at(0).gmtime }
let(:logstash_epoch_time) { LogStash::Timestamp.new(epoch_time).to_s }
let(:config) { super().merge("source" => ['@timestamp']) }

describe 'OpenSSL Fingerprinting' do
let(:config) { super().merge("key" => '0123') }
let(:key) { '0123' }
let(:config) { super().merge("key" => key) }
let(:fingerprint_method) { "SHA1" }
let(:data) { { "@timestamp" => epoch_time } }
it "fingerprints the timestamp correctly" do
expect(fingerprint).to eq('1d5379ec92d86a67cfc642d55aa050ca312d3b9a')
digest = OpenSSL::Digest::SHA1.new
hash = OpenSSL::HMAC.hexdigest(digest, key, logstash_epoch_time).force_encoding(Encoding::UTF_8)
expect(fingerprint).to eq hash
end
end

describe 'MURMUR3 Fingerprinting' do
let(:fingerprint_method) { "MURMUR3" }
let(:data) { { "@timestamp" => epoch_time } }
it "fingerprints the timestamp correctly" do
expect(fingerprint).to eq(743372282)
expect(fingerprint).to eq MurmurHash3::V32.str_hash(logstash_epoch_time)
end
end

describe 'MURMUR3_128 Fingerprinting' do
let(:fingerprint_method) { "MURMUR3_128" }
let(:data) { { "@timestamp" => epoch_time } }
it "fingerprints the timestamp correctly" do
expect(fingerprint).to eq("37785b62a8cae473acc315d39b66d86e")
expect(fingerprint).to eq MurmurHash3::V128.str_hexdigest(logstash_epoch_time, 2)
end
end
end
Expand Down

0 comments on commit 0dee360

Please sign in to comment.