httpclient 2.3.0.1 → 2.8.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +85 -0
  3. data/bin/httpclient +18 -6
  4. data/bin/jsonclient +85 -0
  5. data/lib/http-access2.rb +1 -1
  6. data/lib/httpclient.rb +262 -88
  7. data/lib/httpclient/auth.rb +269 -244
  8. data/lib/httpclient/cacert.pem +3952 -0
  9. data/lib/httpclient/cacert1024.pem +3866 -0
  10. data/lib/httpclient/connection.rb +1 -1
  11. data/lib/httpclient/cookie.rb +161 -514
  12. data/lib/httpclient/http.rb +57 -21
  13. data/lib/httpclient/include_client.rb +2 -0
  14. data/lib/httpclient/jruby_ssl_socket.rb +588 -0
  15. data/lib/httpclient/session.rb +259 -317
  16. data/lib/httpclient/ssl_config.rb +141 -188
  17. data/lib/httpclient/ssl_socket.rb +150 -0
  18. data/lib/httpclient/timeout.rb +1 -1
  19. data/lib/httpclient/util.rb +62 -1
  20. data/lib/httpclient/version.rb +1 -1
  21. data/lib/httpclient/webagent-cookie.rb +459 -0
  22. data/lib/jsonclient.rb +63 -0
  23. data/lib/oauthclient.rb +2 -1
  24. data/sample/jsonclient.rb +67 -0
  25. data/sample/oauth_twitter.rb +4 -4
  26. data/test/{ca-chain.cert → ca-chain.pem} +0 -0
  27. data/test/client-pass.key +18 -0
  28. data/test/helper.rb +10 -8
  29. data/test/jruby_ssl_socket/test_pemutils.rb +32 -0
  30. data/test/test_auth.rb +175 -4
  31. data/test/test_cookie.rb +147 -243
  32. data/test/test_http-access2.rb +17 -16
  33. data/test/test_httpclient.rb +458 -77
  34. data/test/test_jsonclient.rb +80 -0
  35. data/test/test_ssl.rb +341 -17
  36. data/test/test_webagent-cookie.rb +465 -0
  37. metadata +57 -55
  38. data/README.txt +0 -721
  39. data/lib/httpclient/cacert.p7s +0 -1858
  40. data/lib/httpclient/cacert_sha1.p7s +0 -1858
  41. data/sample/oauth_salesforce_10.rb +0 -63
@@ -1,131 +1,20 @@
1
1
  require 'test/unit'
2
2
  require 'uri'
3
+ require 'tempfile'
3
4
 
5
+ require 'httpclient/util'
4
6
  require 'httpclient/cookie'
5
7
 
6
8
  class TestCookie < Test::Unit::TestCase
7
9
  include HTTPClient::Util
8
10
 
9
11
  def setup()
10
- @c = WebAgent::Cookie.new()
12
+ @c = WebAgent::Cookie.new('hoge', 'funi')
11
13
  end
12
14
 
13
15
  def test_s_new()
14
16
  assert_instance_of(WebAgent::Cookie, @c)
15
17
  end
