Skip to content

Commit 78ec4c9

Browse files
committed
Completed rspec
1 parent ee27643 commit 78ec4c9

File tree

1 file changed

+32
-4
lines changed

1 file changed

+32
-4
lines changed

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

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,28 @@
1010
'PHPSESSID=FAKESESSIONID;'
1111
end
1212

13+
let(:username) do
14+
'username'
15+
end
16+
17+
let(:good_password) do
18+
'good_password'
19+
end
20+
21+
let(:bad_password) do
22+
'bad_password'
23+
end
24+
1325
let(:successful_auth_response) do
1426
res = Rex::Proto::Http::Response.new(200, 'OK')
1527
res.headers['Location'] = 'executive_summary.php'
16-
res.headers['Set-Cookie'] = 'PHPSESSID=NEWSESSIONID'
28+
res.headers['Set-Cookie'] = 'PHPSESSID=NEWSESSIONID;'
1729
res
1830
end
1931

2032
let(:fail_auth_response) do
2133
res = Rex::Proto::Http::Response.new(200, 'OK')
22-
res.headers['Set-Cookie'] = 'PHPSESSID=NEWSESSIONID'
34+
res.headers['Set-Cookie'] = 'PHPSESSID=NEWSESSIONID;'
2335
res
2436
end
2537

@@ -94,24 +106,40 @@ def mock_http_cli(res)
94106

95107
describe '#get_login_state' do
96108
context 'when the credential is valid' do
97-
it 'returns a hash indicating successful' do
109+
it 'returns a hash indicating a successful login' do
110+
mock_http_cli(successful_auth_response)
111+
successful_status = Metasploit::Model::Login::Status::SUCCESSFUL
112+
expect(subject.get_login_state(username, good_password)[:status]).to eq(successful_status)
98113
end
99114
end
100115

101116
context 'when the creential is invalid' do
102117
it 'returns a hash indicating an incorrect cred' do
118+
mock_http_cli(fail_auth_response)
119+
incorrect_status = Metasploit::Model::Login::Status::INCORRECT
120+
expect(subject.get_login_state(username, good_password)[:status]).to eq(incorrect_status)
103121
end
104122
end
105123
end
106124

107125
describe '#attempt_login' do
108126
context 'when the credential is valid' do
109-
it 'returns a Result object indicating successful' do
127+
it 'returns a Result object indicating a successful login' do
128+
cred_obj = Metasploit::Framework::Credential.new(public: username, private: good_password)
129+
mock_http_cli(successful_auth_response)
130+
result = subject.attempt_login(cred_obj)
131+
expect(result).to be_kind_of(::Metasploit::Framework::LoginScanner::Result)
132+
expect(result.status).to eq(Metasploit::Model::Login::Status::SUCCESSFUL)
110133
end
111134
end
112135

113136
context 'when the credential is invalid' do
114137
it 'returns a Result object indicating an incorrect cred' do
138+
cred_obj = Metasploit::Framework::Credential.new(public: username, private: bad_password)
139+
mock_http_cli(fail_auth_response)
140+
result = subject.attempt_login(cred_obj)
141+
expect(result).to be_kind_of(::Metasploit::Framework::LoginScanner::Result)
142+
expect(result.status).to eq(Metasploit::Model::Login::Status::INCORRECT)
115143
end
116144
end
117145
end

0 commit comments

Comments
 (0)