Skip to content

Commit c6121f0

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

File tree

1 file changed

+57
-1
lines changed

1 file changed

+57
-1
lines changed

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

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def cell(table, row, column)
117117
mod
118118
end
119119

120-
it "should show an empty value if not set in the framework or module" do
120+
it "should show no value if not set in the framework or module" do
121121
allow(core).to receive(:active_module).and_return(mod)
122122
allow(driver).to receive(:on_variable_set).and_return(true)
123123
core.cmd_get(name)
@@ -154,4 +154,60 @@ def cell(table, row, column)
154154
end
155155
end
156156
end
157+
158+
describe "#cmd_getg" do
159+
describe "without arguments" do
160+
it "should show a help message" do
161+
core.cmd_getg
162+
@output.join.should =~ /Usage: getg /
163+
end
164+
end
165+
166+
describe "with arguments" do
167+
let(:name) { ::Rex::Text.rand_text_alpha(10).upcase }
168+
169+
context "with an active module" do
170+
let(:mod) do
171+
mod = ::Msf::Module.new
172+
mod.send(:initialize, {})
173+
mod
174+
end
175+
176+
it "should show no value if not set in the framework or module" do
177+
allow(core).to receive(:active_module).and_return(mod)
178+
allow(driver).to receive(:on_variable_set).and_return(true)
179+
core.cmd_getg(name)
180+
@output.join.should =~ /^#{name} => $/
181+
end
182+
183+
it "should show no value when only the module has this variable" do
184+
allow(core).to receive(:active_module).and_return(mod)
185+
allow(driver).to receive(:on_variable_set).and_return(true)
186+
core.cmd_set(name, 'MODULE')
187+
@output = []
188+
core.cmd_getg(name)
189+
@output.join.should =~ /^#{name} => $/
190+
end
191+
192+
it "should show the framework's value when only the framework has this variable" do
193+
allow(core).to receive(:active_module).and_return(mod)
194+
allow(driver).to receive(:on_variable_set).and_return(true)
195+
core.cmd_setg(name, 'FRAMEWORK')
196+
@output = []
197+
core.cmd_getg(name)
198+
@output.join.should =~ /^#{name} => FRAMEWORK$/
199+
end
200+
201+
it "should show the framework's value when both the module and the framework have this variable" do
202+
allow(core).to receive(:active_module).and_return(mod)
203+
allow(driver).to receive(:on_variable_set).and_return(true)
204+
core.cmd_setg(name, 'FRAMEWORK')
205+
core.cmd_set(name, 'MODULE')
206+
@output = []
207+
core.cmd_getg(name)
208+
@output.join.should =~ /^#{name} => FRAMEWORK$/
209+
end
210+
end
211+
end
212+
end
157213
end

0 commit comments

Comments
 (0)