16
-
17
- def test_discard?
18
- assert_equal(false, !!(@c.discard?))
19
- @c.discard = true
20
- assert_equal(true, !!(@c.discard?))
21
- end
22
-
23
- def test_match()
24
- url = urify('http://www.rubycolor.org/hoge/funi/#919191')
25
-
26
- @c.domain = 'www.rubycolor.org'
27
- assert_equal(true, @c.match?(url))
28
-
29
- @c.domain = '.rubycolor.org'
30
- assert_equal(true, @c.match?(url))
31
-
32
- @c.domain = 'aaa.www.rubycolor.org'
33
- assert_equal(false, @c.match?(url))
34
-
35
- @c.domain = 'aaa.www.rubycolor.org'
36
- assert_equal(false, @c.match?(url))
37
-
38
- @c.domain = 'www.rubycolor.org'
39
- @c.path = '/'
40
- assert_equal(true, @c.match?(url))
41
-
42
- @c.domain = 'www.rubycolor.org'
43
- @c.path = '/hoge'
44
- assert_equal(true, @c.match?(url))
45
-
46
- @c.domain = 'www.rubycolor.org'
47
- @c.path = '/hoge/hoge'
48
- assert_equal(false, @c.match?(url))
49
-
50
- @c.domain = 'www.rubycolor.org'
51
- @c.path = '/hoge'
52
- @c.secure = true
53
- assert_equal(false, @c.match?(url))
54
-
55
- url2 = urify('https://www.rubycolor.org/hoge/funi/#919191')
56
- @c.domain = 'www.rubycolor.org'
57
- @c.path = '/hoge'
58
- @c.secure = true
59
- assert_equal(true, @c.match?(url2))
60
-
61
- @c.domain = 'www.rubycolor.org'
62
- @c.path = '/hoge'
63
- @c.secure = nil
64
- assert_equal(true, @c.match?(url2)) ## not false!
65
-
66
- url.port = 80
67
- @c.domain = 'www.rubycolor.org'
68
- @c.path = '/hoge'
69
- # @c.port = [80,8080]
70
- assert_equal(true, @c.match?(url))
71
-
72
- url_nopath = URI.parse('http://www.rubycolor.org')
73
- @c.domain = 'www.rubycolor.org'
74
- @c.path = '/'
75
- assert_equal(true, @c.match?(url_nopath))
76
-
77
- end
78
-
79
- def test_head_match?()
80
- assert_equal(true, @c.head_match?("",""))
81
- assert_equal(false, @c.head_match?("a",""))
82
- assert_equal(true, @c.head_match?("","a"))
83
- assert_equal(true, @c.head_match?("abcde","abcde"))
84
- assert_equal(true, @c.head_match?("abcde","abcdef"))
85
- assert_equal(false, @c.head_match?("abcdef","abcde"))
86
- assert_equal(false, @c.head_match?("abcde","bcde"))
87
- assert_equal(false, @c.head_match?("bcde","abcde"))
88
- end
89
-
90
- def test_tail_match?()
91
- assert_equal(true, @c.tail_match?("",""))
92
- assert_equal(false, @c.tail_match?("a",""))
93
- assert_equal(true, @c.tail_match?("","a"))
94
- assert_equal(true, @c.tail_match?("abcde","abcde"))
95
- assert_equal(false, @c.tail_match?("abcde","abcdef"))
96
- assert_equal(false, @c.tail_match?("abcdef","abcde"))
97
- assert_equal(false, @c.tail_match?("abcde","bcde"))
98
- assert_equal(true, @c.tail_match?("bcde","abcde"))
99
- end
100
-
101
-
102
- def test_domain_match()
103
- extend WebAgent::CookieUtils
104
- assert_equal(true, !!domain_match("hoge.co.jp","."))
105
- # assert_equal(true, !!domain_match("locahost",".local"))
106
- assert_equal(true, !!domain_match("192.168.10.1","192.168.10.1"))
107
- assert_equal(false, !!domain_match("192.168.10.1","192.168.10.2"))
108
- # assert_equal(false, !!domain_match("hoge.co.jp",".hoge.co.jp"))
109
- # allows; host == rubyforge.org, domain == .rubyforge.org
110
- assert_equal(true, !!domain_match("hoge.co.jp",".hoge.co.jp"))
111
- assert_equal(true, !!domain_match("www.hoge.co.jp", "www.hoge.co.jp"))
112
- assert_equal(false, !!domain_match("www.hoge.co.jp", "www2.hoge.co.jp"))
113
- assert_equal(true, !!domain_match("www.hoge.co.jp", ".hoge.co.jp"))
114
- assert_equal(true, !!domain_match("www.aa.hoge.co.jp", ".hoge.co.jp"))
115
- assert_equal(false, !!domain_match("www.hoge.co.jp", "hoge.co.jp"))
116
- end
117
-
118
- def test_join_quotedstr()
119
- arr1 = ['hoge=funi', 'hoge2=funi2']
120
- assert_equal(arr1, @c.instance_eval{join_quotedstr(arr1,';')})
121
- arr2 = ['hoge="fu', 'ni"', 'funi=funi']
122
- assert_equal(['hoge="fu;ni"','funi=funi'],
123
- @c.instance_eval{join_quotedstr(arr2,';')})
124
- arr3 = ['hoge="funi";hoge2="fu','ni2";hoge3="hoge"', 'funi="funi"']
125
- assert_equal(['hoge="funi";hoge2="fu,ni2";hoge3="hoge"', 'funi="funi"'],
126
- @c.instance_eval{join_quotedstr(arr3,',')})
127
- end
128
-
129
18
  end
