summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWill Jordan <will@code.org>2017-02-17 07:16:58 -0800
committerWill Jordan <will@code.org>2017-02-17 07:16:58 -0800
commit9c389ff678dee6f4801845a1c82884d31b3499be (patch)
tree620c9ab1a48da1b311cef493c6ee96e88cdacbcf
parent873bac15ae7ddb3032114fb61587314840444ba3 (diff)
downloadbundler-9c389ff678dee6f4801845a1c82884d31b3499be.tar.gz
simplify `md5_available?` test using `OpenSSL::Digest:MD5.digest`
-rw-r--r--lib/bundler/fetcher/compact_index.rb25
-rw-r--r--spec/bundler/fetcher/compact_index_spec.rb22
2 files changed, 17 insertions, 30 deletions
diff --git a/lib/bundler/fetcher/compact_index.rb b/lib/bundler/fetcher/compact_index.rb
index 896f69592e..97de88101b 100644
--- a/lib/bundler/fetcher/compact_index.rb
+++ b/lib/bundler/fetcher/compact_index.rb
@@ -122,24 +122,13 @@ module Bundler
end
def md5_available?
- return true unless fips_enabled? && Process.respond_to?(:fork)
- pid = fork do
- $stderr.reopen(File.new("/dev/null", "w"))
- require "digest/md5"
- Digest::MD5.new
- exit
- end
- Process.wait pid
- $?.success?
- end
-
- def fips_enabled?
- begin
- require "openssl"
- rescue LoadError
- nil
- end
- defined?(OpenSSL::OPENSSL_FIPS) && OpenSSL::OPENSSL_FIPS
+ require "openssl"
+ OpenSSL::Digest::MD5.digest("")
+ true
+ rescue LoadError
+ true
+ rescue OpenSSL::Digest::DigestError
+ false
end
end
end
diff --git a/spec/bundler/fetcher/compact_index_spec.rb b/spec/bundler/fetcher/compact_index_spec.rb
index 7888dbf1bd..b0a23cd5a5 100644
--- a/spec/bundler/fetcher/compact_index_spec.rb
+++ b/spec/bundler/fetcher/compact_index_spec.rb
@@ -35,9 +35,14 @@ RSpec.describe Bundler::Fetcher::CompactIndex do
expect(compact_index).to be_available
end
- it "does not fork" do
- expect(compact_index).to receive(:fork).never
- compact_index.available?
+ context "when OpenSSL is not available" do
+ before do
+ allow(compact_index).to receive(:require).with("openssl").and_raise(LoadError)
+ end
+
+ it "returns true" do
+ expect(compact_index).to be_available
+ end
end
context "when OpenSSL is FIPS-enabled", :ruby => ">= 2.0.0" do
@@ -45,6 +50,8 @@ RSpec.describe Bundler::Fetcher::CompactIndex do
context "when FIPS-mode is active" do
before do
+ allow(OpenSSL::Digest::MD5).to receive(:digest).
+ and_raise(OpenSSL::Digest::DigestError)
allow(Digest::MD5).to receive(:new) do
# OpenSSL writes to STDERR and kills the current process with SIGABRT
# when FIPS mode prevents MD5 from being used.
@@ -56,20 +63,11 @@ RSpec.describe Bundler::Fetcher::CompactIndex do
it "returns false" do
expect(compact_index).to_not be_available
end
-
- it "outputs nothing to stderr" do
- expect { compact_index.available? }.to_not output.to_stderr_from_any_process
- end
end
it "returns true" do
expect(compact_index).to be_available
end
-
- it "does fork" do
- expect(compact_index).to receive(:fork).and_call_original
- compact_index.available?
- end
end
end