Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

[CompactIndex] Disable when openssl is in fips mode #5222

Merged
merged 2 commits into from
Dec 15, 2016
Merged
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
16 changes: 14 additions & 2 deletions lib/bundler/fetcher/compact_index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
require "bundler/worker"

module Bundler
autoload :CompactIndexClient, "bundler/compact_index_client"

class Fetcher
class CompactIndex < Base
require "bundler/compact_index_client"

def self.compact_index_request(method_name)
method = instance_method(method_name)
undef_method(method_name)
Expand Down Expand Up @@ -61,6 +61,7 @@ def fetch_spec(spec)
compact_index_request :fetch_spec

def available?
return nil unless md5_available?
user_home = Bundler.user_home
return nil unless user_home.directory? && user_home.writable?
# Read info file checksums out of /versions, so we can know if gems are up to date
Expand Down Expand Up @@ -119,6 +120,17 @@ def call(path, headers)
Net::HTTPNotModified.new(nil, nil, nil)
end
end

def md5_available?
begin
require "openssl"
return false if defined?(OpenSSL::OPENSSL_FIPS) && OpenSSL::OPENSSL_FIPS
rescue LoadError
nil

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to return false in both cases for consistency?

end

true
end
end
end
end
16 changes: 16 additions & 0 deletions spec/bundler/fetcher/compact_index_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,22 @@
compact_index.specs_for_names(["lskdjf"])
end

describe "#available?" do
context "when OpenSSL is in FIPS mode", :ruby => ">= 2.0.0" do
before { stub_const("OpenSSL::OPENSSL_FIPS", true) }

it "returns false" do
expect(compact_index).to_not be_available
end

it "never requires digest/md5" do
expect(Kernel).to receive(:require).with("digest/md5").never

compact_index.available?
end
end
end

context "logging" do
before { allow(compact_index).to receive(:log_specs).and_call_original }

Expand Down