130
19
 
131
20
  class TestCookieManager < Test::Unit::TestCase
@@ -137,29 +26,15 @@ class TestCookieManager < Test::Unit::TestCase
137
26
 
138
27
  def teardown()
139
28
  end
140
-
141
- def test_total_dot_num()
142
- assert_equal(0, @cm.total_dot_num(""))
143
- assert_equal(0, @cm.total_dot_num("abcde"))
144
- assert_equal(1, @cm.total_dot_num("ab.cde"))
145
- assert_equal(1, @cm.total_dot_num(".abcde"))
146
- assert_equal(1, @cm.total_dot_num("abcde."))
147
- assert_equal(2, @cm.total_dot_num("abc.de."))
148
- assert_equal(2, @cm.total_dot_num("a.bc.de"))
149
- assert_equal(2, @cm.total_dot_num(".abcde."))
150
- assert_equal(3, @cm.total_dot_num(".a.bcde."))
151
- assert_equal(3, @cm.total_dot_num("a.b.cde."))
152
- assert_equal(3, @cm.total_dot_num("a.b.c.de"))
153
- end
154
29
 
155
30
  def test_parse()
156
- str = "inkid=n92b0ADOgACIgUb9lsjHqAAAHu2a; expires=Wed, 01-Dec-2010 00:00:00 GMT; path=/"
31
+ str = "inkid=n92b0ADOgACIgUb9lsjHqAAAHu2a; expires=Wed, 01-Dec-2999 00:00:00 GMT; path=/"
157
32
  @cm.parse(str, urify('http://www.test.jp'))
158
33
  cookie = @cm.cookies[0]
159
34
  assert_instance_of(WebAgent::Cookie, cookie)
160
35
  assert_equal("inkid", cookie.name)
161
36
  assert_equal("n92b0ADOgACIgUb9lsjHqAAAHu2a", cookie.value)
162
- assert_equal(Time.gm(2010, 12, 1, 0,0,0), cookie.expires)
37
+ assert_equal(Time.gm(2999, 12, 1, 0,0,0), cookie.expires)
163
38
  assert_equal("/", cookie.path)
164
39
  end
165
40
 
@@ -171,7 +46,8 @@ class TestCookieManager < Test::Unit::TestCase
171
46
  assert_equal("xmen", cookie.name)
172
47
  assert_equal("off,0,0,1", cookie.value)
173
48
  assert_equal("/", cookie.path)
174
- assert_equal(".excite.co.jp", cookie.domain)
49
+ assert_equal("excite.co.jp", cookie.domain)
50
+ assert_equal(".excite.co.jp", cookie.dot_domain)
175
51
  assert_equal(Time.gm(2037,12,31,12,0,0), cookie.expires)
176
52
  end
177
53
 
@@ -183,7 +59,8 @@ class TestCookieManager < Test::Unit::TestCase
183
59
  assert_equal("xmen", cookie.name)
184
60
  assert_equal("off,0,0,1", cookie.value)
185
61
  assert_equal("/", cookie.path)
186
- assert_equal(".excite.co.jp", cookie.domain)
62
+ assert_equal("excite.co.jp", cookie.domain)
63
+ assert_equal(".excite.co.jp", cookie.dot_domain)
187
64
  assert_equal(Time.gm(2037,12,31,12,0,0), cookie.expires)
188
65
  assert_equal(true, cookie.secure?)
189
66
  assert_equal(true, cookie.http_only?)
@@ -197,7 +74,8 @@ class TestCookieManager < Test::Unit::TestCase
197
74
  assert_equal("xmen", cookie.name)
198
75
  assert_equal("off,0,0,1", cookie.value)
199
76
  assert_equal("/;;", cookie.path)
200
- assert_equal(".excite.co.jp", cookie.domain)
77
+ assert_equal("excite.co.jp", cookie.domain)
78
+ assert_equal(".excite.co.jp", cookie.dot_domain)
201
79
  assert_equal(Time.gm(2037,12,31,12,0,0), cookie.expires)
