diff --git a/lib/solr_wrapper/checksum_validator.rb b/lib/solr_wrapper/checksum_validator.rb index 49a020f..5b34f4b 100644 --- a/lib/solr_wrapper/checksum_validator.rb +++ b/lib/solr_wrapper/checksum_validator.rb @@ -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 diff --git a/spec/lib/solr_wrapper/checksum_validator_spec.rb b/spec/lib/solr_wrapper/checksum_validator_spec.rb new file mode 100644 index 0000000..cc74b8c --- /dev/null +++ b/spec/lib/solr_wrapper/checksum_validator_spec.rb @@ -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