start injecting sanity

bug/bundler_fix
David Maloney 2014-06-13 14:53:56 -05:00
parent a9bcb8b3bd
commit 7187138134
No known key found for this signature in database
GPG Key ID: DEDBA9DC3A913DB2
2 changed files with 26 additions and 9 deletions

View File

@ -81,7 +81,10 @@ module Metasploit
bin_path bin_path
end end
# This method runs the command from {#crack_command} and yields each line of output.
#
# @yield [String] a line of output from the john command
# @return [void]
def crack def crack
::IO.popen(crack_command, "rb") do |fd| ::IO.popen(crack_command, "rb") do |fd|
fd.each_line do |line| fd.each_line do |line|
@ -108,7 +111,7 @@ module Metasploit
if pot.present? if pot.present?
cmd << ( "--pot=" + pot ) cmd << ( "--pot=" + pot )
else else
cmd << ( "--pot" + john_pot_file) cmd << ( "--pot=" + john_pot_file)
end end
if format.present? if format.present?

View File

@ -6,25 +6,39 @@ describe Metasploit::Framework::JtR::Cracker do
subject(:cracker) { described_class.new } subject(:cracker) { described_class.new }
describe '#binary_path' do describe '#binary_path' do
let(:john_path) { '/path/to/john' }
let(:other_john_path) { '/path/to/other/john' }
context 'when the user supplied a john_path' do context 'when the user supplied a john_path' do
before(:each) do before(:each) do
cracker.john_path = '/path/to/john' cracker.john_path = john_path
end end
it 'returns the manual path if it exists and is a regular file' do it 'returns the manual path if it exists and is a regular file' do
expect(::File).to receive(:file?).with(cracker.john_path).at_least(:once).and_return true expect(::File).to receive(:file?).with(john_path).once.and_return true
expect(cracker.binary_path).to eq cracker.john_path expect(cracker.binary_path).to eq john_path
end end
it 'rejects the manual path if it does not exist or is not a regular file' do it 'rejects the manual path if it does not exist or is not a regular file' do
expect(cracker.binary_path).to_not eq cracker.john_path expect(::File).to receive(:file?).with(john_path).once.and_return false
expect(Rex::FileUtils).to receive(:find_full_path).with('john').and_return other_john_path
expect(::File).to receive(:file?).with(other_john_path).once.and_return true
expect(cracker.binary_path).to_not eq john_path
end end
end end
context 'when the user did not supply a path' do context 'when the user did not supply a path' do
it 'searches the Environment PATH' do it 'returns the john binary from the PATH if it exists' do
expect(Rex::FileUtils).to receive(:find_full_path).and_return __FILE__ expect(Rex::FileUtils).to receive(:find_full_path).and_return john_path
expect(cracker.binary_path).to eq __FILE__ expect(::File).to receive(:file?).with(john_path).once.and_return true
expect(cracker.binary_path).to eq john_path
end
it 'returns the shipped john binary if it does not exist in the PATH' do
expect(Rex::FileUtils).to receive(:find_full_path).twice.and_return nil
expect(::File).to receive(:file?).with(nil).once.and_return false
expect(cracker).to receive(:select_shipped_binary).and_return other_john_path
expect(cracker.binary_path).to eq other_john_path
end end
end end
end end