From 145f04893cbe07ffbee472aadd8641843213ff9c Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Thu, 7 Nov 2019 10:15:03 -0800 Subject: [PATCH] Fixes #11137: Fixup how cloud publish handles its arguments Prior to this commit, if a user didn't supply a box file on disk or a box url, Vagrant would crash and display a stacktrace with an invalid file. This commit fixes that by adding some extra handling around the arguments supplied to the publish command. --- plugins/commands/cloud/publish.rb | 2 +- test/unit/plugins/commands/cloud/publish_test.rb | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/plugins/commands/cloud/publish.rb b/plugins/commands/cloud/publish.rb index 632786e88..d8b44a22b 100644 --- a/plugins/commands/cloud/publish.rb +++ b/plugins/commands/cloud/publish.rb @@ -55,7 +55,7 @@ module VagrantPlugins argv = parse_options(opts) return if !argv - if argv.empty? || argv.length > 4 || argv.length < 3 + if argv.empty? || argv.length > 4 || argv.length < 3 || (argv.length == 3 && !options[:url]) raise Vagrant::Errors::CLIInvalidUsage, help: opts.help.chomp end diff --git a/test/unit/plugins/commands/cloud/publish_test.rb b/test/unit/plugins/commands/cloud/publish_test.rb index 074b4ce63..45d375335 100644 --- a/test/unit/plugins/commands/cloud/publish_test.rb +++ b/test/unit/plugins/commands/cloud/publish_test.rb @@ -52,6 +52,15 @@ describe VagrantPlugins::CloudCommand::Command::Publish do let(:argv) { ["vagrant/box", "1.0.0", "virtualbox"] } it "shows help" do + expect { subject.execute }. + to raise_error(Vagrant::Errors::CLIInvalidUsage) + end + end + + context "missing box file" do + let(:argv) { ["vagrant/box", "1.0.0", "virtualbox", "/notreal/file.box"] } + + it "raises an exception" do allow(File).to receive(:file?).and_return(false) expect { subject.execute }. to raise_error(Vagrant::Errors::BoxFileNotExist)