summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThom May <thom@may.lt>2015-05-20 11:54:25 +0100
committerThom May <thom@may.lt>2015-05-20 11:54:25 +0100
commit7f0de95e21cdb92c37b431128c6548382375337a (patch)
tree8c1e3bcadf31e57f8b2df2754268015b909845b5
parentaa96bcb97bd6c5757ae48e861b0ad0811e76e543 (diff)
parentb5ae23df27d6dd2922d40309f6c1c23e97da4bb5 (diff)
downloadchef-7f0de95e21cdb92c37b431128c6548382375337a.tar.gz
Merge pull request #3325 from chef/ryan/validatorless_bootstrap
Enforce passing a node name with validatorless bootstrapping
-rw-r--r--lib/chef/knife/bootstrap.rb6
-rw-r--r--spec/unit/knife/bootstrap_spec.rb13
2 files changed, 19 insertions, 0 deletions
diff --git a/lib/chef/knife/bootstrap.rb b/lib/chef/knife/bootstrap.rb
index a4095e8402..5b29591fcc 100644
--- a/lib/chef/knife/bootstrap.rb
+++ b/lib/chef/knife/bootstrap.rb
@@ -316,6 +316,12 @@ class Chef
# new client-side hawtness, just delete your validation key.
if chef_vault_handler.doing_chef_vault? ||
(Chef::Config[:validation_key] && !File.exist?(File.expand_path(Chef::Config[:validation_key])))
+
+ unless config[:chef_node_name]
+ ui.error("You must pass a node name with -N when bootstrapping with user credentials")
+ exit 1
+ end
+
client_builder.run
chef_vault_handler.run(node_name: config[:chef_node_name])
diff --git a/spec/unit/knife/bootstrap_spec.rb b/spec/unit/knife/bootstrap_spec.rb
index f1ca510ed3..aaace60f6a 100644
--- a/spec/unit/knife/bootstrap_spec.rb
+++ b/spec/unit/knife/bootstrap_spec.rb
@@ -531,6 +531,7 @@ describe Chef::Knife::Bootstrap do
describe "when running the bootstrap" do
let(:knife_ssh) do
knife.name_args = ["foo.example.com"]
+ knife.config[:chef_node_name] = "foo.example.com"
knife.config[:ssh_user] = "rooty"
knife.config[:identity_file] = "~/.ssh/me.rsa"
allow(knife).to receive(:render_template).and_return("")
@@ -590,6 +591,12 @@ describe Chef::Knife::Bootstrap do
expect(knife.chef_vault_handler).not_to receive(:run).with(node_name: knife.config[:chef_node_name])
knife.run
end
+
+ it "raises an exception if the config[:chef_node_name] is not present" do
+ knife.config[:chef_node_name] = nil
+
+ expect { knife.run }.to raise_error(SystemExit)
+ end
end
context "when the validation key is not present" do
@@ -604,6 +611,12 @@ describe Chef::Knife::Bootstrap do
expect(knife.chef_vault_handler).to receive(:run).with(node_name: knife.config[:chef_node_name])
knife.run
end
+
+ it "raises an exception if the config[:chef_node_name] is not present" do
+ knife.config[:chef_node_name] = nil
+
+ expect { knife.run }.to raise_error(SystemExit)
+ end
end
context "when the validation_key is nil" do