202
80
  end
203
81
 
@@ -208,19 +86,21 @@ class TestCookieManager < Test::Unit::TestCase
208
86
  # end
209
87
 
210
88
  def test_check_expired_cookies()
211
- c1 = WebAgent::Cookie.new()
212
- c2 = c1.dup
213
- c3 = c1.dup
214
- c4 = c1.dup
215
- c1.expires = Time.now - 100
216
- c2.expires = Time.now + 100
217
- c3.expires = Time.now - 10
89
+ format = "%a, %d-%b-%Y %H:%M:%S GMT"
90
+ c1 = WebAgent::Cookie.new('hoge1', 'funi', :domain => 'http://www.example.com/', :path => '/')
91
+ c2 = WebAgent::Cookie.new('hoge2', 'funi', :domain => 'http://www.example.com/', :path => '/')
92
+ c3 = WebAgent::Cookie.new('hoge3', 'funi', :domain => 'http://www.example.com/', :path => '/')
93
+ c4 = WebAgent::Cookie.new('hoge4', 'funi', :domain => 'http://www.example.com/', :path => '/')
94
+ c1.expires = (Time.now - 100).gmtime.strftime(format)
95
+ c2.expires = (Time.now + 100).gmtime.strftime(format)
96
+ c3.expires = (Time.now - 10).gmtime.strftime(format)
218
97
  c4.expires = nil
219
98
  cookies = [c1,c2,c3,c4]
220
99
  @cm.cookies = cookies
221
- @cm.check_expired_cookies()
222
- # expires == nil cookies (session cookie) exists.
223
- assert_equal([c2,c4], @cm.cookies)
100
+ assert_equal(c2.name, @cm.cookies[0].name)
101
+ assert_equal(c2.expires, @cm.cookies[0].expires)
102
+ assert_equal(c4.name, @cm.cookies[1].name)
103
+ assert_equal(c4.expires, @cm.cookies[1].expires)
224
104
  end
225
105
 
226
106
  def test_parse_expires
@@ -249,6 +129,27 @@ class TestCookieManager < Test::Unit::TestCase
249
129
  assert_equal("/", cookie.path)
250
130
  end
251
131
 
132
+ def test_parse_after_expiration
133
+ str = "inkid=n92b0ADOgACIgUb9lsjHqAAAHu2a; expires=Wed, 01-Dec-2999 00:00:00 GMT; path=/"
134
+ @cm.parse(str, urify('http://www.test.jp'))
135
+ cookie = @cm.cookies[0]
136
+ assert_instance_of(WebAgent::Cookie, cookie)
137
+ assert_equal("inkid", cookie.name)
138
+ assert_equal("n92b0ADOgACIgUb9lsjHqAAAHu2a", cookie.value)
139
+ assert_equal(Time.gm(2999, 12, 1, 0,0,0), cookie.expires)
140
+ assert_equal("/", cookie.path)
141
+
142
+ time = Time.at(Time.now.to_i + 60).utc
143
+ expires = time.strftime("%a, %d-%b-%Y %H:%M:%S GMT")
144
+ str = "inkid=n92b0ADOgACIgUb9lsjHqAAAHu2a; expires=#{expires}; path=/"
145
+ @cm.parse(str, urify('http://www.test.jp'))
146
+ cookie = @cm.cookies[0]
147
+ assert_equal("inkid", cookie.name)
148
+ assert_equal("n92b0ADOgACIgUb9lsjHqAAAHu2a", cookie.value)
149
+ assert_equal(time, cookie.expires)
150
+ assert_equal("/", cookie.path)
151
+ end
152
+
252
153
  def test_find_cookie()
253
154
  str = "xmen=off,0,0,1; path=/; domain=.excite2.co.jp; expires=Wednesday, 31-Dec-2037 12:00:00 GMT"
254
155
  @cm.parse(str, urify("http://www.excite2.co.jp/"))
@@ -256,49 +157,43 @@ class TestCookieManager < Test::Unit::TestCase
256
157
  str = "xmen=off,0,0,2; path=/; domain=.excite.co.jp; expires=Wednesday, 31-Dec-2037 12:00:00 GMT"
257
158
  @cm.parse(str, urify("http://www.excite.co.jp/"))
