Skip to content

Commit

Permalink
Validate arguments to msfupdate before updating
Browse files Browse the repository at this point in the history
  • Loading branch information
bturner-r7 committed Nov 15, 2013
1 parent 730edc4 commit 823aa3a
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 0 deletions.
23 changes: 23 additions & 0 deletions msfupdate
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 "[*]"
Expand Down
96 changes: 96 additions & 0 deletions spec/msfupdate_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,57 @@ def dummy_apt_pathname
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 }

its(:apt?) { should == true }
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!)
Expand Down Expand Up @@ -200,6 +244,32 @@ def dummy_apt_pathname
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!)
Expand Down Expand Up @@ -227,6 +297,32 @@ def dummy_apt_pathname
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!)
Expand Down

0 comments on commit 823aa3a

Please sign in to comment.