-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GeoIP database add license files #12756
Changes from 4 commits
b2ffe29
9aa747b
7bdce6f
ac4166d
e2a43d5
e507670
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,14 +50,23 @@ module LogStash module Filters module Geoip | |
end | ||
|
||
context "save timestamp" do | ||
before do | ||
::File.open(DEFAULT_CITY_GZ_PATH, "w") { |f| f.write "make a non empty file" } | ||
end | ||
|
||
after do | ||
delete_file(DEFAULT_CITY_GZ_PATH) | ||
end | ||
|
||
it "write the current time" do | ||
dbm.save_timestamp(DEFAULT_CITY_DB_PATH) | ||
|
||
metadata = dbm.get_metadata.last | ||
expect(metadata[DatabaseMetadata::Column::DATABASE_TYPE]).to eq("City") | ||
past = metadata[DatabaseMetadata::Column::UPDATE_AT] | ||
expect(Time.now.to_i - past.to_i).to be < 100 | ||
expect(metadata[DatabaseMetadata::Column::GZ_MD5]).to eq('') | ||
expect(metadata[DatabaseMetadata::Column::GZ_MD5]).not_to be_empty | ||
expect(metadata[DatabaseMetadata::Column::GZ_MD5]).to eq(md5(DEFAULT_CITY_GZ_PATH)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I see that this spec opens up the Geoip filter's definition, then opens up a spec context with module LogStash module Filters module Geoip
describe DatabaseMetadata, :aggregate_failures do
# ...
end
end end end Should be: context LogStash::Filters::Geoip do
describe DatabaseMetadata, :aggregate_failures do
# ...
end
end |
||
expect(metadata[DatabaseMetadata::Column::MD5]).to eq(DEFAULT_CITY_DB_MD5) | ||
expect(metadata[DatabaseMetadata::Column::FILENAME]).to eq(DEFAULT_CITY_DB_NAME) | ||
end | ||
|
@@ -128,9 +137,10 @@ module LogStash module Filters module Geoip | |
end | ||
|
||
context "database filenames" do | ||
it "should give filename in .mmdb .gz" do | ||
it "should give filename in .mmdb .tgz" do | ||
write_temp_metadata(temp_metadata_path) | ||
expect(dbm.database_filenames).to match_array([DEFAULT_CITY_DB_NAME, DEFAULT_ASN_DB_NAME, 'GeoLite2-City.mmdb.gz', 'GeoLite2-ASN.mmdb.gz']) | ||
expect(dbm.database_filenames).to match_array([DEFAULT_CITY_DB_NAME, DEFAULT_ASN_DB_NAME, | ||
'GeoLite2-City.tgz', 'GeoLite2-ASN.tgz']) | ||
end | ||
end | ||
|
||
|
@@ -145,5 +155,6 @@ module LogStash module Filters module Geoip | |
expect(dbm.exist?).to be_truthy | ||
end | ||
end | ||
|
||
end | ||
end end end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,12 @@ module LogStash module Filters module Geoip | |
end | ||
let(:logger) { double("Logger") } | ||
|
||
GEOIP_STAGING_HOST = "https://geoip.elastic.dev" | ||
GEOIP_STAGING_ENDPOINT = "#{GEOIP_STAGING_HOST}#{LogStash::Filters::Geoip::DownloadManager::GEOIP_PATH}" | ||
|
||
before do | ||
stub_const('LogStash::Filters::Geoip::DownloadManager::GEOIP_ENDPOINT', GEOIP_STAGING_ENDPOINT) | ||
end | ||
|
||
context "rest client" do | ||
it "can call endpoint" do | ||
|
@@ -32,7 +38,9 @@ module LogStash module Filters module Geoip | |
context "check update" do | ||
before(:each) do | ||
expect(download_manager).to receive(:get_uuid).and_return(SecureRandom.uuid) | ||
mock_resp = double("geoip_endpoint", :body => ::File.read(::File.expand_path("./fixtures/normal_resp.json", ::File.dirname(__FILE__))), :status => 200) | ||
mock_resp = double("geoip_endpoint", | ||
:body => ::File.read(::File.expand_path("./fixtures/normal_resp.json", ::File.dirname(__FILE__))), | ||
:status => 200) | ||
allow(download_manager).to receive_message_chain("rest_client.get").and_return(mock_resp) | ||
end | ||
|
||
|
@@ -50,7 +58,7 @@ module LogStash module Filters module Geoip | |
end | ||
|
||
it "should return false when md5 is the same" do | ||
expect(mock_metadata).to receive(:gz_md5).and_return("2449075797a3ecd7cd2d4ea9d01e6e8f") | ||
expect(mock_metadata).to receive(:gz_md5).and_return("89d225ac546310b1e7979502ac9ad11c") | ||
|
||
has_update, info = download_manager.send(:check_update) | ||
expect(has_update).to be_falsey | ||
|
@@ -75,7 +83,7 @@ module LogStash module Filters module Geoip | |
} | ||
end | ||
let(:md5_hash) { SecureRandom.hex } | ||
let(:filename) { "GeoLite2-City.mmdb.gz"} | ||
let(:filename) { "GeoLite2-City.tgz"} | ||
|
||
it "should raise error if md5 does not match" do | ||
allow(Down).to receive(:download) | ||
|
@@ -86,26 +94,38 @@ module LogStash module Filters module Geoip | |
expect(download_manager).to receive(:md5).and_return(md5_hash) | ||
|
||
path = download_manager.send(:download_database, db_info) | ||
expect(path).to match /GeoLite2-City_\d+\.mmdb\.gz/ | ||
expect(path).to match /GeoLite2-City_\d+\.tgz/ | ||
expect(::File.exist?(path)).to be_truthy | ||
::File.delete(path) if ::File.exist?(path) | ||
|
||
delete_file(path) | ||
end | ||
end | ||
|
||
context "unzip" do | ||
before(:each) do | ||
let(:copyright_path) { get_file_path('COPYRIGHT.txt') } | ||
let(:license_path) { get_file_path('LICENSE.txt') } | ||
let(:readme_path) { get_file_path('README.txt') } | ||
|
||
before do | ||
file_path = ::File.expand_path("./fixtures/sample", ::File.dirname(__FILE__)) | ||
::File.delete(file_path) if ::File.exist?(file_path) | ||
delete_file(file_path, copyright_path, license_path, readme_path) | ||
end | ||
|
||
it "gz file" do | ||
path = ::File.expand_path("./fixtures/sample.gz", ::File.dirname(__FILE__)) | ||
unzip_path = download_manager.send(:unzip, path) | ||
expect(::File.exist?(unzip_path)).to be_truthy | ||
it "should extract database and license related files" do | ||
path = ::File.expand_path("./fixtures/sample.tgz", ::File.dirname(__FILE__)) | ||
unzip_db_path = download_manager.send(:unzip, path) | ||
|
||
expect(unzip_db_path).to match /\.mmdb/ | ||
expect(::File.exist?(unzip_db_path)).to be_truthy | ||
expect(::File.exist?(copyright_path)).to be_truthy | ||
expect(::File.exist?(license_path)).to be_truthy | ||
expect(::File.exist?(readme_path)).to be_falsey | ||
|
||
delete_file(unzip_db_path, copyright_path, license_path) | ||
end | ||
end | ||
|
||
context "assert database" do | ||
xcontext "assert database" do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why are we skipping this group of assertions? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because we move the |
||
it "should raise error if file is invalid" do | ||
expect{ download_manager.send(:assert_database!, "Gemfile") }.to raise_error /failed to load database/ | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logstash-filter-geoip
rename the package toorg.logstash.filters.geoip
and is waiting to merge that cause the failure of CI. Once the plugin is published, CI should be green