258
159
 
259
- @cm.cookies[0].use = true
260
- @cm.cookies[1].use = true
261
-
262
160
  url = urify('http://www.excite.co.jp/hoge/funi/')
263
161
  cookie_str = @cm.find(url)
264
- assert_equal("xmen=off,0,0,2", cookie_str)
162
+ assert_equal("xmen=\"off,0,0,2\"", cookie_str)
265
163
  end
266
164
 
267
165
  def test_load_cookies()
268
- begin
269
- File.open("tmp_test.tmp","w") {|f|
270
- f.write <<EOF
166
+ cookiefile = Tempfile.new('test_cookie')
167
+ File.open(cookiefile.path, 'w') do |f|
168
+ f.write <<EOF
271
169
  http://www.zdnet.co.jp/news/0106/08/e_gibson.html NGUserID d29b8f49-10875-992421294-1 2145801600 www.zdnet.co.jp / 9 0
272
- http://www.zdnet.co.jp/news/0106/08/e_gibson.html PACK zd3-992421294-7436 1293839999 .zdnet.co.jp / 13 0
170
+ http://www.zdnet.co.jp/news/0106/08/e_gibson.html PACK zd3-992421294-7436 2293839999 .zdnet.co.jp / 13 0
273
171
  http://example.org/ key value 0 .example.org / 13 0
274
172
  http://example.org/ key value .example.org / 13 0
275
173
  EOF
276
- }
277
-
278
- @cm.cookies_file = 'tmp_test.tmp'
279
- @cm.load_cookies()
280
- c0, c1, c2, c3 = @cm.cookies
281
- assert_equal('http://www.zdnet.co.jp/news/0106/08/e_gibson.html', c0.url.to_s)
282
- assert_equal('NGUserID', c0.name)
283
- assert_equal('d29b8f49-10875-992421294-1', c0.value)
284
- assert_equal(Time.at(2145801600), c0.expires)
285
- assert_equal('www.zdnet.co.jp', c0.domain)
286
- assert_equal('/', c0.path)
287
- assert_equal(9, c0.flag)
288
- #
289
- assert_equal('http://www.zdnet.co.jp/news/0106/08/e_gibson.html', c1.url.to_s)
290
- assert_equal('PACK', c1.name)
291
- assert_equal('zd3-992421294-7436', c1.value)
292
- assert_equal(Time.at(1293839999), c1.expires)
293
- assert_equal('.zdnet.co.jp', c1.domain)
294
- assert_equal('/', c1.path)
295
- assert_equal(13, c1.flag)
296
- #
297
- assert_equal(nil, c2.expires)
298
- assert_equal(nil, c3.expires) # allow empty 'expires' (should not happen)
299
- ensure
300
- File.unlink("tmp_test.tmp")
301
174
  end
175
+
176
+ @cm.cookies_file = cookiefile.path
177
+ @cm.load_cookies()
178
+ c0, c1, c2 = @cm.cookies
179
+ assert_equal('http://www.zdnet.co.jp/news/0106/08/e_gibson.html', c0.url.to_s)
180
+ assert_equal('NGUserID', c0.name)
181
+ assert_equal('d29b8f49-10875-992421294-1', c0.value)
182
+ assert_equal(Time.at(2145801600), c0.expires)
183
+ assert_equal('www.zdnet.co.jp', c0.domain)
184
+ assert_equal('/', c0.path)
185
+ assert_equal(9, c0.flag)
186
+ #
187
+ assert_equal('http://www.zdnet.co.jp/news/0106/08/e_gibson.html', c1.url.to_s)
188
+ assert_equal('PACK', c1.name)
189
+ assert_equal('zd3-992421294-7436', c1.value)
190
+ assert_equal(Time.at(2293839999), c1.expires)
191
+ assert_equal('zdnet.co.jp', c1.domain)
192
+ assert_equal('.zdnet.co.jp', c1.dot_domain)
193
+ assert_equal('/', c1.path)
194
+ assert_equal(13, c1.flag)
195
+ #
196
+ assert_equal(nil, c2.expires)
302
197
  end
303
198
 
304
199
  def test_save_cookie()
