Skip to content

Commit 7f90b68

Browse files
committed
Add rspec coverage for get (and set/setg, in a way)
1 parent da1c56a commit 7f90b68

File tree

1 file changed

+44
-6
lines changed

1 file changed

+44
-6
lines changed

spec/lib/msf/ui/console/command_dispatcher/core_spec.rb

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,51 @@ def cell(table, row, column)
106106
@output.join.should =~ /Usage: get /
107107
end
108108
end
109-
end
110109

111-
describe "#cmd_getg" do
112-
describe "without arguments" do
113-
it "should show a help message" do
114-
core.cmd_getg
115-
@output.join.should =~ /Usage: getg /
110+
describe "with arguments" do
111+
let(:name) { ::Rex::Text.rand_text_alpha(10).upcase }
112+
113+
context "with an active module" do
114+
let(:mod) do
115+
mod = ::Msf::Module.new
116+
mod.send(:initialize, {})
117+
mod
118+
end
119+
120+
it "should show an empty value if not set in the framework or module" do
121+
allow(core).to receive(:active_module).and_return(mod)
122+
allow(driver).to receive(:on_variable_set).and_return(true)
123+
core.cmd_get(name)
124+
@output.join.should =~ /^#{name} => $/
125+
end
126+
127+
it "should show no value when only the framework has this variable" do
128+
allow(core).to receive(:active_module).and_return(mod)
129+
allow(driver).to receive(:on_variable_set).and_return(true)
130+
core.cmd_setg(name, 'FRAMEWORK')
131+
@output = []
132+
core.cmd_get(name)
133+
@output.join.should =~ /^#{name} => $/
134+
end
135+
136+
it "should show the module's value when only the module has this variable" do
137+
allow(core).to receive(:active_module).and_return(mod)
138+
allow(driver).to receive(:on_variable_set).and_return(true)
139+
core.cmd_set(name, 'MODULE')
140+
@output = []
141+
core.cmd_get(name)
142+
@output.join.should =~ /^#{name} => MODULE$/
143+
end
144+
145+
it "should show the module's value when both the module and the framework have this variable" do
146+
allow(core).to receive(:active_module).and_return(mod)
147+
allow(driver).to receive(:on_variable_set).and_return(true)
148+
core.cmd_setg(name, 'FRAMEWORK')
149+
core.cmd_set(name, 'MODULE')
150+
@output = []
151+
core.cmd_get(name)
152+
@output.join.should =~ /^#{name} => MODULE$/
153+
end
116154
end
117155
end
118156
end

0 commit comments

Comments
 (0)