39
39
described_class . new
40
40
end
41
41
42
- def mock_http_cli ( res )
43
- cli = Rex ::Proto ::Http ::Client
44
- allow ( cli ) . to receive ( :request_cgi ) . with ( any_args )
45
- allow ( cli ) . to receive ( :send_recv ) . with ( any_args ) . and_return ( res )
46
- allow ( cli ) . to receive ( :set_config ) . with ( any_args )
47
- allow ( cli ) . to receive ( :close )
48
- allow ( cli ) . to receive ( :connect )
49
- allow ( Rex ::Proto ::Http ::Client ) . to receive ( :new ) . and_return ( cli )
42
+ let ( :response ) do
43
+ Rex ::Proto ::Http ::Response . new ( 200 , 'OK' )
44
+ end
45
+
46
+ before ( :each ) do
47
+ allow_any_instance_of ( Rex ::Proto ::Http ::Client ) . to receive ( :request_cgi ) . with ( any_args )
48
+ allow_any_instance_of ( Rex ::Proto ::Http ::Client ) . to receive ( :send_recv ) . with ( any_args ) . and_return ( response )
49
+ allow_any_instance_of ( Rex ::Proto ::Http ::Client ) . to receive ( :set_config ) . with ( any_args )
50
+ allow_any_instance_of ( Rex ::Proto ::Http ::Client ) . to receive ( :close )
51
+ allow_any_instance_of ( Rex ::Proto ::Http ::Client ) . to receive ( :connect )
50
52
end
51
53
52
54
describe '#check_setup' do
@@ -56,20 +58,15 @@ def mock_http_cli(res)
56
58
res
57
59
end
58
60
59
- let ( :empty_html_response ) do
60
- Rex ::Proto ::Http ::Response . new ( 200 , 'OK' )
61
- end
62
-
63
61
context 'when target is Symantec Web Gateway' do
62
+ let ( :response ) { swg_html_response }
64
63
it 'returns true' do
65
- mock_http_cli ( swg_html_response )
66
64
expect ( subject . check_setup ) . to be_truthy
67
65
end
68
66
end
69
67
70
68
context 'when target is not Symantec Web Gateway' do
71
69
it 'returns false' do
72
- mock_http_cli ( empty_html_response )
73
70
expect ( subject . check_setup ) . to be_falsey
74
71
end
75
72
end
@@ -78,19 +75,21 @@ def mock_http_cli(res)
78
75
describe '#send_request' do
79
76
context 'when a valid request is sent' do
80
77
it 'returns a response object' do
81
- expected_response = Rex ::Proto ::Http ::Response . new ( 200 , 'OK' )
82
- mock_http_cli ( expected_response )
83
78
expect ( subject . send_request ( { 'uri' => '/' } ) ) . to be_kind_of ( Rex ::Proto ::Http ::Response )
84
79
end
85
80
end
86
81
end
87
82
88
83
describe '#get_last_sid' do
84
+ let ( :response ) do
85
+ res = Rex ::Proto ::Http ::Response . new ( 200 , 'OK' )
86
+ res . headers [ 'Set-Cookie' ] = session_id
87
+
88
+ res
89
+ end
90
+
89
91
context 'when there is no session ID' do
90
92
it 'returns a new session ID' do
91
- res = Rex ::Proto ::Http ::Response . new ( 200 , 'OK' )
92
- res . headers [ 'Set-Cookie' ] = session_id
93
- mock_http_cli ( res )
94
93
expect ( subject . get_last_sid ) . to include ( 'PHPSESSID' )
95
94
end
96
95
end
@@ -106,16 +105,16 @@ def mock_http_cli(res)
106
105
107
106
describe '#get_login_state' do
108
107
context 'when the credential is valid' do
108
+ let ( :response ) { successful_auth_response }
109
109
it 'returns a hash indicating a successful login' do
110
- mock_http_cli ( successful_auth_response )
111
110
successful_status = Metasploit ::Model ::Login ::Status ::SUCCESSFUL
112
111
expect ( subject . get_login_state ( username , good_password ) [ :status ] ) . to eq ( successful_status )
113
112
end
114
113
end
115
114
116
115
context 'when the creential is invalid' do
116
+ let ( :response ) { fail_auth_response }
117
117
it 'returns a hash indicating an incorrect cred' do
118
- mock_http_cli ( fail_auth_response )
119
118
incorrect_status = Metasploit ::Model ::Login ::Status ::INCORRECT
120
119
expect ( subject . get_login_state ( username , good_password ) [ :status ] ) . to eq ( incorrect_status )
121
120
end
@@ -124,19 +123,20 @@ def mock_http_cli(res)
124
123
125
124
describe '#attempt_login' do
126
125
context 'when the credential is valid' do
126
+ let ( :response ) { successful_auth_response }
127
+
127
128
it 'returns a Result object indicating a successful login' do
128
129
cred_obj = Metasploit ::Framework ::Credential . new ( public : username , private : good_password )
129
- mock_http_cli ( successful_auth_response )
130
130
result = subject . attempt_login ( cred_obj )
131
131
expect ( result ) . to be_kind_of ( ::Metasploit ::Framework ::LoginScanner ::Result )
132
132
expect ( result . status ) . to eq ( Metasploit ::Model ::Login ::Status ::SUCCESSFUL )
133
133
end
134
134
end
135
135
136
136
context 'when the credential is invalid' do
137
+ let ( :response ) { fail_auth_response }
137
138
it 'returns a Result object indicating an incorrect cred' do
138
139
cred_obj = Metasploit ::Framework ::Credential . new ( public : username , private : bad_password )
139
- mock_http_cli ( fail_auth_response )
140
140
result = subject . attempt_login ( cred_obj )
141
141
expect ( result ) . to be_kind_of ( ::Metasploit ::Framework ::LoginScanner ::Result )
142
142
expect ( result . status ) . to eq ( Metasploit ::Model ::Login ::Status ::INCORRECT )
0 commit comments