@@ -306,56 +201,44 @@ EOF
306
201
  http://www.zdnet.co.jp/news/0106/08/e_gibson.html NGUserID d29b8f49-10875-992421294-1 2145801600 www.zdnet.co.jp / 9
307
202
  http://www.zdnet.co.jp/news/0106/08/e_gibson.html PACK zd3-992421294-7436 2145801600 .zdnet.co.jp / 13
308
203
  EOF
309
- begin
310
- File.open("tmp_test.tmp","w") {|f|
311
- f.write str
312
- }
313
- @cm.cookies_file = 'tmp_test.tmp'
314
- @cm.load_cookies()
315
- @cm.instance_eval{@is_saved = false}
316
- @cm.cookies_file = 'tmp_test2.tmp'
317
- @cm.save_cookies()
318
- str2 = ''
319
- File.open("tmp_test2.tmp","r") {|f|
320
- str2 = f.read()
321
- }
322
- assert_equal(str, str2)
323
- #
324
- assert(File.exist?('tmp_test2.tmp'))
325
- File.unlink("tmp_test2.tmp")
326
- @cm.save_cookies()
327
- assert(!File.exist?('tmp_test2.tmp'))
328
- @cm.save_cookies(true)
329
- assert(File.exist?('tmp_test2.tmp'))
330
- ensure
331
- File.unlink("tmp_test.tmp")
332
- if FileTest.exist?("tmp_test2.tmp")
333
- File.unlink("tmp_test2.tmp")
334
- end
204
+ cookiefile = Tempfile.new('test_cookie')
205
+ cookiefile2 = Tempfile.new('test_cookie2')
206
+ File.open(cookiefile.path, 'w') do |f|
207
+ f.write str
335
208
  end
209
+
210
+ @cm.cookies_file = cookiefile.path
211
+ @cm.load_cookies()
212
+ @cm.instance_eval{@is_saved = false}
213
+ @cm.cookies_file = cookiefile2.path
214
+ @cm.save_cookies()
215
+ str2 = ''
216
+ File.open(cookiefile2.path, 'r') do |f|
217
+ str2 = f.read
218
+ end
219
+ assert_equal(str.split.sort, str2.split.sort)
220
+ assert(File.exist?(cookiefile2.path))
221
+ File.unlink(cookiefile2.path)
222
+ @cm.save_cookies()
223
+ assert(File.exist?(cookiefile2.path))
336
224
  end
337
225
 
338
226
  def test_not_saved_expired_cookies
339
- begin
340
- @cm.cookies_file = 'tmp_test.tmp'
341
- uri = urify('http://www.example.org')
342
- @cm.parse("foo=1; path=/", uri)
343
- @cm.parse("bar=2; path=/; expires=", uri)
344
- @cm.parse("baz=3; path=/; expires=\"\"", uri)
345
- @cm.parse("qux=4; path=/; expires=#{(Time.now + 10).asctime}", uri)
346
- @cm.parse("quxx=5; path=/; expires=#{(Time.now - 10).asctime}", uri)
347
- @cm.save_cookies()
348
- @cm.load_cookies
349
- assert_equal(1, @cm.cookies.size) # +10 cookies only
350
- ensure
351
- File.unlink("tmp_test.tmp") if File.exist?("tmp_test.tmp")
352
- end
227
+ cookiefile = Tempfile.new('test_cookie')
228
+ @cm.cookies_file = cookiefile.path
229
+ uri = urify('http://www.example.org')
230
+ @cm.parse("foo=1; path=/", uri)
231
+ @cm.parse("bar=2; path=/; expires=", uri)
232
+ @cm.parse("baz=3; path=/; expires=\"\"", uri)
233
+ @cm.parse("qux=4; path=/; expires=#{(Time.now.gmtime + 10).asctime}", uri)
234
+ @cm.parse("quxx=5; path=/; expires=#{(Time.now.gmtime - 10).asctime}", uri)
235
+ @cm.save_cookies
236
+ @cm.load_cookies
237
+ assert_equal(1, @cm.cookies.size) # +10 cookies only
353
238
  end
354
239
 
355
240
  def test_add()
356
- c = WebAgent::Cookie.new()
357
- c.name = "hoge"
358
- c.value = "funi"
241
+ c = WebAgent::Cookie.new('hoge', 'funi')
359
242
  c.url = urify("http://www.inac.co.jp/hoge")
