-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
require 'spec_helper' | ||
require 'ronin/nmap' | ||
|
||
RSpec.describe Ronin::Nmap do | ||
describe '.scan' do | ||
let(:targets) { '192.168.1.*' } | ||
|
||
context 'if tartets is empty' do | ||
it 'must raise an ArgumentError' do | ||
expect { | ||
subject.scan | ||
}.to raise_error(ArgumentError, 'must specify at least one target') | ||
end | ||
end | ||
|
||
context 'if sudo is not a Hash, true, false, nor nil' do | ||
it 'must raise an ArgumentError' do | ||
expect { | ||
subject.scan(targets, sudo: 'sudo') | ||
}.to raise_error(ArgumentError, 'sudo keyword must be a Hash, true, false, or nil') | ||
end | ||
end | ||
|
||
context 'when nmap command was successfull' do | ||
let(:expected_output_filename) { %r{#{Ronin::Nmap::CACHE_DIR}\/nmap[^.]+\.xml} } | ||
|
||
before do | ||
allow(Kernel).to receive(:system).with({}, 'nmap', '-oX', match(expected_output_filename), targets).and_return(true) | ||
end | ||
|
||
it 'must return false' do | ||
expect(subject.scan(targets).class).to be(Nmap::XML) | ||
end | ||
end | ||
|
||
context 'when nmap command fails' do | ||
before do | ||
allow(Kernel).to receive(:system).with({}, 'nmap', '-oX', anything, targets).and_return(false) | ||
end | ||
|
||
it 'must return false' do | ||
expect(subject.scan(targets)).to be(false) | ||
end | ||
end | ||
|
||
context 'when nmap command is not installed' do | ||
before do | ||
allow(Kernel).to receive(:system).with({}, 'nmap', '-oX', anything, targets).and_return(nil) | ||
end | ||
|
||
it 'must return nil' do | ||
expect(subject.scan(targets)).to be(nil) | ||
end | ||
end | ||
end | ||
end |