Skip to content

Commit

Permalink
Land #10692, Add rspec test for cmd_set_tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
wchen-r7 committed Sep 25, 2018
2 parents 2eb675e + b5df80d commit 427080a
Showing 1 changed file with 79 additions and 0 deletions.
79 changes: 79 additions & 0 deletions spec/lib/msf/ui/console/command_dispatcher/core_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require 'msf/ui'
require 'msf/ui/console/module_command_dispatcher'
require 'msf/ui/console/command_dispatcher/core'
require 'readline'

RSpec.describe Msf::Ui::Console::CommandDispatcher::Core do
include_context 'Msf::DBManager'
Expand All @@ -14,6 +15,8 @@

it { is_expected.to respond_to :cmd_get }
it { is_expected.to respond_to :cmd_getg }
it { is_expected.to respond_to :cmd_set_tabs }
it { is_expected.to respond_to :cmd_setg_tabs }

def set_and_test_variable(name, framework_value, module_value, framework_re, module_re)
# set the current module
Expand Down Expand Up @@ -80,4 +83,80 @@ def set_and_test_variable(name, framework_value, module_value, framework_re, mod
end
end
end


def set_tabs_test(option)
allow(core).to receive(:active_module).and_return(mod)
# always assume set variables validate (largely irrelevant because ours are random)
allow(driver).to receive(:on_variable_set).and_return(true)

double = double('framework')
allow(double).to receive(:get).and_return(nil)
allow(double).to receive(:sessions).and_return([])
allow_any_instance_of(Msf::Post).to receive(:framework).and_return(double)

# Test for setting uncomplete option
output = core.cmd_set_tabs(option, ["set"])
expect(output).to be_kind_of(Array).or eq(nil)

# Test for setting option
output = core.cmd_set_tabs("", ["set", option])
expect(output).to be_kind_of(Array).or eq(nil)
end

describe "#cmd_set_tabs" do
# The options of all kinds of modules.
all_options = ::Msf::Exploit.new.datastore.keys +
::Msf::Post.new.datastore.keys +
::Msf::Auxiliary.new.datastore.keys
all_options.uniq!

context "with a Exploit active module" do
let(:mod) do
mod = ::Msf::Exploit.new
mod.send(:initialize, {})
mod
end

all_options.each do |option|
describe "with #{option} arguments" do
it "should return array or nil" do
set_tabs_test(option)
end
end
end
end

context "with a Post active module" do
let(:mod) do
mod = ::Msf::Post.new
mod.send(:initialize, {})
mod
end

all_options.each do |option|
describe "with #{option} arguments" do
it "should return array or nil" do
set_tabs_test(option)
end
end
end
end

context "with a Auxiliary active module" do
let(:mod) do
mod = ::Msf::Auxiliary.new
mod.send(:initialize, {})
mod
end

all_options.each do |option|
describe "with #{option} arguments" do
it "should return array or nil" do
set_tabs_test(option)
end
end
end
end
end
end

0 comments on commit 427080a

Please sign in to comment.