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

Encourage gem signing by adding the required fields in bundle gem #2401

Closed
wants to merge 2 commits into from
Closed
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Original file line Diff line number Diff line change
@@ -1,5 +1,9 @@
## 1.3.3 ## 1.3.3


Features:

- Encourage gem signing by adding the required fields in `bundle gem`

Bugfixes: Bugfixes:


- use YAML.dump over {}.to_yaml for better forwards compat - use YAML.dump over {}.to_yaml for better forwards compat
Expand Down
4 changes: 3 additions & 1 deletion lib/bundler/cli.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -688,7 +688,9 @@ def gem(name)
:constant_array => constant_array, :constant_array => constant_array,
:author => git_user_name.empty? ? "TODO: Write your name" : git_user_name, :author => git_user_name.empty? ? "TODO: Write your name" : git_user_name,
:email => git_user_email.empty? ? "TODO: Write your email address" : git_user_email, :email => git_user_email.empty? ? "TODO: Write your email address" : git_user_email,
:test => options[:test] :test => options[:test],
:cert_chain => "TODO: Path to your public key (a .pem file)",
:signing_key => "TODO: Path to your private key (a .pem file)",
} }
gemspec_dest = File.join(target, "#{name}.gemspec") gemspec_dest = File.join(target, "#{name}.gemspec")
template(File.join("newgem/Gemfile.tt"), File.join(target, "Gemfile"), opts) template(File.join("newgem/Gemfile.tt"), File.join(target, "Gemfile"), opts)
Expand Down
6 changes: 6 additions & 0 deletions lib/bundler/templates/newgem/newgem.gemspec.tt
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ Gem::Specification.new do |spec|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ["lib"] spec.require_paths = ["lib"]


# You can generate a key pair with `gem cert --build <%=config[:email]%>`
# Keep your signing_key secret - don't check it in!
# For more details, read http://docs.rubygems.org/read/chapter/21
spec.cert_chain = [<%=config[:cert_chain].inspect%>]
spec.signing_key = <%=config[:signing_key].inspect%>

spec.add_development_dependency "bundler", "~> <%= Bundler::VERSION.split(".")[0..1].join(".") %>" spec.add_development_dependency "bundler", "~> <%= Bundler::VERSION.split(".")[0..1].join(".") %>"
spec.add_development_dependency "rake" spec.add_development_dependency "rake"
<% if config[:test] -%> <% if config[:test] -%>
Expand Down
14 changes: 14 additions & 0 deletions spec/other/newgem_spec.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@
end end
end end


shared_examples_for "it is signed" do
it "should have a default cert chain" do
expect(generated_gem.gemspec.cert_chain.first).to eq("TODO: Path to your public key (a .pem file)")
end

it "should have a default signing key" do
expect(generated_gem.gemspec.signing_key).to eq("TODO: Path to your private key (a .pem file)")
end
end

context "gem naming with underscore" do context "gem naming with underscore" do
let(:gem_name) { 'test_gem' } let(:gem_name) { 'test_gem' }


Expand Down Expand Up @@ -86,6 +96,8 @@
expect(bundled_app("test_gem/lib/test_gem.rb").read).to match(/require "test_gem\/version"/) expect(bundled_app("test_gem/lib/test_gem.rb").read).to match(/require "test_gem\/version"/)
end end


it_should_behave_like "it is signed"

it "runs rake without problems" do it "runs rake without problems" do
system_gems ["rake-10.0.2"] system_gems ["rake-10.0.2"]


Expand Down Expand Up @@ -262,6 +274,8 @@
expect(bundled_app("test-gem/lib/test/gem.rb").read).to match(/require "test\/gem\/version"/) expect(bundled_app("test-gem/lib/test/gem.rb").read).to match(/require "test\/gem\/version"/)
end end


it_should_behave_like "it is signed"

it "runs rake without problems" do it "runs rake without problems" do
system_gems ["rake-10.0.2"] system_gems ["rake-10.0.2"]


Expand Down