Simplify get/getg rspec
parent
c6121f0a37
commit
e7566944df
|
@ -99,65 +99,37 @@ describe Msf::Ui::Console::CommandDispatcher::Core do
|
|||
it { is_expected.to respond_to :cmd_get }
|
||||
it { is_expected.to respond_to :cmd_getg }
|
||||
|
||||
describe "#cmd_get" do
|
||||
describe "without arguments" do
|
||||
it "should show a help message" do
|
||||
core.cmd_get
|
||||
@output.join.should =~ /Usage: get /
|
||||
end
|
||||
def set_and_test_variable(name, framework_value, module_value, framework_re, module_re)
|
||||
# set the current module
|
||||
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)
|
||||
# the specified global value
|
||||
core.cmd_setg(name, framework_value) if framework_value
|
||||
# set the specified local value
|
||||
core.cmd_set(name, module_value) if module_value
|
||||
|
||||
# test the global value if specified
|
||||
if framework_re
|
||||
@output = []
|
||||
core.cmd_getg(name)
|
||||
@output.join.should =~ framework_re
|
||||
end
|
||||
|
||||
describe "with arguments" do
|
||||
let(:name) { ::Rex::Text.rand_text_alpha(10).upcase }
|
||||
|
||||
context "with an active module" do
|
||||
let(:mod) do
|
||||
mod = ::Msf::Module.new
|
||||
mod.send(:initialize, {})
|
||||
mod
|
||||
end
|
||||
|
||||
it "should show no value if not set in the framework or module" do
|
||||
allow(core).to receive(:active_module).and_return(mod)
|
||||
allow(driver).to receive(:on_variable_set).and_return(true)
|
||||
core.cmd_get(name)
|
||||
@output.join.should =~ /^#{name} => $/
|
||||
end
|
||||
|
||||
it "should show no value when only the framework has this variable" do
|
||||
allow(core).to receive(:active_module).and_return(mod)
|
||||
allow(driver).to receive(:on_variable_set).and_return(true)
|
||||
core.cmd_setg(name, 'FRAMEWORK')
|
||||
@output = []
|
||||
core.cmd_get(name)
|
||||
@output.join.should =~ /^#{name} => $/
|
||||
end
|
||||
|
||||
it "should show the module's value when only the module has this variable" do
|
||||
allow(core).to receive(:active_module).and_return(mod)
|
||||
allow(driver).to receive(:on_variable_set).and_return(true)
|
||||
core.cmd_set(name, 'MODULE')
|
||||
@output = []
|
||||
core.cmd_get(name)
|
||||
@output.join.should =~ /^#{name} => MODULE$/
|
||||
end
|
||||
|
||||
it "should show the module's value when both the module and the framework have this variable" do
|
||||
allow(core).to receive(:active_module).and_return(mod)
|
||||
allow(driver).to receive(:on_variable_set).and_return(true)
|
||||
core.cmd_setg(name, 'FRAMEWORK')
|
||||
core.cmd_set(name, 'MODULE')
|
||||
@output = []
|
||||
core.cmd_get(name)
|
||||
@output.join.should =~ /^#{name} => MODULE$/
|
||||
end
|
||||
end
|
||||
# test the local value if specified
|
||||
if module_re
|
||||
@output = []
|
||||
core.cmd_get(name)
|
||||
@output.join.should =~ module_re
|
||||
end
|
||||
end
|
||||
|
||||
describe "#cmd_getg" do
|
||||
describe "#cmd_get and #cmd_getg" do
|
||||
describe "without arguments" do
|
||||
it "should show a help message" do
|
||||
it "should show the correct help message" do
|
||||
core.cmd_get
|
||||
@output.join.should =~ /Usage: get /
|
||||
@output = []
|
||||
core.cmd_getg
|
||||
@output.join.should =~ /Usage: getg /
|
||||
end
|
||||
|
@ -174,38 +146,19 @@ describe Msf::Ui::Console::CommandDispatcher::Core do
|
|||
end
|
||||
|
||||
it "should show no value if not set in the framework or module" do
|
||||
allow(core).to receive(:active_module).and_return(mod)
|
||||
allow(driver).to receive(:on_variable_set).and_return(true)
|
||||
core.cmd_getg(name)
|
||||
@output.join.should =~ /^#{name} => $/
|
||||
set_and_test_variable(name, nil, nil, /^#{name} => $/, /^#{name} => $/)
|
||||
end
|
||||
|
||||
it "should show no value when only the module has this variable" do
|
||||
allow(core).to receive(:active_module).and_return(mod)
|
||||
allow(driver).to receive(:on_variable_set).and_return(true)
|
||||
core.cmd_set(name, 'MODULE')
|
||||
@output = []
|
||||
core.cmd_getg(name)
|
||||
@output.join.should =~ /^#{name} => $/
|
||||
it "should show the correct value when only the module has this variable" do
|
||||
set_and_test_variable(name, nil, 'MODULE', /^#{name} => $/, /^#{name} => MODULE$/)
|
||||
end
|
||||
|
||||
it "should show the framework's value when only the framework has this variable" do
|
||||
allow(core).to receive(:active_module).and_return(mod)
|
||||
allow(driver).to receive(:on_variable_set).and_return(true)
|
||||
core.cmd_setg(name, 'FRAMEWORK')
|
||||
@output = []
|
||||
core.cmd_getg(name)
|
||||
@output.join.should =~ /^#{name} => FRAMEWORK$/
|
||||
it "should show the correct value when only the framework has this variable" do
|
||||
set_and_test_variable(name, 'FRAMEWORK', nil, /^#{name} => FRAMEWORK$/, /^#{name} => $/)
|
||||
end
|
||||
|
||||
it "should show the framework's value when both the module and the framework have this variable" do
|
||||
allow(core).to receive(:active_module).and_return(mod)
|
||||
allow(driver).to receive(:on_variable_set).and_return(true)
|
||||
core.cmd_setg(name, 'FRAMEWORK')
|
||||
core.cmd_set(name, 'MODULE')
|
||||
@output = []
|
||||
core.cmd_getg(name)
|
||||
@output.join.should =~ /^#{name} => FRAMEWORK$/
|
||||
it "should show the correct value when both the module and the framework have this variable" do
|
||||
set_and_test_variable(name, 'FRAMEWORK', 'MODULE', /^#{name} => FRAMEWORK$/, /^#{name} => MODULE$/)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue