Validate arguments to msfupdate before updating

bug/bundler_fix
Brandon Turner 2013-11-15 16:55:53 -06:00
parent 730edc4bf5
commit 823aa3a6f7
2 changed files with 119 additions and 0 deletions

View File

@ -82,6 +82,27 @@ Options:
end
end
def validate_args
valid = true
if binary_install? || apt?
if @git_branch
stderr.puts "[-] git-branch is not supported on this installation"
valid = false
end
if @git_remote
stderr.puts "[-] git-remote is not supported on this installation"
valid = false
end
end
if apt? || git?
if @offline_file
stderr.puts "[-] offline-file option is not supported on this installations"
valid = false
end
end
valid
end
def apt?
File.exists?(File.expand_path(File.join(@msfbase_dir, '.apt')))
end
@ -96,6 +117,8 @@ Options:
end
def run!
validate_args || maybe_wait_and_exit(0x13)
stderr.puts "[*]"
stderr.puts "[*] Attempting to update the Metasploit Framework..."
stderr.puts "[*]"

View File

@ -166,6 +166,24 @@ describe Msfupdate do
end
end
context "#run!" do
before(:each) do
subject.parse_args(args)
end
let(:args) { [] }
it "calls validate_args" do
subject.should_receive(:validate_args) { true }
subject.run!
end
it "exits if arguments are invalid" do
subject.stub(:validate_args) { false }
subject.should_receive(:maybe_wait_and_exit).and_raise(SystemExit)
expect { subject.run! }.to raise_error(SystemExit)
end
end
context "in an apt installation" do
let(:msfbase_dir) { dummy_apt_pathname }
@ -173,6 +191,32 @@ describe Msfupdate do
its(:binary_install?) { should == false }
its(:git?) { should == false }
context "#validate_args" do
before(:each) do
subject.parse_args(args)
end
context "with no args" do
let(:args) { [] }
its(:validate_args) { should == true }
end
context "with --git-remote" do
let(:args) { ['--git-remote', 'foo'] }
its(:validate_args) { should == false }
end
context "with --git-branch" do
let(:args) { ['--git-branch', 'foo'] }
its(:validate_args) { should == false }
end
context "with --offline-file" do
let(:args) { ['--offline-file', 'foo'] }
its(:validate_args) { should == false }
end
end
context "#run!" do
it "calls update_apt!" do
subject.should_receive(:update_apt!)
@ -200,6 +244,32 @@ describe Msfupdate do
its(:binary_install?) { should == true }
its(:git?) { should == false }
context "#validate_args" do
before(:each) do
subject.parse_args(args)
end
context "with no args" do
let(:args) { [] }
its(:validate_args) { should == true }
end
context "with --git-remote" do
let(:args) { ['--git-remote', 'foo'] }
its(:validate_args) { should == false }
end
context "with --git-branch" do
let(:args) { ['--git-branch', 'foo'] }
its(:validate_args) { should == false }
end
context "with --offline-file" do
let(:args) { ['--offline-file', 'foo'] }
its(:validate_args) { should == true }
end
end
context "#run!" do
it "does not call update_apt!" do
subject.should_not_receive(:update_apt!)
@ -227,6 +297,32 @@ describe Msfupdate do
its(:binary_install?) { should == false }
its(:git?) { should == true }
context "#validate_args" do
before(:each) do
subject.parse_args(args)
end
context "with no args" do
let(:args) { [] }
its(:validate_args) { should == true }
end
context "with --git-remote" do
let(:args) { ['--git-remote', 'foo'] }
its(:validate_args) { should == true }
end
context "with --git-branch" do
let(:args) { ['--git-branch', 'foo'] }
its(:validate_args) { should == true }
end
context "with --offline-file" do
let(:args) { ['--offline-file', 'foo'] }
its(:validate_args) { should == false }
end
end
context "#run!" do
it "does not call update_apt!" do
subject.should_not_receive(:update_apt!)