summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Rakefile8
-rw-r--r--lib/bundler/ssl_certs/certificate_manager.rb41
-rw-r--r--spec/other/ssl_cert_spec.rb8
3 files changed, 57 insertions, 0 deletions
diff --git a/Rakefile b/Rakefile
index 5bc8e6de80..64ea17d1db 100644
--- a/Rakefile
+++ b/Rakefile
@@ -3,6 +3,7 @@ $:.unshift File.expand_path("../lib", __FILE__)
require 'rubygems'
require 'shellwords'
require 'benchmark'
+require 'bundler/ssl_certs/certificate_manager'
def safe_task(&block)
yield
@@ -223,3 +224,10 @@ task :build => ["man:clean", "man:build"]
task :release => ["man:clean", "man:build"]
task :default => :spec
+
+namespace :rubygems do
+ desc "Update bundler certificates to match those from rubygems"
+ task :update_certs => "spec:rubygems:clone_rubygems_master" do
+ CertificateManager.new.update!
+ end
+end
diff --git a/lib/bundler/ssl_certs/certificate_manager.rb b/lib/bundler/ssl_certs/certificate_manager.rb
new file mode 100644
index 0000000000..7485072292
--- /dev/null
+++ b/lib/bundler/ssl_certs/certificate_manager.rb
@@ -0,0 +1,41 @@
+class CertificateManager
+ BUNDLER_CERTIFICATES_PATH = "lib/bundler/ssl_certs/"
+ LOCAL_RUBYGEMS_PATH = "tmp/rubygems"
+ RUBYGEMS_CERTIFICATES_PATH = "#{File.join(LOCAL_RUBYGEMS_PATH, 'lib/rubygems/ssl_certs/')}"
+ CERTIFICATE_FILE_EXTENSION = ".pem"
+
+ attr_reader :bundler_certificates, :rubygems_certificates
+
+ def initialize
+ @bundler_certificates = certificate_files(BUNDLER_CERTIFICATES_PATH)
+ @rubygems_certificates = certificate_files(RUBYGEMS_CERTIFICATES_PATH)
+ end
+
+ def up_to_date?
+ same_filenames = (bundler_certificates == rubygems_certificates)
+ same_certificates = false
+
+ if same_filenames
+ same_certificates = bundler_certificates.all? do |filename|
+ FileUtils.compare_file(File.join(BUNDLER_CERTIFICATES_PATH, filename), File.join(RUBYGEMS_CERTIFICATES_PATH, filename))
+ end
+ end
+
+ same_filenames && same_certificates
+ end
+
+ def update!
+ unless up_to_date?
+ FileUtils.rm Dir.glob(File.join(BUNDLER_CERTIFICATES_PATH, "*#{CERTIFICATE_FILE_EXTENSION}"))
+ FileUtils.cp_r Dir.glob(File.join(RUBYGEMS_CERTIFICATES_PATH, "*#{CERTIFICATE_FILE_EXTENSION}")), BUNDLER_CERTIFICATES_PATH
+ end
+ end
+
+ private
+
+ def certificate_files(path)
+ Dir.entries(path).select do |filename|
+ filename.end_with?(CERTIFICATE_FILE_EXTENSION)
+ end.sort
+ end
+end
diff --git a/spec/other/ssl_cert_spec.rb b/spec/other/ssl_cert_spec.rb
new file mode 100644
index 0000000000..14b5af2062
--- /dev/null
+++ b/spec/other/ssl_cert_spec.rb
@@ -0,0 +1,8 @@
+require_relative '../../lib/bundler/ssl_certs/certificate_manager'
+
+describe "SSL Certificates" do
+ it "are up to date with Rubygems" do
+ manager = CertificateManager.new
+ expect(manager).to be_up_to_date
+ end
+end