360
243
  @cm.add(c)
361
244
  c = @cm.cookies[0]
@@ -365,41 +248,62 @@ EOF
365
248
  end
366
249
 
367
250
  def test_add2()
368
- c = WebAgent::Cookie.new()
369
- c.name = "hoge"
370
- c.value = "funi"
251
+ c = WebAgent::Cookie.new('hoge', 'funi')
371
252
  c.path = ''
372
253
  c.url = urify("http://www.inac.co.jp/hoge/hoge2/hoge3")
373
254
  @cm.add(c)
374
255
  #
375
- c = WebAgent::Cookie.new()
376
- c.name = "hoge"
377
- c.value = "funi"
256
+ c = WebAgent::Cookie.new('hoge', 'funi')
378
257
  #c.path = '' NO path given -> same as URL
379
258
  c.url = urify("http://www.inac.co.jp/hoge/hoge2/hoge3")
380
259
  @cm.add(c)
381
260
  #
382
261
  c1, c2 = @cm.cookies
383
- assert_equal('', c1.path)
384
- assert_equal('/hoge/hoge2', c2.path)
262
+ assert_equal('/hoge/hoge2/', c1.path)
263
+ assert_equal('/', c2.path)
264
+ end
265
+
266
+ def test_keep_escaped
267
+ uri = urify('http://www.example.org')
268
+
269
+ @cm.parse("bar=2; path=/", uri)
270
+ c = @cm.cookies.first
271
+ assert_equal('2', c.value)
272
+ assert_equal('bar=2', @cm.find(uri))
273
+
274
+ @cm.parse("bar=\"2\"; path=/", uri)
275
+ c = @cm.cookies.first
276
+ assert_equal('2', c.value)
277
+ assert_equal('bar=2', @cm.find(uri))
278
+
279
+ @cm.parse("bar=; path=/", uri)
280
+ c = @cm.cookies.first
281
+ assert_equal('', c.value)
282
+ assert_equal('bar=', @cm.find(uri))
283
+
284
+ @cm.parse("bar=\"\"; path=/", uri)
285
+ c = @cm.cookies.first
286
+ assert_equal('', c.value)
287
+ assert_equal('bar=', @cm.find(uri))
385
288
  end
386
289
 
387
- def test_check_cookie_accept_domain()
388
- @cm.accept_domains = [".example1.co.jp", "www1.example.jp"]
389
- @cm.reject_domains = [".example2.co.jp", "www2.example.jp"]
390
- check1 = @cm.check_cookie_accept_domain("www.example1.co.jp")
391
- assert_equal(true, check1)
392
- check2 = @cm.check_cookie_accept_domain("www.example2.co.jp")
393
- assert_equal(false, check2)
394
- check3 = @cm.check_cookie_accept_domain("www1.example.jp")
395
- assert_equal(true, check3)
396
- check4 = @cm.check_cookie_accept_domain("www2.example.jp")
397
- assert_equal(false, check4)
398
- check5 = @cm.check_cookie_accept_domain("aa.www2.example.jp")
399
- assert_equal(true, check5)
400
- check6 = @cm.check_cookie_accept_domain("aa.www2.example.jp")
401
- assert_equal(true, check6)
402
- assert_equal(false, @cm.check_cookie_accept_domain(nil))
290
+ def test_load_cookies_escaped
291
+ uri = urify('http://example.org/')
292
+ f = Tempfile.new('test_cookie')
293
+ File.open(f.path, 'w') do |out|
294
+ out.write <<EOF
295
+ http://example.org/ key1 "value" 0 .example.org / 13 0
296
+ http://example.org/ key2 "" 0 .example.org / 13 0
297
+ http://example.org/ key3 0 .example.org / 13 0
298
+ EOF
299
+ end
300
+ @cm.cookies_file = f.path
301
+ @cm.load_cookies
302
+ c0, c1, c2 = @cm.cookies
303
+ assert_equal('"value"', c0.value)
304
+ assert_equal('""', c1.value)
305
+ assert_equal('', c2.value)
306
+ assert_equal('key1="\\"value\\""; key2="\\"\\""; key3=', @cm.find(uri))
403
307
  end
404
308
 
405
309
  end