mechanize 2.7.3 → 2.8.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of mechanize might be problematic. Click here for more details.
- checksums.yaml +5 -5
- data/.github/workflows/ci-test.yml +45 -0
- data/.gitignore +15 -0
- data/.yardopts +8 -0
- data/{CHANGELOG.rdoc → CHANGELOG.md} +149 -62
- data/EXAMPLES.rdoc +2 -25
- data/Gemfile +3 -0
- data/{LICENSE.rdoc → LICENSE.txt} +4 -0
- data/README.md +79 -0
- data/Rakefile +36 -37
- data/examples/{rubyforge.rb → rubygems.rb} +7 -6
- data/lib/mechanize.rb +75 -33
- data/lib/mechanize/chunked_termination_error.rb +1 -0
- data/lib/mechanize/content_type_error.rb +1 -0
- data/lib/mechanize/cookie.rb +1 -13
- data/lib/mechanize/cookie_jar.rb +4 -12
- data/lib/mechanize/directory_saver.rb +15 -2
- data/lib/mechanize/download.rb +2 -1
- data/lib/mechanize/element_matcher.rb +29 -14
- data/lib/mechanize/element_not_found_error.rb +1 -0
- data/lib/mechanize/file.rb +2 -1
- data/lib/mechanize/file_connection.rb +5 -3
- data/lib/mechanize/file_request.rb +1 -0
- data/lib/mechanize/file_response.rb +5 -4
- data/lib/mechanize/file_saver.rb +1 -0
- data/lib/mechanize/form.rb +119 -46
- data/lib/mechanize/form/button.rb +1 -0
- data/lib/mechanize/form/check_box.rb +1 -0
- data/lib/mechanize/form/field.rb +47 -0
- data/lib/mechanize/form/file_upload.rb +1 -0
- data/lib/mechanize/form/hidden.rb +1 -0
- data/lib/mechanize/form/image_button.rb +1 -0
- data/lib/mechanize/form/keygen.rb +1 -0
- data/lib/mechanize/form/multi_select_list.rb +8 -14
- data/lib/mechanize/form/option.rb +3 -1
- data/lib/mechanize/form/radio_button.rb +1 -0
- data/lib/mechanize/form/reset.rb +1 -0
- data/lib/mechanize/form/select_list.rb +1 -0
- data/lib/mechanize/form/submit.rb +1 -0
- data/lib/mechanize/form/text.rb +1 -0
- data/lib/mechanize/form/textarea.rb +1 -0
- data/lib/mechanize/headers.rb +1 -0
- data/lib/mechanize/history.rb +2 -1
- data/lib/mechanize/http.rb +1 -0
- data/lib/mechanize/http/agent.rb +115 -64
- data/lib/mechanize/http/auth_challenge.rb +1 -0
- data/lib/mechanize/http/auth_realm.rb +2 -1
- data/lib/mechanize/http/auth_store.rb +3 -0
- data/lib/mechanize/http/content_disposition_parser.rb +18 -3
- data/lib/mechanize/http/www_authenticate_parser.rb +5 -5
- data/lib/mechanize/image.rb +1 -0
- data/lib/mechanize/page.rb +166 -55
- data/lib/mechanize/page/base.rb +1 -0
- data/lib/mechanize/page/frame.rb +4 -1
- data/lib/mechanize/page/image.rb +3 -0
- data/lib/mechanize/page/label.rb +1 -0
- data/lib/mechanize/page/link.rb +13 -1
- data/lib/mechanize/page/meta_refresh.rb +1 -0
- data/lib/mechanize/parser.rb +4 -3
- data/lib/mechanize/pluggable_parsers.rb +14 -1
- data/lib/mechanize/prependable.rb +1 -0
- data/lib/mechanize/redirect_limit_reached_error.rb +1 -0
- data/lib/mechanize/redirect_not_get_or_head_error.rb +1 -0
- data/lib/mechanize/response_code_error.rb +2 -1
- data/lib/mechanize/response_read_error.rb +1 -0
- data/lib/mechanize/robots_disallowed_error.rb +1 -0
- data/lib/mechanize/test_case.rb +39 -29
- data/lib/mechanize/test_case/bad_chunking_servlet.rb +1 -0
- data/lib/mechanize/test_case/basic_auth_servlet.rb +1 -0
- data/lib/mechanize/test_case/content_type_servlet.rb +1 -0
- data/lib/mechanize/test_case/digest_auth_servlet.rb +1 -0
- data/lib/mechanize/test_case/file_upload_servlet.rb +1 -0
- data/lib/mechanize/test_case/form_servlet.rb +1 -0
- data/lib/mechanize/test_case/gzip_servlet.rb +4 -3
- data/lib/mechanize/test_case/header_servlet.rb +1 -0
- data/lib/mechanize/test_case/http_refresh_servlet.rb +2 -2
- data/lib/mechanize/test_case/infinite_redirect_servlet.rb +1 -0
- data/lib/mechanize/test_case/infinite_refresh_servlet.rb +2 -2
- data/lib/mechanize/test_case/many_cookies_as_string_servlet.rb +1 -0
- data/lib/mechanize/test_case/many_cookies_servlet.rb +1 -0
- data/lib/mechanize/test_case/modified_since_servlet.rb +1 -0
- data/lib/mechanize/test_case/ntlm_servlet.rb +1 -0
- data/lib/mechanize/test_case/one_cookie_no_spaces_servlet.rb +1 -0
- data/lib/mechanize/test_case/one_cookie_servlet.rb +1 -0
- data/lib/mechanize/test_case/quoted_value_cookie_servlet.rb +1 -0
- data/lib/mechanize/test_case/redirect_servlet.rb +1 -0
- data/lib/mechanize/test_case/referer_servlet.rb +1 -0
- data/lib/mechanize/test_case/refresh_with_empty_url.rb +1 -0
- data/lib/mechanize/test_case/refresh_without_url.rb +1 -0
- data/lib/mechanize/test_case/response_code_servlet.rb +1 -0
- data/lib/mechanize/test_case/robots_txt_servlet.rb +15 -0
- data/lib/mechanize/test_case/send_cookies_servlet.rb +1 -0
- data/lib/mechanize/test_case/server.rb +1 -0
- data/lib/mechanize/test_case/servlets.rb +4 -0
- data/lib/mechanize/test_case/verb_servlet.rb +5 -6
- data/lib/mechanize/unauthorized_error.rb +2 -1
- data/lib/mechanize/unsupported_scheme_error.rb +5 -2
- data/lib/mechanize/util.rb +90 -43
- data/lib/mechanize/version.rb +4 -0
- data/lib/mechanize/xml_file.rb +1 -0
- data/mechanize.gemspec +69 -0
- data/test/htdocs/dir with spaces/foo.html +1 -0
- data/test/htdocs/find_link.html +1 -4
- data/test/htdocs/tc_links.html +1 -1
- data/test/test_mechanize.rb +111 -55
- data/test/test_mechanize_cookie.rb +75 -60
- data/test/test_mechanize_cookie_jar.rb +112 -59
- data/test/test_mechanize_download.rb +13 -1
- data/test/test_mechanize_file.rb +10 -0
- data/test/test_mechanize_file_connection.rb +21 -3
- data/test/test_mechanize_file_response.rb +26 -2
- data/test/test_mechanize_form.rb +46 -11
- data/test/test_mechanize_form_check_box.rb +10 -0
- data/test/test_mechanize_form_encoding.rb +3 -8
- data/test/test_mechanize_form_keygen.rb +1 -0
- data/test/test_mechanize_form_multi_select_list.rb +5 -1
- data/test/test_mechanize_http_agent.rb +175 -18
- data/test/test_mechanize_http_auth_challenge.rb +14 -0
- data/test/test_mechanize_http_auth_realm.rb +7 -1
- data/test/test_mechanize_http_auth_store.rb +37 -0
- data/test/test_mechanize_http_content_disposition_parser.rb +35 -1
- data/test/test_mechanize_http_www_authenticate_parser.rb +24 -0
- data/test/test_mechanize_link.rb +60 -4
- data/test/test_mechanize_page.rb +82 -7
- data/test/test_mechanize_page_encoding.rb +2 -3
- data/test/test_mechanize_page_image.rb +1 -1
- data/test/test_mechanize_page_link.rb +20 -5
- data/test/test_mechanize_page_meta_refresh.rb +1 -1
- data/test/test_mechanize_parser.rb +12 -2
- data/test/test_mechanize_util.rb +46 -11
- metadata +198 -99
- data/.gemtest +0 -0
- data/.travis.yml +0 -26
- data/Manifest.txt +0 -205
- data/README.rdoc +0 -83
- data/lib/mechanize/monkey_patch.rb +0 -17
- data/test/htdocs/robots.txt +0 -2
@@ -18,14 +18,21 @@ module Enumerable
|
|
18
18
|
end
|
19
19
|
|
20
20
|
class TestMechanizeCookie < Mechanize::TestCase
|
21
|
-
def
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
21
|
+
def assert_cookie_parse url, cookie_text, &block
|
22
|
+
cookie = nil
|
23
|
+
|
24
|
+
block ||= proc { |p_cookie| cookie = p_cookie }
|
25
|
+
|
26
|
+
exp_re = /The call of Mechanize::Cookie.parse/
|
27
|
+
assert_output "", exp_re do
|
28
|
+
Mechanize::Cookie.parse(url, cookie_text, &block)
|
29
|
+
end
|
30
|
+
|
31
|
+
cookie
|
27
32
|
end
|
28
33
|
|
34
|
+
alias silently capture_io
|
35
|
+
|
29
36
|
def test_parse_dates
|
30
37
|
url = URI.parse('http://localhost/')
|
31
38
|
|
@@ -64,7 +71,7 @@ class TestMechanizeCookie < Mechanize::TestCase
|
|
64
71
|
|
65
72
|
uri = URI.parse 'http://example'
|
66
73
|
|
67
|
-
|
74
|
+
assert_cookie_parse uri, cookie_str do |cookie|
|
68
75
|
assert_equal 'a', cookie.name
|
69
76
|
assert_equal 'b', cookie.value
|
70
77
|
end
|
@@ -75,7 +82,7 @@ class TestMechanizeCookie < Mechanize::TestCase
|
|
75
82
|
|
76
83
|
uri = URI.parse 'http://example'
|
77
84
|
|
78
|
-
|
85
|
+
assert_cookie_parse uri, cookie_str do |cookie|
|
79
86
|
assert_equal 'foo', cookie.name
|
80
87
|
assert_equal 'bar', cookie.value
|
81
88
|
assert_equal '/', cookie.path
|
@@ -89,7 +96,7 @@ class TestMechanizeCookie < Mechanize::TestCase
|
|
89
96
|
|
90
97
|
uri = URI.parse 'http://example'
|
91
98
|
|
92
|
-
|
99
|
+
assert_cookie_parse uri, cookie_str do |cookie|
|
93
100
|
assert_equal 'quoted', cookie.name
|
94
101
|
assert_equal 'value', cookie.value
|
95
102
|
end
|
@@ -98,41 +105,43 @@ class TestMechanizeCookie < Mechanize::TestCase
|
|
98
105
|
def test_parse_weird_cookie
|
99
106
|
cookie = 'n/a, ASPSESSIONIDCSRRQDQR=FBLDGHPBNDJCPCGNCPAENELB; path=/'
|
100
107
|
url = URI.parse('http://www.searchinnovation.com/')
|
101
|
-
|
108
|
+
assert_cookie_parse url, cookie do |c|
|
102
109
|
assert_equal('ASPSESSIONIDCSRRQDQR', c.name)
|
103
110
|
assert_equal('FBLDGHPBNDJCPCGNCPAENELB', c.value)
|
104
|
-
|
111
|
+
end
|
105
112
|
end
|
106
113
|
|
107
114
|
def test_double_semicolon
|
108
115
|
double_semi = 'WSIDC=WEST;; domain=.williams-sonoma.com; path=/'
|
109
116
|
url = URI.parse('http://williams-sonoma.com/')
|
110
|
-
|
117
|
+
assert_cookie_parse url, double_semi do |cookie|
|
111
118
|
assert_equal('WSIDC', cookie.name)
|
112
119
|
assert_equal('WEST', cookie.value)
|
113
|
-
|
120
|
+
end
|
114
121
|
end
|
115
122
|
|
116
123
|
def test_parse_bad_version
|
117
124
|
bad_cookie = 'PRETANET=TGIAqbFXtt; Name=/PRETANET; Path=/; Version=1.2; Content-type=text/html; Domain=192.168.6.196; expires=Friday, 13-November-2026 23:01:46 GMT;'
|
118
125
|
url = URI.parse('http://localhost/')
|
119
|
-
|
126
|
+
|
127
|
+
assert_cookie_parse url, bad_cookie do |cookie|
|
120
128
|
assert_nil(cookie.version)
|
121
|
-
|
129
|
+
end
|
122
130
|
end
|
123
131
|
|
124
132
|
def test_parse_bad_max_age
|
125
133
|
bad_cookie = 'PRETANET=TGIAqbFXtt; Name=/PRETANET; Path=/; Max-Age=1.2; Content-type=text/html; Domain=192.168.6.196; expires=Friday, 13-November-2026 23:01:46 GMT;'
|
126
134
|
url = URI.parse('http://localhost/')
|
127
|
-
|
135
|
+
|
136
|
+
assert_cookie_parse url, bad_cookie do |cookie|
|
128
137
|
assert_nil(cookie.max_age)
|
129
|
-
|
138
|
+
end
|
130
139
|
end
|
131
140
|
|
132
141
|
def test_parse_date_fail
|
133
142
|
url = URI.parse('http://localhost/')
|
134
143
|
|
135
|
-
dates = [
|
144
|
+
dates = [
|
136
145
|
"20/06/95 21:07",
|
137
146
|
]
|
138
147
|
|
@@ -151,7 +160,7 @@ class TestMechanizeCookie < Mechanize::TestCase
|
|
151
160
|
|
152
161
|
cookie_str = 'a=b; domain=.example.com'
|
153
162
|
|
154
|
-
cookie =
|
163
|
+
cookie = assert_cookie_parse url, cookie_str
|
155
164
|
|
156
165
|
assert_equal 'example.com', cookie.domain
|
157
166
|
assert cookie.for_domain?
|
@@ -162,7 +171,7 @@ class TestMechanizeCookie < Mechanize::TestCase
|
|
162
171
|
|
163
172
|
cookie_str = 'a=b; domain=example.com'
|
164
173
|
|
165
|
-
cookie =
|
174
|
+
cookie = assert_cookie_parse url, cookie_str
|
166
175
|
|
167
176
|
assert_equal 'example.com', cookie.domain
|
168
177
|
assert cookie.for_domain?
|
@@ -173,7 +182,7 @@ class TestMechanizeCookie < Mechanize::TestCase
|
|
173
182
|
|
174
183
|
cookie_str = 'a=b;'
|
175
184
|
|
176
|
-
cookie =
|
185
|
+
cookie = assert_cookie_parse url, cookie_str
|
177
186
|
|
178
187
|
assert_equal 'example.com', cookie.domain
|
179
188
|
assert !cookie.for_domain?
|
@@ -184,17 +193,23 @@ class TestMechanizeCookie < Mechanize::TestCase
|
|
184
193
|
|
185
194
|
date = 'Mon, 19 Feb 2012 19:26:04 GMT'
|
186
195
|
|
187
|
-
|
196
|
+
cookie_text = "name=Akinori; expires=#{date}"
|
197
|
+
cookie = assert_cookie_parse url, cookie_text
|
188
198
|
assert_equal Time.at(1329679564), cookie.expires
|
189
199
|
|
190
|
-
|
200
|
+
cookie_text = 'name=Akinori; max-age=3600'
|
201
|
+
cookie = assert_cookie_parse url, cookie_text
|
191
202
|
assert_in_delta Time.now + 3600, cookie.expires, 1
|
192
203
|
|
193
204
|
# Max-Age has precedence over Expires
|
194
|
-
|
205
|
+
cookie_text = "name=Akinori; max-age=3600; expires=#{date}"
|
206
|
+
cookie = assert_cookie_parse url, cookie_text
|
207
|
+
|
195
208
|
assert_in_delta Time.now + 3600, cookie.expires, 1
|
196
209
|
|
197
|
-
|
210
|
+
cookie_text = "name=Akinori; expires=#{date}; max-age=3600"
|
211
|
+
cookie = assert_cookie_parse url, cookie_text
|
212
|
+
|
198
213
|
assert_in_delta Time.now + 3600, cookie.expires, 1
|
199
214
|
end
|
200
215
|
|
@@ -208,7 +223,7 @@ class TestMechanizeCookie < Mechanize::TestCase
|
|
208
223
|
'name=Akinori; expires=',
|
209
224
|
'name=Akinori; max-age=',
|
210
225
|
].each { |str|
|
211
|
-
cookie =
|
226
|
+
cookie = assert_cookie_parse url, str
|
212
227
|
assert cookie.session, str
|
213
228
|
}
|
214
229
|
|
@@ -216,7 +231,7 @@ class TestMechanizeCookie < Mechanize::TestCase
|
|
216
231
|
'name=Akinori; expires=Mon, 19 Feb 2012 19:26:04 GMT',
|
217
232
|
'name=Akinori; max-age=3600',
|
218
233
|
].each { |str|
|
219
|
-
cookie =
|
234
|
+
cookie = assert_cookie_parse url, str
|
220
235
|
assert !cookie.session, str
|
221
236
|
}
|
222
237
|
end
|
@@ -237,7 +252,8 @@ class TestMechanizeCookie < Mechanize::TestCase
|
|
237
252
|
"no_domain2=no_domain; Expires=Sun, 06 Nov 2011 00:29:53 GMT; no_expires=nope; Domain, " \
|
238
253
|
"no_domain3=no_domain; Expires=Sun, 06 Nov 2011 00:29:53 GMT; no_expires=nope; Domain="
|
239
254
|
|
240
|
-
cookies =
|
255
|
+
cookies = nil
|
256
|
+
silently { cookies = Mechanize::Cookie.parse url, cookie_str }
|
241
257
|
assert_equal 13, cookies.length
|
242
258
|
|
243
259
|
name = cookies.find { |c| c.name == 'name' }
|
@@ -274,16 +290,16 @@ class TestMechanizeCookie < Mechanize::TestCase
|
|
274
290
|
end
|
275
291
|
|
276
292
|
def test_parse_valid_cookie
|
277
|
-
url = URI.parse('http://
|
293
|
+
url = URI.parse('http://rubygems.org/')
|
278
294
|
cookie_params = {}
|
279
295
|
cookie_params['expires'] = 'expires=Sun, 27-Sep-2037 00:00:00 GMT'
|
280
296
|
cookie_params['path'] = 'path=/'
|
281
|
-
cookie_params['domain'] = 'domain=.
|
297
|
+
cookie_params['domain'] = 'domain=.rubygems.org'
|
282
298
|
cookie_params['httponly'] = 'HttpOnly'
|
283
299
|
cookie_value = '12345%7D=ASDFWEE345%3DASda'
|
284
300
|
|
285
301
|
expires = Time.parse('Sun, 27-Sep-2037 00:00:00 GMT')
|
286
|
-
|
302
|
+
|
287
303
|
cookie_params.keys.combine.each do |c|
|
288
304
|
cookie_text = "#{cookie_value}; "
|
289
305
|
c.each_with_index do |key, idx|
|
@@ -293,8 +309,8 @@ class TestMechanizeCookie < Mechanize::TestCase
|
|
293
309
|
cookie_text << "#{cookie_params[key]}; "
|
294
310
|
end
|
295
311
|
end
|
296
|
-
|
297
|
-
|
312
|
+
|
313
|
+
cookie = assert_cookie_parse url, cookie_text
|
298
314
|
|
299
315
|
assert_equal('12345%7D=ASDFWEE345%3DASda', cookie.to_s)
|
300
316
|
assert_equal('/', cookie.path)
|
@@ -309,16 +325,16 @@ class TestMechanizeCookie < Mechanize::TestCase
|
|
309
325
|
end
|
310
326
|
|
311
327
|
def test_parse_valid_cookie_empty_value
|
312
|
-
url = URI.parse('http://
|
328
|
+
url = URI.parse('http://rubygems.org/')
|
313
329
|
cookie_params = {}
|
314
330
|
cookie_params['expires'] = 'expires=Sun, 27-Sep-2037 00:00:00 GMT'
|
315
331
|
cookie_params['path'] = 'path=/'
|
316
|
-
cookie_params['domain'] = 'domain=.
|
332
|
+
cookie_params['domain'] = 'domain=.rubygems.org'
|
317
333
|
cookie_params['httponly'] = 'HttpOnly'
|
318
334
|
cookie_value = '12345%7D='
|
319
335
|
|
320
336
|
expires = Time.parse('Sun, 27-Sep-2037 00:00:00 GMT')
|
321
|
-
|
337
|
+
|
322
338
|
cookie_params.keys.combine.each do |c|
|
323
339
|
cookie_text = "#{cookie_value}; "
|
324
340
|
c.each_with_index do |key, idx|
|
@@ -328,8 +344,7 @@ class TestMechanizeCookie < Mechanize::TestCase
|
|
328
344
|
cookie_text << "#{cookie_params[key]}; "
|
329
345
|
end
|
330
346
|
end
|
331
|
-
cookie =
|
332
|
-
Mechanize::Cookie.parse(url, cookie_text) { |p_cookie| cookie = p_cookie }
|
347
|
+
cookie = assert_cookie_parse url, cookie_text
|
333
348
|
|
334
349
|
assert_equal('12345%7D=', cookie.to_s)
|
335
350
|
assert_equal('', cookie.value)
|
@@ -346,16 +361,16 @@ class TestMechanizeCookie < Mechanize::TestCase
|
|
346
361
|
|
347
362
|
# If no path was given, use the one from the URL
|
348
363
|
def test_cookie_using_url_path
|
349
|
-
url = URI.parse('http://
|
364
|
+
url = URI.parse('http://rubygems.org/login.php')
|
350
365
|
cookie_params = {}
|
351
366
|
cookie_params['expires'] = 'expires=Sun, 27-Sep-2037 00:00:00 GMT'
|
352
367
|
cookie_params['path'] = 'path=/'
|
353
|
-
cookie_params['domain'] = 'domain=.
|
368
|
+
cookie_params['domain'] = 'domain=.rubygems.org'
|
354
369
|
cookie_params['httponly'] = 'HttpOnly'
|
355
370
|
cookie_value = '12345%7D=ASDFWEE345%3DASda'
|
356
371
|
|
357
372
|
expires = Time.parse('Sun, 27-Sep-2037 00:00:00 GMT')
|
358
|
-
|
373
|
+
|
359
374
|
cookie_params.keys.combine.each do |c|
|
360
375
|
next if c.find { |k| k == 'path' }
|
361
376
|
cookie_text = "#{cookie_value}; "
|
@@ -366,8 +381,8 @@ class TestMechanizeCookie < Mechanize::TestCase
|
|
366
381
|
cookie_text << "#{cookie_params[key]}; "
|
367
382
|
end
|
368
383
|
end
|
369
|
-
|
370
|
-
|
384
|
+
|
385
|
+
cookie = assert_cookie_parse url, cookie_text
|
371
386
|
|
372
387
|
assert_equal('12345%7D=ASDFWEE345%3DASda', cookie.to_s)
|
373
388
|
assert_equal('/', cookie.path)
|
@@ -383,16 +398,16 @@ class TestMechanizeCookie < Mechanize::TestCase
|
|
383
398
|
|
384
399
|
# Test using secure cookies
|
385
400
|
def test_cookie_with_secure
|
386
|
-
url = URI.parse('http://
|
401
|
+
url = URI.parse('http://rubygems.org/')
|
387
402
|
cookie_params = {}
|
388
403
|
cookie_params['expires'] = 'expires=Sun, 27-Sep-2037 00:00:00 GMT'
|
389
404
|
cookie_params['path'] = 'path=/'
|
390
|
-
cookie_params['domain'] = 'domain=.
|
405
|
+
cookie_params['domain'] = 'domain=.rubygems.org'
|
391
406
|
cookie_params['secure'] = 'secure'
|
392
407
|
cookie_value = '12345%7D=ASDFWEE345%3DASda'
|
393
408
|
|
394
409
|
expires = Time.parse('Sun, 27-Sep-2037 00:00:00 GMT')
|
395
|
-
|
410
|
+
|
396
411
|
cookie_params.keys.combine.each do |c|
|
397
412
|
next unless c.find { |k| k == 'secure' }
|
398
413
|
cookie_text = "#{cookie_value}; "
|
@@ -403,8 +418,8 @@ class TestMechanizeCookie < Mechanize::TestCase
|
|
403
418
|
cookie_text << "#{cookie_params[key]}; "
|
404
419
|
end
|
405
420
|
end
|
406
|
-
|
407
|
-
|
421
|
+
|
422
|
+
cookie = assert_cookie_parse url, cookie_text
|
408
423
|
|
409
424
|
assert_equal('12345%7D=ASDFWEE345%3DASda', cookie.to_s)
|
410
425
|
assert_equal('/', cookie.path)
|
@@ -420,16 +435,16 @@ class TestMechanizeCookie < Mechanize::TestCase
|
|
420
435
|
end
|
421
436
|
|
422
437
|
def test_parse_cookie_no_spaces
|
423
|
-
url = URI.parse('http://
|
438
|
+
url = URI.parse('http://rubygems.org/')
|
424
439
|
cookie_params = {}
|
425
440
|
cookie_params['expires'] = 'expires=Sun, 27-Sep-2037 00:00:00 GMT'
|
426
441
|
cookie_params['path'] = 'path=/'
|
427
|
-
cookie_params['domain'] = 'domain=.
|
442
|
+
cookie_params['domain'] = 'domain=.rubygems.org'
|
428
443
|
cookie_params['httponly'] = 'HttpOnly'
|
429
444
|
cookie_value = '12345%7D=ASDFWEE345%3DASda'
|
430
445
|
|
431
446
|
expires = Time.parse('Sun, 27-Sep-2037 00:00:00 GMT')
|
432
|
-
|
447
|
+
|
433
448
|
cookie_params.keys.combine.each do |c|
|
434
449
|
cookie_text = "#{cookie_value};"
|
435
450
|
c.each_with_index do |key, idx|
|
@@ -439,8 +454,8 @@ class TestMechanizeCookie < Mechanize::TestCase
|
|
439
454
|
cookie_text << "#{cookie_params[key]};"
|
440
455
|
end
|
441
456
|
end
|
442
|
-
|
443
|
-
|
457
|
+
|
458
|
+
cookie = assert_cookie_parse url, cookie_text
|
444
459
|
|
445
460
|
assert_equal('12345%7D=ASDFWEE345%3DASda', cookie.to_s)
|
446
461
|
assert_equal('/', cookie.path)
|
@@ -458,7 +473,7 @@ class TestMechanizeCookie < Mechanize::TestCase
|
|
458
473
|
cookie = Mechanize::Cookie.new('key', 'value')
|
459
474
|
assert_equal 'key', cookie.name
|
460
475
|
assert_equal 'value', cookie.value
|
461
|
-
|
476
|
+
assert_nil cookie.expires
|
462
477
|
|
463
478
|
# Minimum unit for the expires attribute is second
|
464
479
|
expires = Time.at((Time.now + 3600).to_i)
|
@@ -478,7 +493,7 @@ class TestMechanizeCookie < Mechanize::TestCase
|
|
478
493
|
url = URI.parse('http://host.dom.example.com:8080/')
|
479
494
|
|
480
495
|
cookie_str = 'a=b; domain=Example.Com'
|
481
|
-
cookie =
|
496
|
+
cookie = assert_cookie_parse url, cookie_str
|
482
497
|
assert 'example.com', cookie.domain
|
483
498
|
|
484
499
|
cookie.domain = DomainName(url.host)
|
@@ -496,13 +511,13 @@ class TestMechanizeCookie < Mechanize::TestCase
|
|
496
511
|
end
|
497
512
|
|
498
513
|
def test_cookie_httponly
|
499
|
-
url = URI.parse('http://
|
514
|
+
url = URI.parse('http://rubygems.org/')
|
500
515
|
cookie_params = {}
|
501
516
|
cookie_params['httponly'] = 'HttpOnly'
|
502
517
|
cookie_value = '12345%7D=ASDFWEE345%3DASda'
|
503
518
|
|
504
519
|
expires = Time.parse('Sun, 27-Sep-2037 00:00:00 GMT')
|
505
|
-
|
520
|
+
|
506
521
|
cookie_params.keys.combine.each do |c|
|
507
522
|
cookie_text = "#{cookie_value}; "
|
508
523
|
c.each_with_index do |key, idx|
|
@@ -512,12 +527,12 @@ class TestMechanizeCookie < Mechanize::TestCase
|
|
512
527
|
cookie_text << "#{cookie_params[key]}; "
|
513
528
|
end
|
514
529
|
end
|
515
|
-
|
516
|
-
|
530
|
+
|
531
|
+
cookie = assert_cookie_parse url, cookie_text
|
517
532
|
|
518
533
|
assert_equal(true, cookie.httponly)
|
519
534
|
|
520
|
-
|
535
|
+
|
521
536
|
# if expires was set, make sure we parsed it
|
522
537
|
if c.find { |k| k == 'expires' }
|
523
538
|
assert_equal(expires, cookie.expires)
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'mechanize/test_case'
|
2
|
+
require 'fileutils'
|
2
3
|
|
3
4
|
class TestMechanizeCookieJar < Mechanize::TestCase
|
4
5
|
|
@@ -6,6 +7,30 @@ class TestMechanizeCookieJar < Mechanize::TestCase
|
|
6
7
|
super
|
7
8
|
|
8
9
|
@jar = Mechanize::CookieJar.new
|
10
|
+
|
11
|
+
@jar.extend Minitest::Assertions
|
12
|
+
|
13
|
+
def @jar.add(*args)
|
14
|
+
capture_io { super }
|
15
|
+
end
|
16
|
+
|
17
|
+
def @jar.jar(*args)
|
18
|
+
result = nil
|
19
|
+
capture_io { result = super }
|
20
|
+
result
|
21
|
+
end
|
22
|
+
|
23
|
+
def @jar.save_as(*args)
|
24
|
+
result = nil
|
25
|
+
capture_io { result = super }
|
26
|
+
result
|
27
|
+
end
|
28
|
+
|
29
|
+
def @jar.clear!(*args)
|
30
|
+
result = nil
|
31
|
+
capture_io { result = super }
|
32
|
+
result
|
33
|
+
end
|
9
34
|
end
|
10
35
|
|
11
36
|
def cookie_values(options = {})
|
@@ -15,23 +40,23 @@ class TestMechanizeCookieJar < Mechanize::TestCase
|
|
15
40
|
:path => '/',
|
16
41
|
:expires => Time.now + (10 * 86400),
|
17
42
|
:for_domain => true,
|
18
|
-
:domain => '
|
43
|
+
:domain => 'rubygems.org'
|
19
44
|
}.merge(options)
|
20
45
|
end
|
21
46
|
|
22
47
|
def test_two_cookies_same_domain_and_name_different_paths
|
23
|
-
url = URI 'http://
|
48
|
+
url = URI 'http://rubygems.org/'
|
24
49
|
|
25
50
|
cookie = Mechanize::Cookie.new(cookie_values)
|
26
51
|
@jar.add(url, cookie)
|
27
52
|
@jar.add(url, Mechanize::Cookie.new(cookie_values(:path => '/onetwo')))
|
28
53
|
|
29
54
|
assert_equal(1, @jar.cookies(url).length)
|
30
|
-
assert_equal 2, @jar.cookies(URI('http://
|
55
|
+
assert_equal 2, @jar.cookies(URI('http://rubygems.org/onetwo')).length
|
31
56
|
end
|
32
57
|
|
33
58
|
def test_domain_case
|
34
|
-
url = URI 'http://
|
59
|
+
url = URI 'http://rubygems.org/'
|
35
60
|
|
36
61
|
# Add one cookie with an expiration date in the future
|
37
62
|
cookie = Mechanize::Cookie.new(cookie_values)
|
@@ -39,49 +64,49 @@ class TestMechanizeCookieJar < Mechanize::TestCase
|
|
39
64
|
assert_equal(1, @jar.cookies(url).length)
|
40
65
|
|
41
66
|
@jar.add(url, Mechanize::Cookie.new(
|
42
|
-
cookie_values(:domain => '
|
67
|
+
cookie_values(:domain => 'rubygems.Org', :name => 'aaron')))
|
43
68
|
|
44
69
|
assert_equal(2, @jar.cookies(url).length)
|
45
70
|
|
46
|
-
url2 = URI 'http://
|
71
|
+
url2 = URI 'http://rubygems.oRg/'
|
47
72
|
assert_equal(2, @jar.cookies(url2).length)
|
48
73
|
end
|
49
74
|
|
50
75
|
def test_host_only
|
51
|
-
url = URI.parse('http://
|
76
|
+
url = URI.parse('http://rubygems.org/')
|
52
77
|
|
53
78
|
@jar.add(url, Mechanize::Cookie.new(
|
54
|
-
cookie_values(:domain => '
|
79
|
+
cookie_values(:domain => 'rubygems.org', :for_domain => false)))
|
55
80
|
|
56
81
|
assert_equal(1, @jar.cookies(url).length)
|
57
82
|
|
58
|
-
assert_equal(1, @jar.cookies(URI('http://
|
83
|
+
assert_equal(1, @jar.cookies(URI('http://rubygems.org/')).length)
|
59
84
|
|
60
|
-
assert_equal(1, @jar.cookies(URI('https://
|
85
|
+
assert_equal(1, @jar.cookies(URI('https://rubygems.org/')).length)
|
61
86
|
|
62
|
-
assert_equal(0, @jar.cookies(URI('http://www.
|
87
|
+
assert_equal(0, @jar.cookies(URI('http://www.rubygems.org/')).length)
|
63
88
|
end
|
64
89
|
|
65
90
|
def test_empty_value
|
66
91
|
values = cookie_values(:value => "")
|
67
|
-
url = URI 'http://
|
92
|
+
url = URI 'http://rubygems.org/'
|
68
93
|
|
69
94
|
# Add one cookie with an expiration date in the future
|
70
95
|
cookie = Mechanize::Cookie.new(values)
|
71
96
|
@jar.add(url, cookie)
|
72
97
|
assert_equal(1, @jar.cookies(url).length)
|
73
98
|
|
74
|
-
@jar.add url, Mechanize::Cookie.new(values.merge(:domain => '
|
99
|
+
@jar.add url, Mechanize::Cookie.new(values.merge(:domain => 'rubygems.Org',
|
75
100
|
:name => 'aaron'))
|
76
101
|
|
77
102
|
assert_equal(2, @jar.cookies(url).length)
|
78
103
|
|
79
|
-
url2 = URI 'http://
|
104
|
+
url2 = URI 'http://rubygems.oRg/'
|
80
105
|
assert_equal(2, @jar.cookies(url2).length)
|
81
106
|
end
|
82
107
|
|
83
108
|
def test_add_future_cookies
|
84
|
-
url = URI 'http://
|
109
|
+
url = URI 'http://rubygems.org/'
|
85
110
|
|
86
111
|
# Add one cookie with an expiration date in the future
|
87
112
|
cookie = Mechanize::Cookie.new(cookie_values)
|
@@ -93,14 +118,14 @@ class TestMechanizeCookieJar < Mechanize::TestCase
|
|
93
118
|
assert_equal(1, @jar.cookies(url).length)
|
94
119
|
|
95
120
|
# Make sure we can get the cookie from different paths
|
96
|
-
assert_equal(1, @jar.cookies(URI('http://
|
121
|
+
assert_equal(1, @jar.cookies(URI('http://rubygems.org/login')).length)
|
97
122
|
|
98
123
|
# Make sure we can't get the cookie from different domains
|
99
124
|
assert_equal(0, @jar.cookies(URI('http://google.com/')).length)
|
100
125
|
end
|
101
126
|
|
102
127
|
def test_add_multiple_cookies
|
103
|
-
url = URI 'http://
|
128
|
+
url = URI 'http://rubygems.org/'
|
104
129
|
|
105
130
|
# Add one cookie with an expiration date in the future
|
106
131
|
cookie = Mechanize::Cookie.new(cookie_values)
|
@@ -112,14 +137,14 @@ class TestMechanizeCookieJar < Mechanize::TestCase
|
|
112
137
|
assert_equal(2, @jar.cookies(url).length)
|
113
138
|
|
114
139
|
# Make sure we can get the cookie from different paths
|
115
|
-
assert_equal(2, @jar.cookies(URI('http://
|
140
|
+
assert_equal(2, @jar.cookies(URI('http://rubygems.org/login')).length)
|
116
141
|
|
117
142
|
# Make sure we can't get the cookie from different domains
|
118
143
|
assert_equal(0, @jar.cookies(URI('http://google.com/')).length)
|
119
144
|
end
|
120
145
|
|
121
146
|
def test_add_rejects_cookies_that_do_not_contain_an_embedded_dot
|
122
|
-
url = URI 'http://
|
147
|
+
url = URI 'http://rubygems.org/'
|
123
148
|
|
124
149
|
tld_cookie = Mechanize::Cookie.new(cookie_values(:domain => '.org'))
|
125
150
|
@jar.add(url, tld_cookie)
|
@@ -172,43 +197,43 @@ class TestMechanizeCookieJar < Mechanize::TestCase
|
|
172
197
|
end
|
173
198
|
|
174
199
|
def test_cookie_without_leading_dot_does_not_cause_substring_match
|
175
|
-
url = URI 'http://
|
200
|
+
url = URI 'http://arubygems.org/'
|
176
201
|
|
177
|
-
cookie = Mechanize::Cookie.new(cookie_values(:domain => '
|
202
|
+
cookie = Mechanize::Cookie.new(cookie_values(:domain => 'rubygems.org'))
|
178
203
|
@jar.add(url, cookie)
|
179
204
|
|
180
205
|
assert_equal(0, @jar.cookies(url).length)
|
181
206
|
end
|
182
207
|
|
183
208
|
def test_cookie_without_leading_dot_matches_subdomains
|
184
|
-
url = URI 'http://admin.
|
209
|
+
url = URI 'http://admin.rubygems.org/'
|
185
210
|
|
186
|
-
cookie = Mechanize::Cookie.new(cookie_values(:domain => '
|
211
|
+
cookie = Mechanize::Cookie.new(cookie_values(:domain => 'rubygems.org'))
|
187
212
|
@jar.add(url, cookie)
|
188
213
|
|
189
214
|
assert_equal(1, @jar.cookies(url).length)
|
190
215
|
end
|
191
216
|
|
192
217
|
def test_cookies_with_leading_dot_match_subdomains
|
193
|
-
url = URI 'http://admin.
|
218
|
+
url = URI 'http://admin.rubygems.org/'
|
194
219
|
|
195
|
-
@jar.add(url, Mechanize::Cookie.new(cookie_values(:domain => '.
|
220
|
+
@jar.add(url, Mechanize::Cookie.new(cookie_values(:domain => '.rubygems.org')))
|
196
221
|
|
197
222
|
assert_equal(1, @jar.cookies(url).length)
|
198
223
|
end
|
199
224
|
|
200
225
|
def test_cookies_with_leading_dot_match_parent_domains
|
201
|
-
url = URI 'http://
|
226
|
+
url = URI 'http://rubygems.org/'
|
202
227
|
|
203
|
-
@jar.add(url, Mechanize::Cookie.new(cookie_values(:domain => '.
|
228
|
+
@jar.add(url, Mechanize::Cookie.new(cookie_values(:domain => '.rubygems.org')))
|
204
229
|
|
205
230
|
assert_equal(1, @jar.cookies(url).length)
|
206
231
|
end
|
207
232
|
|
208
233
|
def test_cookies_with_leading_dot_match_parent_domains_exactly
|
209
|
-
url = URI 'http://
|
234
|
+
url = URI 'http://arubygems.org/'
|
210
235
|
|
211
|
-
@jar.add(url, Mechanize::Cookie.new(cookie_values(:domain => '.
|
236
|
+
@jar.add(url, Mechanize::Cookie.new(cookie_values(:domain => '.rubygems.org')))
|
212
237
|
|
213
238
|
assert_equal(0, @jar.cookies(url).length)
|
214
239
|
end
|
@@ -251,7 +276,7 @@ class TestMechanizeCookieJar < Mechanize::TestCase
|
|
251
276
|
end
|
252
277
|
|
253
278
|
def test_clear_bang
|
254
|
-
url = URI 'http://
|
279
|
+
url = URI 'http://rubygems.org/'
|
255
280
|
|
256
281
|
# Add one cookie with an expiration date in the future
|
257
282
|
cookie = Mechanize::Cookie.new(cookie_values)
|
@@ -265,13 +290,12 @@ class TestMechanizeCookieJar < Mechanize::TestCase
|
|
265
290
|
end
|
266
291
|
|
267
292
|
def test_save_cookies_yaml
|
268
|
-
url = URI 'http://
|
293
|
+
url = URI 'http://rubygems.org/'
|
269
294
|
|
270
295
|
# Add one cookie with an expiration date in the future
|
271
296
|
cookie = Mechanize::Cookie.new(cookie_values)
|
272
297
|
s_cookie = Mechanize::Cookie.new(cookie_values(:name => 'Bar',
|
273
|
-
:expires => nil
|
274
|
-
:session => true))
|
298
|
+
:expires => nil))
|
275
299
|
|
276
300
|
@jar.add(url, cookie)
|
277
301
|
@jar.add(url, s_cookie)
|
@@ -292,13 +316,12 @@ class TestMechanizeCookieJar < Mechanize::TestCase
|
|
292
316
|
end
|
293
317
|
|
294
318
|
def test_save_session_cookies_yaml
|
295
|
-
url = URI 'http://
|
319
|
+
url = URI 'http://rubygems.org/'
|
296
320
|
|
297
321
|
# Add one cookie with an expiration date in the future
|
298
322
|
cookie = Mechanize::Cookie.new(cookie_values)
|
299
323
|
s_cookie = Mechanize::Cookie.new(cookie_values(:name => 'Bar',
|
300
|
-
:expires => nil
|
301
|
-
:session => true))
|
324
|
+
:expires => nil))
|
302
325
|
|
303
326
|
@jar.add(url, cookie)
|
304
327
|
@jar.add(url, s_cookie)
|
@@ -319,13 +342,12 @@ class TestMechanizeCookieJar < Mechanize::TestCase
|
|
319
342
|
|
320
343
|
|
321
344
|
def test_save_cookies_cookiestxt
|
322
|
-
url = URI 'http://
|
345
|
+
url = URI 'http://rubygems.org/'
|
323
346
|
|
324
347
|
# Add one cookie with an expiration date in the future
|
325
348
|
cookie = Mechanize::Cookie.new(cookie_values)
|
326
349
|
s_cookie = Mechanize::Cookie.new(cookie_values(:name => 'Bar',
|
327
|
-
:expires => nil
|
328
|
-
:session => true))
|
350
|
+
:expires => nil))
|
329
351
|
|
330
352
|
@jar.add(url, cookie)
|
331
353
|
@jar.add(url, s_cookie)
|
@@ -357,7 +379,7 @@ class TestMechanizeCookieJar < Mechanize::TestCase
|
|
357
379
|
end
|
358
380
|
|
359
381
|
def test_expire_cookies
|
360
|
-
url = URI 'http://
|
382
|
+
url = URI 'http://rubygems.org/'
|
361
383
|
|
362
384
|
# Add one cookie with an expiration date in the future
|
363
385
|
cookie = Mechanize::Cookie.new(cookie_values)
|
@@ -369,7 +391,7 @@ class TestMechanizeCookieJar < Mechanize::TestCase
|
|
369
391
|
assert_equal(2, @jar.cookies(url).length)
|
370
392
|
|
371
393
|
# Make sure we can get the cookie from different paths
|
372
|
-
assert_equal(2, @jar.cookies(URI('http://
|
394
|
+
assert_equal(2, @jar.cookies(URI('http://rubygems.org/login')).length)
|
373
395
|
|
374
396
|
# Expire the first cookie
|
375
397
|
@jar.add(url, Mechanize::Cookie.new(
|
@@ -384,7 +406,7 @@ class TestMechanizeCookieJar < Mechanize::TestCase
|
|
384
406
|
|
385
407
|
def test_session_cookies
|
386
408
|
values = cookie_values(:expires => nil)
|
387
|
-
url = URI 'http://
|
409
|
+
url = URI 'http://rubygems.org/'
|
388
410
|
|
389
411
|
# Add one cookie with an expiration date in the future
|
390
412
|
cookie = Mechanize::Cookie.new(values)
|
@@ -396,7 +418,7 @@ class TestMechanizeCookieJar < Mechanize::TestCase
|
|
396
418
|
assert_equal(2, @jar.cookies(url).length)
|
397
419
|
|
398
420
|
# Make sure we can get the cookie from different paths
|
399
|
-
assert_equal(2, @jar.cookies(URI('http://
|
421
|
+
assert_equal(2, @jar.cookies(URI('http://rubygems.org/login')).length)
|
400
422
|
|
401
423
|
# Expire the first cookie
|
402
424
|
@jar.add(url, Mechanize::Cookie.new(values.merge(:expires => Time.now - (10 * 86400))))
|
@@ -409,7 +431,7 @@ class TestMechanizeCookieJar < Mechanize::TestCase
|
|
409
431
|
|
410
432
|
# When given a URI with a blank path, CookieJar#cookies should return
|
411
433
|
# cookies with the path '/':
|
412
|
-
url = URI 'http://
|
434
|
+
url = URI 'http://rubygems.org'
|
413
435
|
assert_equal '', url.path
|
414
436
|
assert_equal(0, @jar.cookies(url).length)
|
415
437
|
# Now add a cookie with the path set to '/':
|
@@ -420,7 +442,7 @@ class TestMechanizeCookieJar < Mechanize::TestCase
|
|
420
442
|
|
421
443
|
def test_paths
|
422
444
|
values = cookie_values(:path => "/login", :expires => nil)
|
423
|
-
url = URI 'http://
|
445
|
+
url = URI 'http://rubygems.org/login'
|
424
446
|
|
425
447
|
# Add one cookie with an expiration date in the future
|
426
448
|
cookie = Mechanize::Cookie.new(values)
|
@@ -432,8 +454,8 @@ class TestMechanizeCookieJar < Mechanize::TestCase
|
|
432
454
|
assert_equal(2, @jar.cookies(url).length)
|
433
455
|
|
434
456
|
# Make sure we don't get the cookie in a different path
|
435
|
-
assert_equal(0, @jar.cookies(URI('http://
|
436
|
-
assert_equal(0, @jar.cookies(URI('http://
|
457
|
+
assert_equal(0, @jar.cookies(URI('http://rubygems.org/hello')).length)
|
458
|
+
assert_equal(0, @jar.cookies(URI('http://rubygems.org/')).length)
|
437
459
|
|
438
460
|
# Expire the first cookie
|
439
461
|
@jar.add(url, Mechanize::Cookie.new(values.merge( :expires => Time.now - (10 * 86400))))
|
@@ -446,7 +468,7 @@ class TestMechanizeCookieJar < Mechanize::TestCase
|
|
446
468
|
end
|
447
469
|
|
448
470
|
def test_save_and_read_cookiestxt
|
449
|
-
url = URI 'http://
|
471
|
+
url = URI 'http://rubygems.org/'
|
450
472
|
|
451
473
|
# Add one cookie with an expiration date in the future
|
452
474
|
cookie = Mechanize::Cookie.new(cookie_values)
|
@@ -465,7 +487,7 @@ class TestMechanizeCookieJar < Mechanize::TestCase
|
|
465
487
|
end
|
466
488
|
|
467
489
|
def test_save_and_read_cookiestxt_with_session_cookies
|
468
|
-
url = URI 'http://
|
490
|
+
url = URI 'http://rubygems.org/'
|
469
491
|
|
470
492
|
@jar.add(url, Mechanize::Cookie.new(cookie_values(:expires => nil)))
|
471
493
|
|
@@ -479,10 +501,41 @@ class TestMechanizeCookieJar < Mechanize::TestCase
|
|
479
501
|
assert_equal(0, @jar.cookies(url).length)
|
480
502
|
end
|
481
503
|
|
504
|
+
def test_prevent_command_injection_when_saving
|
505
|
+
skip if windows?
|
506
|
+
url = URI 'http://rubygems.org/'
|
507
|
+
path = '| ruby -rfileutils -e \'FileUtils.touch("vul.txt")\''
|
508
|
+
|
509
|
+
@jar.add(url, Mechanize::Cookie.new(cookie_values))
|
510
|
+
|
511
|
+
in_tmpdir do
|
512
|
+
@jar.save_as(path, :cookiestxt)
|
513
|
+
assert_equal(false, File.exist?('vul.txt'))
|
514
|
+
end
|
515
|
+
end
|
516
|
+
|
517
|
+
def test_prevent_command_injection_when_loading
|
518
|
+
skip if windows?
|
519
|
+
url = URI 'http://rubygems.org/'
|
520
|
+
path = '| ruby -rfileutils -e \'FileUtils.touch("vul.txt")\''
|
521
|
+
|
522
|
+
@jar.add(url, Mechanize::Cookie.new(cookie_values))
|
523
|
+
|
524
|
+
in_tmpdir do
|
525
|
+
@jar.save_as("cookies.txt", :cookiestxt)
|
526
|
+
@jar.clear!
|
527
|
+
|
528
|
+
assert_raises Errno::ENOENT do
|
529
|
+
@jar.load(path, :cookiestxt)
|
530
|
+
end
|
531
|
+
assert_equal(false, File.exist?('vul.txt'))
|
532
|
+
end
|
533
|
+
end
|
534
|
+
|
482
535
|
def test_save_and_read_expired_cookies
|
483
|
-
url = URI 'http://
|
536
|
+
url = URI 'http://rubygems.org/'
|
484
537
|
|
485
|
-
@jar.jar['
|
538
|
+
@jar.jar['rubygems.org'] = {}
|
486
539
|
|
487
540
|
|
488
541
|
@jar.add url, Mechanize::Cookie.new(cookie_values)
|
@@ -494,7 +547,7 @@ class TestMechanizeCookieJar < Mechanize::TestCase
|
|
494
547
|
# thanks to michal "ocher" ochman for reporting the bug responsible for this test.
|
495
548
|
values = cookie_values(:expires => nil)
|
496
549
|
values_ssl = values.merge(:name => 'Baz', :domain => "#{values[:domain]}:443")
|
497
|
-
url = URI 'https://
|
550
|
+
url = URI 'https://rubygems.org/login'
|
498
551
|
|
499
552
|
cookie = Mechanize::Cookie.new(values)
|
500
553
|
@jar.add(url, cookie)
|
@@ -506,8 +559,8 @@ class TestMechanizeCookieJar < Mechanize::TestCase
|
|
506
559
|
end
|
507
560
|
|
508
561
|
def test_secure_cookie
|
509
|
-
nurl = URI 'http://
|
510
|
-
surl = URI 'https://
|
562
|
+
nurl = URI 'http://rubygems.org/login'
|
563
|
+
surl = URI 'https://rubygems.org/login'
|
511
564
|
|
512
565
|
ncookie = Mechanize::Cookie.new(cookie_values(:name => 'Foo1'))
|
513
566
|
scookie = Mechanize::Cookie.new(cookie_values(:name => 'Foo2', :secure => true))
|
@@ -522,10 +575,10 @@ class TestMechanizeCookieJar < Mechanize::TestCase
|
|
522
575
|
end
|
523
576
|
|
524
577
|
def test_save_cookies_cookiestxt_subdomain
|
525
|
-
top_url = URI 'http://
|
526
|
-
subdomain_url = URI 'http://admin.
|
578
|
+
top_url = URI 'http://rubygems.org/'
|
579
|
+
subdomain_url = URI 'http://admin.rubygems.org/'
|
527
580
|
|
528
|
-
# cookie1 is for *.
|
581
|
+
# cookie1 is for *.rubygems.org; cookie2 is only for rubygems.org, no subdomains
|
529
582
|
cookie1 = Mechanize::Cookie.new(cookie_values)
|
530
583
|
cookie2 = Mechanize::Cookie.new(cookie_values(:name => 'Boo', :for_domain => false))
|
531
584
|
|
@@ -551,8 +604,8 @@ class TestMechanizeCookieJar < Mechanize::TestCase
|
|
551
604
|
# * Cookies that match subdomains may have a leading dot, and must have
|
552
605
|
# TRUE as the second field.
|
553
606
|
cookies_txt = File.readlines("cookies.txt")
|
554
|
-
assert_equal(1, cookies_txt.grep( /^
|
555
|
-
assert_equal(1, cookies_txt.grep( /^\.
|
607
|
+
assert_equal(1, cookies_txt.grep( /^rubygems\.org\tFALSE/ ).length)
|
608
|
+
assert_equal(1, cookies_txt.grep( /^\.rubygems\.org\tTRUE/ ).length)
|
556
609
|
end
|
557
610
|
|
558
611
|
assert_equal(2, @jar.cookies(top_url).length)
|