@@ -141,6 +141,71 @@ def cookie_sanity_check(meth)
141
141
cookies . split ( ';' ) . map ( &:strip )
142
142
end
143
143
144
+
145
+ describe '#get_hidden_inputs' do
146
+ let ( :response ) do
147
+ res = Rex ::Proto ::Http ::Response . new ( 200 , 'OK' )
148
+ res . body = %Q|
149
+ <html>
150
+ <head>
151
+ <body>
152
+ <form action="test.php">
153
+ <input name="input_1" type="hidden" value="some_value_1" />
154
+ </form>
155
+ <form>
156
+ <input name="input_0" type="text" value="Not a hidden input" />
157
+ <input name="input_1" type="hidden" value="some_value_1" />
158
+ <INPUT name="input_2" type="hidden" value="" />
159
+ </form>
160
+ </body>
161
+ </head>
162
+ </htm>
163
+ |
164
+ res
165
+ end
166
+
167
+ subject do
168
+ cli = Rex ::Proto ::Http ::Client . new ( '127.0.0.1' )
169
+ cli . connect
170
+ req = cli . request_cgi ( { 'uri' => '/' } )
171
+ res = cli . send_recv ( req )
172
+ res
173
+ end
174
+
175
+ before ( :each ) do
176
+ allow_any_instance_of ( Rex ::Proto ::Http ::Client ) . to receive ( :request_cgi ) . with ( any_args )
177
+ allow_any_instance_of ( Rex ::Proto ::Http ::Client ) . to receive ( :send_recv ) . with ( any_args ) . and_return ( response )
178
+ allow_any_instance_of ( Rex ::Proto ::Http ::Client ) . to receive ( :set_config ) . with ( any_args )
179
+ allow_any_instance_of ( Rex ::Proto ::Http ::Client ) . to receive ( :close )
180
+ allow_any_instance_of ( Rex ::Proto ::Http ::Client ) . to receive ( :connect )
181
+ end
182
+
183
+ context 'when an HTML page contains two forms containing hidden inputs' do
184
+ it 'returns an array' do
185
+ expect ( subject . get_hidden_inputs ) . to be_kind_of ( Array )
186
+ end
187
+
188
+ it 'returns hashes in the array' do
189
+ subject . get_hidden_inputs . each do |form |
190
+ expect ( form ) . to be_kind_of ( Hash )
191
+ end
192
+ end
193
+
194
+ it 'returns \'some_value_1\' in the input_1 hidden input from the first element' do
195
+ expect ( subject . get_hidden_inputs [ 0 ] [ 'input_1' ] ) . to eq ( 'some_value_1' )
196
+ end
197
+
198
+ it 'returns two hidden inputs in the second element' do
199
+ expect ( subject . get_hidden_inputs [ 1 ] . length ) . to eq ( 2 )
200
+ end
201
+
202
+ it 'returns an empty string for the input_2 hidden input from the second element' do
203
+ expect ( subject . get_hidden_inputs [ 1 ] [ 'input_2' ] ) . to be_empty
204
+ end
205
+ end
206
+ end
207
+
208
+
144
209
context "#get_cookies" do
145
210
146
211
it 'returns empty string for no Set-Cookies' do
0 commit comments