@@ -117,7 +117,7 @@ def cell(table, row, column)
117
117
mod
118
118
end
119
119
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
121
121
allow ( core ) . to receive ( :active_module ) . and_return ( mod )
122
122
allow ( driver ) . to receive ( :on_variable_set ) . and_return ( true )
123
123
core . cmd_get ( name )
@@ -154,4 +154,60 @@ def cell(table, row, column)
154
154
end
155
155
end
156
156
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
157
213
end
0 commit comments