Skip to content

Commit 6cdfd32

Browse files
committed
change should to expect
1 parent e6f7b35 commit 6cdfd32

File tree

1 file changed

+77
-5
lines changed

1 file changed

+77
-5
lines changed

spec/lib/metasploit/framework/login_scanner/glassfish_spec.rb

Lines changed: 77 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,11 @@
142142
end
143143

144144
it 'returns status Metasploit::Model::Login::Status::SUCCESSFUL for a valid credential' do
145-
http_scanner.try_glassfish_2(cred)[:status].should eq(Metasploit::Model::Login::Status::SUCCESSFUL)
145+
expect(http_scanner.try_glassfish_2(cred)[:status]).to eq(Metasploit::Model::Login::Status::SUCCESSFUL)
146146
end
147147

148148
it 'returns Metasploit::Model::Login::Status::INCORRECT for an invalid credential' do
149-
http_scanner.try_glassfish_2(bad_cred)[:status].should eq(Metasploit::Model::Login::Status::INCORRECT)
149+
expect(http_scanner.try_glassfish_2(bad_cred)[:status]).to eq(Metasploit::Model::Login::Status::INCORRECT)
150150
end
151151
end
152152

@@ -188,15 +188,15 @@
188188
end
189189

190190
it 'returns status Metasploit::Model::Login::Status::SUCCESSFUL for a valid credential' do
191-
http_scanner.try_glassfish_3(cred)[:status].should eq(Metasploit::Model::Login::Status::SUCCESSFUL)
191+
expect(http_scanner.try_glassfish_3(cred)[:status]).to eq(Metasploit::Model::Login::Status::SUCCESSFUL)
192192
end
193193

194194
it 'returns status Metasploit::Model::Login::Status::SUCCESSFUL based on a disabled remote admin message' do
195-
http_scanner.try_glassfish_3(disabled_cred)[:status].should eq(Metasploit::Model::Login::Status::SUCCESSFUL)
195+
expect(http_scanner.try_glassfish_3(disabled_cred)[:status]).to eq(Metasploit::Model::Login::Status::SUCCESSFUL)
196196
end
197197

198198
it 'returns status Metasploit::Model::Login::Status::INCORRECT for an invalid credential' do
199-
http_scanner.try_glassfish_3(bad_cred)[:status].should eq(Metasploit::Model::Login::Status::INCORRECT)
199+
expect(http_scanner.try_glassfish_3(bad_cred)[:status]).to eq(Metasploit::Model::Login::Status::INCORRECT)
200200
end
201201
end
202202

@@ -229,6 +229,78 @@
229229
end
230230
end
231231

232+
context 'when Glassfish version 2' do
233+
let(:login_ok_message) do
234+
'<title>Deploy Enterprise Applications/Modules</title>'
235+
end
236+
237+
it 'returns a Metasploit::Framework::LoginScanner::Result' do
238+
allow_any_instance_of(Rex::Proto::Http::Client).to receive(:send_recv) do |cli, req|
239+
if req.opts['uri'] && req.opts['uri'].include?('j_security_check') &&
240+
req.opts['data'] &&
241+
req.opts['data'].include?("j_username=#{username}") &&
242+
req. opts['data'].include?("j_password=#{password}")
243+
res = Rex::Proto::Http::Response.new(302)
244+
res.headers['Location'] = '/applications/upload.jsf'
245+
res.headers['Set-Cookie'] = 'JSESSIONID=GOODSESSIONID'
246+
res
247+
elsif req.opts['uri'] && req.opts['uri'].include?('j_security_check')
248+
res = Rex::Proto::Http::Response.new(200)
249+
res.body = 'bad login'
250+
elsif req.opts['uri'] &&
251+
req.opts['uri'].include?('/applications/upload.jsf')
252+
res = Rex::Proto::Http::Response.new(200)
253+
res.body = '<title>Deploy Enterprise Applications/Modules</title>'
254+
else
255+
res = Rex::Proto::Http::Response.new(404)
256+
end
257+
258+
res
259+
end
260+
261+
expect(http_scanner.attempt_login(cred)).to be_kind_of(Metasploit::Framework::LoginScanner::Result)
262+
end
263+
end
264+
265+
context 'when Glassfish version 3' do
266+
let(:login_ok_message) do
267+
'<title>Deploy Enterprise Applications/Modules</title>'
268+
end
269+
270+
271+
it 'returns a Metasploit::Framework::LoginScanner::Result' do
272+
allow_any_instance_of(Rex::Proto::Http::Client).to receive(:send_recv) do |cli, req|
273+
if req.opts['uri'] && req.opts['uri'].include?('j_security_check') &&
274+
req.opts['data'] &&
275+
req.opts['data'].include?("j_username=#{username}") &&
276+
req. opts['data'].include?("j_password=#{password}")
277+
res = Rex::Proto::Http::Response.new(302)
278+
res.headers['Location'] = '/common/applications/uploadFrame.jsf'
279+
res.headers['Set-Cookie'] = 'JSESSIONID=GOODSESSIONID'
280+
res
281+
elsif req.opts['uri'] && req.opts['uri'].include?('j_security_check') &&
282+
req.opts['data'] &&
283+
req.opts['data'].include?("j_username=#{username_disabled}") &&
284+
req. opts['data'].include?("j_password=#{password_disabled}")
285+
res = Rex::Proto::Http::Response.new(200)
286+
res.body = 'Secure Admin must be enabled'
287+
elsif req.opts['uri'] && req.opts['uri'].include?('j_security_check')
288+
res = Rex::Proto::Http::Response.new(200)
289+
res.body = 'bad login'
290+
elsif req.opts['uri'] &&
291+
req.opts['uri'].include?('/common/applications/uploadFrame.jsf')
292+
res = Rex::Proto::Http::Response.new(200)
293+
res.body = '<title>Deploy Applications or Modules'
294+
else
295+
res = Rex::Proto::Http::Response.new(404)
296+
end
297+
298+
res
299+
end
300+
301+
expect(http_scanner.attempt_login(cred)).to be_kind_of(Metasploit::Framework::LoginScanner::Result)
302+
end
303+
end
232304
end
233305

234306
end

0 commit comments

Comments
 (0)