Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions lib/solr_wrapper/checksum_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,17 @@ def validate!(file)
private

def checksumurl(suffix)
if config.default_download_url == config.static_config.archive_download_url
"#{config.default_download_url}.#{suffix}"
if remote_checksum?(suffix)
config.checksum
else
"http://www.us.apache.org/dist/lucene/solr/#{config.static_config.version}/solr-#{config.static_config.version}.zip.#{suffix}"
"http://archive.apache.org/dist/lucene/solr/#{config.static_config.version}/solr-#{config.static_config.version}.zip.#{suffix}"
end
end

def remote_checksum?(alg)
config.checksum && config.checksum.match(/http.*#{alg}/, 0)
end

def checksum_path(suffix)
File.join(config.download_dir, File.basename(checksumurl(suffix)))
end
Expand Down
26 changes: 26 additions & 0 deletions spec/lib/solr_wrapper/checksum_validator_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require 'spec_helper'

RSpec.describe SolrWrapper::ChecksumValidator do
let(:validator) { described_class.new(settings) }
let(:settings) { SolrWrapper::Settings.new(config) }
let(:config) { SolrWrapper::Configuration.new(options) }

describe '#checksumurl' do
subject { validator.send(:checksumurl, described_class::ALGORITHM) }

context 'when the checksum option is not set' do
let(:options) { { version: '6.6.0'} }
it { is_expected.to eq 'http://archive.apache.org/dist/lucene/solr/6.6.0/solr-6.6.0.zip.sha1' }
end

context 'when the checksum option is not a URL' do
let(:options) { { version: '6.6.1', checksum: './just/a/path.sha1'} }
it { is_expected.to eq 'http://archive.apache.org/dist/lucene/solr/6.6.1/solr-6.6.1.zip.sha1' }
end

context 'when the checksum option is a URL' do
let(:options) { { version: '6.6.2', checksum: 'http://lib-solr-mirror.princeton.edu/dist/lucene/solr/6.6.2/solr-6.6.2.zip.sha1'} }
it { is_expected.to eq 'http://lib-solr-mirror.princeton.edu/dist/lucene/solr/6.6.2/solr-6.6.2.zip.sha1' }
end
end
end