httpclient 2.1.5 → 2.8.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +85 -0
- data/bin/httpclient +77 -0
- data/bin/jsonclient +85 -0
- data/lib/hexdump.rb +50 -0
- data/lib/http-access2.rb +6 -4
- data/lib/httpclient/auth.rb +575 -173
- data/lib/httpclient/cacert.pem +3952 -0
- data/lib/httpclient/cacert1024.pem +3866 -0
- data/lib/httpclient/connection.rb +6 -2
- data/lib/httpclient/cookie.rb +162 -504
- data/lib/httpclient/http.rb +334 -119
- data/lib/httpclient/include_client.rb +85 -0
- data/lib/httpclient/jruby_ssl_socket.rb +588 -0
- data/lib/httpclient/session.rb +385 -288
- data/lib/httpclient/ssl_config.rb +195 -155
- data/lib/httpclient/ssl_socket.rb +150 -0
- data/lib/httpclient/timeout.rb +14 -10
- data/lib/httpclient/util.rb +142 -6
- data/lib/httpclient/version.rb +3 -0
- data/lib/httpclient/webagent-cookie.rb +459 -0
- data/lib/httpclient.rb +509 -202
- data/lib/jsonclient.rb +63 -0
- data/lib/oauthclient.rb +111 -0
- data/sample/async.rb +8 -0
- data/sample/auth.rb +11 -0
- data/sample/cookie.rb +18 -0
- data/sample/dav.rb +103 -0
- data/sample/howto.rb +49 -0
- data/sample/jsonclient.rb +67 -0
- data/sample/oauth_buzz.rb +57 -0
- data/sample/oauth_friendfeed.rb +59 -0
- data/sample/oauth_twitter.rb +61 -0
- data/sample/ssl/0cert.pem +22 -0
- data/sample/ssl/0key.pem +30 -0
- data/sample/ssl/1000cert.pem +19 -0
- data/sample/ssl/1000key.pem +18 -0
- data/sample/ssl/htdocs/index.html +10 -0
- data/sample/ssl/ssl_client.rb +22 -0
- data/sample/ssl/webrick_httpsd.rb +29 -0
- data/sample/stream.rb +21 -0
- data/sample/thread.rb +27 -0
- data/sample/wcat.rb +21 -0
- data/test/ca-chain.pem +44 -0
- data/test/ca.cert +23 -0
- data/test/client-pass.key +18 -0
- data/test/client.cert +19 -0
- data/test/client.key +15 -0
- data/test/helper.rb +131 -0
- data/test/htdigest +1 -0
- data/test/htpasswd +2 -0
- data/test/jruby_ssl_socket/test_pemutils.rb +32 -0
- data/test/runner.rb +2 -0
- data/test/server.cert +19 -0
- data/test/server.key +15 -0
- data/test/sslsvr.rb +65 -0
- data/test/subca.cert +21 -0
- data/test/test_auth.rb +492 -0
- data/test/test_cookie.rb +309 -0
- data/test/test_hexdump.rb +14 -0
- data/test/test_http-access2.rb +508 -0
- data/test/test_httpclient.rb +2145 -0
- data/test/test_include_client.rb +52 -0
- data/test/test_jsonclient.rb +80 -0
- data/test/test_ssl.rb +559 -0
- data/test/test_webagent-cookie.rb +465 -0
- metadata +85 -44
- data/lib/httpclient/auth.rb.orig +0 -513
- data/lib/httpclient/cacert.p7s +0 -1579
- data/lib/httpclient.rb.orig +0 -1020
- data/lib/tags +0 -908
@@ -0,0 +1,465 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'uri'
|
3
|
+
require 'tempfile'
|
4
|
+
|
5
|
+
# This testcase is located for reference, not for running.
|
6
|
+
if false
|
7
|
+
|
8
|
+
require 'httpclient/webagent-cookie'
|
9
|
+
|
10
|
+
class TestCookie < Test::Unit::TestCase
|
11
|
+
include HTTPClient::Util
|
12
|
+
|
13
|
+
def setup()
|
14
|
+
@c = WebAgent::Cookie.new()
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_s_new()
|
18
|
+
assert_instance_of(WebAgent::Cookie, @c)
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_discard?
|
22
|
+
assert_equal(false, !!(@c.discard?))
|
23
|
+
@c.discard = true
|
24
|
+
assert_equal(true, !!(@c.discard?))
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_match()
|
28
|
+
url = urify('http://www.rubycolor.org/hoge/funi/#919191')
|
29
|
+
|
30
|
+
@c.domain = 'www.rubycolor.org'
|
31
|
+
assert_equal(true, @c.match?(url))
|
32
|
+
|
33
|
+
@c.domain = '.rubycolor.org'
|
34
|
+
assert_equal(true, @c.match?(url))
|
35
|
+
|
36
|
+
@c.domain = 'aaa.www.rubycolor.org'
|
37
|
+
assert_equal(false, @c.match?(url))
|
38
|
+
|
39
|
+
@c.domain = 'aaa.www.rubycolor.org'
|
40
|
+
assert_equal(false, @c.match?(url))
|
41
|
+
|
42
|
+
@c.domain = 'www.rubycolor.org'
|
43
|
+
@c.path = '/'
|
44
|
+
assert_equal(true, @c.match?(url))
|
45
|
+
|
46
|
+
@c.domain = 'www.rubycolor.org'
|
47
|
+
@c.path = '/hoge'
|
48
|
+
assert_equal(true, @c.match?(url))
|
49
|
+
|
50
|
+
@c.domain = 'www.rubycolor.org'
|
51
|
+
@c.path = '/hoge/hoge'
|
52
|
+
assert_equal(false, @c.match?(url))
|
53
|
+
|
54
|
+
@c.domain = 'www.rubycolor.org'
|
55
|
+
@c.path = '/hoge'
|
56
|
+
@c.secure = true
|
57
|
+
assert_equal(false, @c.match?(url))
|
58
|
+
|
59
|
+
url2 = urify('https://www.rubycolor.org/hoge/funi/#919191')
|
60
|
+
@c.domain = 'www.rubycolor.org'
|
61
|
+
@c.path = '/hoge'
|
62
|
+
@c.secure = true
|
63
|
+
assert_equal(true, @c.match?(url2))
|
64
|
+
|
65
|
+
@c.domain = 'www.rubycolor.org'
|
66
|
+
@c.path = '/hoge'
|
67
|
+
@c.secure = nil
|
68
|
+
assert_equal(true, @c.match?(url2)) ## not false!
|
69
|
+
|
70
|
+
url.port = 80
|
71
|
+
@c.domain = 'www.rubycolor.org'
|
72
|
+
@c.path = '/hoge'
|
73
|
+
# @c.port = [80,8080]
|
74
|
+
assert_equal(true, @c.match?(url))
|
75
|
+
|
76
|
+
url_nopath = URI.parse('http://www.rubycolor.org')
|
77
|
+
@c.domain = 'www.rubycolor.org'
|
78
|
+
@c.path = '/'
|
79
|
+
assert_equal(true, @c.match?(url_nopath))
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_head_match?()
|
84
|
+
assert_equal(true, @c.head_match?("",""))
|
85
|
+
assert_equal(false, @c.head_match?("a",""))
|
86
|
+
assert_equal(true, @c.head_match?("","a"))
|
87
|
+
assert_equal(true, @c.head_match?("abcde","abcde"))
|
88
|
+
assert_equal(true, @c.head_match?("abcde","abcdef"))
|
89
|
+
assert_equal(false, @c.head_match?("abcdef","abcde"))
|
90
|
+
assert_equal(false, @c.head_match?("abcde","bcde"))
|
91
|
+
assert_equal(false, @c.head_match?("bcde","abcde"))
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_tail_match?()
|
95
|
+
assert_equal(true, @c.tail_match?("",""))
|
96
|
+
assert_equal(false, @c.tail_match?("a",""))
|
97
|
+
assert_equal(true, @c.tail_match?("","a"))
|
98
|
+
assert_equal(true, @c.tail_match?("abcde","abcde"))
|
99
|
+
assert_equal(false, @c.tail_match?("abcde","abcdef"))
|
100
|
+
assert_equal(false, @c.tail_match?("abcdef","abcde"))
|
101
|
+
assert_equal(false, @c.tail_match?("abcde","bcde"))
|
102
|
+
assert_equal(true, @c.tail_match?("bcde","abcde"))
|
103
|
+
end
|
104
|
+
|
105
|
+
|
106
|
+
def test_domain_match()
|
107
|
+
extend WebAgent::CookieUtils
|
108
|
+
assert_equal(true, !!domain_match("hoge.co.jp","."))
|
109
|
+
# assert_equal(true, !!domain_match("locahost",".local"))
|
110
|
+
assert_equal(true, !!domain_match("192.168.10.1","192.168.10.1"))
|
111
|
+
assert_equal(false, !!domain_match("192.168.10.1","192.168.10.2"))
|
112
|
+
# assert_equal(false, !!domain_match("hoge.co.jp",".hoge.co.jp"))
|
113
|
+
# allows; host == rubyforge.org, domain == .rubyforge.org
|
114
|
+
assert_equal(true, !!domain_match("hoge.co.jp",".hoge.co.jp"))
|
115
|
+
assert_equal(true, !!domain_match("www.hoge.co.jp", "www.hoge.co.jp"))
|
116
|
+
assert_equal(false, !!domain_match("www.hoge.co.jp", "www2.hoge.co.jp"))
|
117
|
+
assert_equal(true, !!domain_match("www.hoge.co.jp", ".hoge.co.jp"))
|
118
|
+
assert_equal(true, !!domain_match("www.aa.hoge.co.jp", ".hoge.co.jp"))
|
119
|
+
assert_equal(false, !!domain_match("www.hoge.co.jp", "hoge.co.jp"))
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_join_quotedstr()
|
123
|
+
arr1 = ['hoge=funi', 'hoge2=funi2']
|
124
|
+
assert_equal(arr1, @c.instance_eval{join_quotedstr(arr1,';')})
|
125
|
+
arr2 = ['hoge="fu', 'ni"', 'funi=funi']
|
126
|
+
assert_equal(['hoge="fu;ni"','funi=funi'],
|
127
|
+
@c.instance_eval{join_quotedstr(arr2,';')})
|
128
|
+
arr3 = ['hoge="funi";hoge2="fu','ni2";hoge3="hoge"', 'funi="funi"']
|
129
|
+
assert_equal(['hoge="funi";hoge2="fu,ni2";hoge3="hoge"', 'funi="funi"'],
|
130
|
+
@c.instance_eval{join_quotedstr(arr3,',')})
|
131
|
+
end
|
132
|
+
|
133
|
+
end
|
134
|
+
|
135
|
+
class TestCookieManager < Test::Unit::TestCase
|
136
|
+
include HTTPClient::Util
|
137
|
+
|
138
|
+
def setup()
|
139
|
+
@cm = WebAgent::CookieManager.new()
|
140
|
+
end
|
141
|
+
|
142
|
+
def teardown()
|
143
|
+
end
|
144
|
+
|
145
|
+
def test_parse()
|
146
|
+
str = "inkid=n92b0ADOgACIgUb9lsjHqAAAHu2a; expires=Wed, 01-Dec-2010 00:00:00 GMT; path=/"
|
147
|
+
@cm.parse(str, urify('http://www.test.jp'))
|
148
|
+
cookie = @cm.cookies[0]
|
149
|
+
assert_instance_of(WebAgent::Cookie, cookie)
|
150
|
+
assert_equal("inkid", cookie.name)
|
151
|
+
assert_equal("n92b0ADOgACIgUb9lsjHqAAAHu2a", cookie.value)
|
152
|
+
assert_equal(Time.gm(2010, 12, 1, 0,0,0), cookie.expires)
|
153
|
+
assert_equal("/", cookie.path)
|
154
|
+
end
|
155
|
+
|
156
|
+
def test_parse2()
|
157
|
+
str = "xmen=off,0,0,1; path=/; domain=.excite.co.jp; expires=Wednesday, 31-Dec-2037 12:00:00 GMT"
|
158
|
+
@cm.parse(str, urify('http://www.excite.co.jp'))
|
159
|
+
cookie = @cm.cookies[0]
|
160
|
+
assert_instance_of(WebAgent::Cookie, cookie)
|
161
|
+
assert_equal("xmen", cookie.name)
|
162
|
+
assert_equal("off,0,0,1", cookie.value)
|
163
|
+
assert_equal("/", cookie.path)
|
164
|
+
assert_equal(".excite.co.jp", cookie.domain)
|
165
|
+
assert_equal(Time.gm(2037,12,31,12,0,0), cookie.expires)
|
166
|
+
end
|
167
|
+
|
168
|
+
def test_parse3()
|
169
|
+
str = "xmen=off,0,0,1; path=/; domain=.excite.co.jp; expires=Wednesday, 31-Dec-2037 12:00:00 GMT;Secure;HTTPOnly"
|
170
|
+
@cm.parse(str, urify('http://www.excite.co.jp'))
|
171
|
+
cookie = @cm.cookies[0]
|
172
|
+
assert_instance_of(WebAgent::Cookie, cookie)
|
173
|
+
assert_equal("xmen", cookie.name)
|
174
|
+
assert_equal("off,0,0,1", cookie.value)
|
175
|
+
assert_equal("/", cookie.path)
|
176
|
+
assert_equal(".excite.co.jp", cookie.domain)
|
177
|
+
assert_equal(Time.gm(2037,12,31,12,0,0), cookie.expires)
|
178
|
+
assert_equal(true, cookie.secure?)
|
179
|
+
assert_equal(true, cookie.http_only?)
|
180
|
+
end
|
181
|
+
|
182
|
+
def test_parse_double_semicolon()
|
183
|
+
str = "xmen=off,0,0,1;; path=\"/;;\"; domain=.excite.co.jp; expires=Wednesday, 31-Dec-2037 12:00:00 GMT"
|
184
|
+
@cm.parse(str, urify('http://www.excite.co.jp'))
|
185
|
+
cookie = @cm.cookies[0]
|
186
|
+
assert_instance_of(WebAgent::Cookie, cookie)
|
187
|
+
assert_equal("xmen", cookie.name)
|
188
|
+
assert_equal("off,0,0,1", cookie.value)
|
189
|
+
assert_equal("/;;", cookie.path)
|
190
|
+
assert_equal(".excite.co.jp", cookie.domain)
|
191
|
+
assert_equal(Time.gm(2037,12,31,12,0,0), cookie.expires)
|
192
|
+
end
|
193
|
+
|
194
|
+
# def test_make_portlist()
|
195
|
+
# assert_equal([80,8080], @cm.instance_eval{make_portlist("80,8080")})
|
196
|
+
# assert_equal([80], @cm.instance_eval{make_portlist("80")})
|
197
|
+
# assert_equal([80,8080,10080], @cm.instance_eval{make_portlist(" 80, 8080, 10080 \n")})
|
198
|
+
# end
|
199
|
+
|
200
|
+
def test_check_expired_cookies()
|
201
|
+
c1 = WebAgent::Cookie.new()
|
202
|
+
c2 = c1.dup
|
203
|
+
c3 = c1.dup
|
204
|
+
c4 = c1.dup
|
205
|
+
c1.expires = Time.now - 100
|
206
|
+
c2.expires = Time.now + 100
|
207
|
+
c3.expires = Time.now - 10
|
208
|
+
c4.expires = nil
|
209
|
+
cookies = [c1,c2,c3,c4]
|
210
|
+
@cm.cookies = cookies
|
211
|
+
@cm.check_expired_cookies()
|
212
|
+
# expires == nil cookies (session cookie) exists.
|
213
|
+
assert_equal([c2,c4], @cm.cookies)
|
214
|
+
end
|
215
|
+
|
216
|
+
def test_parse_expires
|
217
|
+
str = "inkid=n92b0ADOgACIgUb9lsjHqAAAHu2a; expires=; path=/"
|
218
|
+
@cm.parse(str, urify('http://www.test.jp'))
|
219
|
+
cookie = @cm.cookies[0]
|
220
|
+
assert_equal("inkid", cookie.name)
|
221
|
+
assert_equal("n92b0ADOgACIgUb9lsjHqAAAHu2a", cookie.value)
|
222
|
+
assert_equal(nil, cookie.expires)
|
223
|
+
assert_equal("/", cookie.path)
|
224
|
+
#
|
225
|
+
str = "inkid=n92b0ADOgACIgUb9lsjHqAAAHu2a; path=/; expires="
|
226
|
+
@cm.parse(str, urify('http://www.test.jp'))
|
227
|
+
cookie = @cm.cookies[0]
|
228
|
+
assert_equal("inkid", cookie.name)
|
229
|
+
assert_equal("n92b0ADOgACIgUb9lsjHqAAAHu2a", cookie.value)
|
230
|
+
assert_equal(nil, cookie.expires)
|
231
|
+
assert_equal("/", cookie.path)
|
232
|
+
#
|
233
|
+
str = "inkid=n92b0ADOgACIgUb9lsjHqAAAHu2a; path=/; expires=\"\""
|
234
|
+
@cm.parse(str, urify('http://www.test.jp'))
|
235
|
+
cookie = @cm.cookies[0]
|
236
|
+
assert_equal("inkid", cookie.name)
|
237
|
+
assert_equal("n92b0ADOgACIgUb9lsjHqAAAHu2a", cookie.value)
|
238
|
+
assert_equal(nil, cookie.expires)
|
239
|
+
assert_equal("/", cookie.path)
|
240
|
+
end
|
241
|
+
|
242
|
+
def test_parse_after_expiration
|
243
|
+
str = "inkid=n92b0ADOgACIgUb9lsjHqAAAHu2a; expires=Wed, 01-Dec-2010 00:00:00 GMT; path=/"
|
244
|
+
@cm.parse(str, urify('http://www.test.jp'))
|
245
|
+
cookie = @cm.cookies[0]
|
246
|
+
assert_instance_of(WebAgent::Cookie, cookie)
|
247
|
+
assert_equal("inkid", cookie.name)
|
248
|
+
assert_equal("n92b0ADOgACIgUb9lsjHqAAAHu2a", cookie.value)
|
249
|
+
assert_equal(Time.gm(2010, 12, 1, 0,0,0), cookie.expires)
|
250
|
+
assert_equal("/", cookie.path)
|
251
|
+
|
252
|
+
time = Time.at(Time.now.to_i + 60).utc
|
253
|
+
expires = time.strftime("%a, %d-%b-%Y %H:%M:%S GMT")
|
254
|
+
str = "inkid=n92b0ADOgACIgUb9lsjHqAAAHu2a; expires=#{expires}; path=/"
|
255
|
+
@cm.parse(str, urify('http://www.test.jp'))
|
256
|
+
cookie = @cm.cookies[0]
|
257
|
+
assert_equal("inkid", cookie.name)
|
258
|
+
assert_equal("n92b0ADOgACIgUb9lsjHqAAAHu2a", cookie.value)
|
259
|
+
assert_equal(time, cookie.expires)
|
260
|
+
assert_equal("/", cookie.path)
|
261
|
+
end
|
262
|
+
|
263
|
+
def test_find_cookie()
|
264
|
+
str = "xmen=off,0,0,1; path=/; domain=.excite2.co.jp; expires=Wednesday, 31-Dec-2037 12:00:00 GMT"
|
265
|
+
@cm.parse(str, urify("http://www.excite2.co.jp/"))
|
266
|
+
|
267
|
+
str = "xmen=off,0,0,2; path=/; domain=.excite.co.jp; expires=Wednesday, 31-Dec-2037 12:00:00 GMT"
|
268
|
+
@cm.parse(str, urify("http://www.excite.co.jp/"))
|
269
|
+
|
270
|
+
@cm.cookies[0].use = true
|
271
|
+
@cm.cookies[1].use = true
|
272
|
+
|
273
|
+
url = urify('http://www.excite.co.jp/hoge/funi/')
|
274
|
+
cookie_str = @cm.find(url)
|
275
|
+
assert_equal("xmen=off,0,0,2", cookie_str)
|
276
|
+
end
|
277
|
+
|
278
|
+
def test_load_cookies()
|
279
|
+
begin
|
280
|
+
File.open("tmp_test.tmp","w") {|f|
|
281
|
+
f.write <<EOF
|
282
|
+
http://www.zdnet.co.jp/news/0106/08/e_gibson.html NGUserID d29b8f49-10875-992421294-1 2145801600 www.zdnet.co.jp / 9 0
|
283
|
+
http://www.zdnet.co.jp/news/0106/08/e_gibson.html PACK zd3-992421294-7436 1293839999 .zdnet.co.jp / 13 0
|
284
|
+
http://example.org/ key value 0 .example.org / 13 0
|
285
|
+
http://example.org/ key value .example.org / 13 0
|
286
|
+
EOF
|
287
|
+
}
|
288
|
+
|
289
|
+
@cm.cookies_file = 'tmp_test.tmp'
|
290
|
+
@cm.load_cookies()
|
291
|
+
c0, c1, c2, c3 = @cm.cookies
|
292
|
+
assert_equal('http://www.zdnet.co.jp/news/0106/08/e_gibson.html', c0.url.to_s)
|
293
|
+
assert_equal('NGUserID', c0.name)
|
294
|
+
assert_equal('d29b8f49-10875-992421294-1', c0.value)
|
295
|
+
assert_equal(Time.at(2145801600), c0.expires)
|
296
|
+
assert_equal('www.zdnet.co.jp', c0.domain)
|
297
|
+
assert_equal('/', c0.path)
|
298
|
+
assert_equal(9, c0.flag)
|
299
|
+
#
|
300
|
+
assert_equal('http://www.zdnet.co.jp/news/0106/08/e_gibson.html', c1.url.to_s)
|
301
|
+
assert_equal('PACK', c1.name)
|
302
|
+
assert_equal('zd3-992421294-7436', c1.value)
|
303
|
+
assert_equal(Time.at(1293839999), c1.expires)
|
304
|
+
assert_equal('.zdnet.co.jp', c1.domain)
|
305
|
+
assert_equal('/', c1.path)
|
306
|
+
assert_equal(13, c1.flag)
|
307
|
+
#
|
308
|
+
assert_equal(nil, c2.expires)
|
309
|
+
assert_equal(nil, c3.expires) # allow empty 'expires' (should not happen)
|
310
|
+
ensure
|
311
|
+
File.unlink("tmp_test.tmp")
|
312
|
+
end
|
313
|
+
end
|
314
|
+
|
315
|
+
def test_save_cookie()
|
316
|
+
str = <<EOF
|
317
|
+
http://www.zdnet.co.jp/news/0106/08/e_gibson.html NGUserID d29b8f49-10875-992421294-1 2145801600 www.zdnet.co.jp / 9
|
318
|
+
http://www.zdnet.co.jp/news/0106/08/e_gibson.html PACK zd3-992421294-7436 2145801600 .zdnet.co.jp / 13
|
319
|
+
EOF
|
320
|
+
begin
|
321
|
+
File.open("tmp_test.tmp","w") {|f|
|
322
|
+
f.write str
|
323
|
+
}
|
324
|
+
@cm.cookies_file = 'tmp_test.tmp'
|
325
|
+
@cm.load_cookies()
|
326
|
+
@cm.instance_eval{@is_saved = false}
|
327
|
+
@cm.cookies_file = 'tmp_test2.tmp'
|
328
|
+
@cm.save_cookies()
|
329
|
+
str2 = ''
|
330
|
+
File.open("tmp_test2.tmp","r") {|f|
|
331
|
+
str2 = f.read()
|
332
|
+
}
|
333
|
+
assert_equal(str, str2)
|
334
|
+
#
|
335
|
+
assert(File.exist?('tmp_test2.tmp'))
|
336
|
+
File.unlink("tmp_test2.tmp")
|
337
|
+
@cm.save_cookies()
|
338
|
+
assert(!File.exist?('tmp_test2.tmp'))
|
339
|
+
@cm.save_cookies(true)
|
340
|
+
assert(File.exist?('tmp_test2.tmp'))
|
341
|
+
ensure
|
342
|
+
File.unlink("tmp_test.tmp")
|
343
|
+
if FileTest.exist?("tmp_test2.tmp")
|
344
|
+
File.unlink("tmp_test2.tmp")
|
345
|
+
end
|
346
|
+
end
|
347
|
+
end
|
348
|
+
|
349
|
+
def test_not_saved_expired_cookies
|
350
|
+
begin
|
351
|
+
@cm.cookies_file = 'tmp_test.tmp'
|
352
|
+
uri = urify('http://www.example.org')
|
353
|
+
@cm.parse("foo=1; path=/", uri)
|
354
|
+
@cm.parse("bar=2; path=/; expires=", uri)
|
355
|
+
@cm.parse("baz=3; path=/; expires=\"\"", uri)
|
356
|
+
@cm.parse("qux=4; path=/; expires=#{(Time.now + 10).asctime}", uri)
|
357
|
+
@cm.parse("quxx=5; path=/; expires=#{(Time.now - 10).asctime}", uri)
|
358
|
+
@cm.save_cookies()
|
359
|
+
@cm.load_cookies
|
360
|
+
assert_equal(1, @cm.cookies.size) # +10 cookies only
|
361
|
+
ensure
|
362
|
+
File.unlink("tmp_test.tmp") if File.exist?("tmp_test.tmp")
|
363
|
+
end
|
364
|
+
end
|
365
|
+
|
366
|
+
def test_add()
|
367
|
+
c = WebAgent::Cookie.new()
|
368
|
+
c.name = "hoge"
|
369
|
+
c.value = "funi"
|
370
|
+
c.url = urify("http://www.inac.co.jp/hoge")
|
371
|
+
@cm.add(c)
|
372
|
+
c = @cm.cookies[0]
|
373
|
+
assert_equal('hoge', c.name)
|
374
|
+
assert_equal('funi', c.value)
|
375
|
+
assert_equal(nil, c.expires)
|
376
|
+
end
|
377
|
+
|
378
|
+
def test_add2()
|
379
|
+
c = WebAgent::Cookie.new()
|
380
|
+
c.name = "hoge"
|
381
|
+
c.value = "funi"
|
382
|
+
c.path = ''
|
383
|
+
c.url = urify("http://www.inac.co.jp/hoge/hoge2/hoge3")
|
384
|
+
@cm.add(c)
|
385
|
+
#
|
386
|
+
c = WebAgent::Cookie.new()
|
387
|
+
c.name = "hoge"
|
388
|
+
c.value = "funi"
|
389
|
+
#c.path = '' NO path given -> same as URL
|
390
|
+
c.url = urify("http://www.inac.co.jp/hoge/hoge2/hoge3")
|
391
|
+
@cm.add(c)
|
392
|
+
#
|
393
|
+
c1, c2 = @cm.cookies
|
394
|
+
assert_equal('', c1.path)
|
395
|
+
assert_equal('/hoge/hoge2', c2.path)
|
396
|
+
end
|
397
|
+
|
398
|
+
def test_check_cookie_accept_domain()
|
399
|
+
@cm.accept_domains = [".example1.co.jp", "www1.example.jp"]
|
400
|
+
@cm.reject_domains = [".example2.co.jp", "www2.example.jp"]
|
401
|
+
check1 = @cm.check_cookie_accept_domain("www.example1.co.jp")
|
402
|
+
assert_equal(true, check1)
|
403
|
+
check2 = @cm.check_cookie_accept_domain("www.example2.co.jp")
|
404
|
+
assert_equal(false, check2)
|
405
|
+
check3 = @cm.check_cookie_accept_domain("www1.example.jp")
|
406
|
+
assert_equal(true, check3)
|
407
|
+
check4 = @cm.check_cookie_accept_domain("www2.example.jp")
|
408
|
+
assert_equal(false, check4)
|
409
|
+
check5 = @cm.check_cookie_accept_domain("aa.www2.example.jp")
|
410
|
+
assert_equal(true, check5)
|
411
|
+
check6 = @cm.check_cookie_accept_domain("aa.www2.example.jp")
|
412
|
+
assert_equal(true, check6)
|
413
|
+
assert_equal(false, @cm.check_cookie_accept_domain(nil))
|
414
|
+
end
|
415
|
+
|
416
|
+
def test_escaped
|
417
|
+
uri = urify('http://www.example.org')
|
418
|
+
|
419
|
+
@cm.parse("bar=2; path=/", uri)
|
420
|
+
c = @cm.cookies.first
|
421
|
+
assert_equal('2', c.value)
|
422
|
+
assert_equal('bar=2', @cm.find(uri))
|
423
|
+
|
424
|
+
@cm.parse("bar=2; path=/", uri)
|
425
|
+
c = @cm.cookies.first
|
426
|
+
assert_equal('2', c.value)
|
427
|
+
assert_equal('bar=2', @cm.find(uri))
|
428
|
+
|
429
|
+
@cm.parse("bar=; path=/", uri)
|
430
|
+
c = @cm.cookies.first
|
431
|
+
assert_equal(nil, c.value)
|
432
|
+
assert_equal('bar=', @cm.find(uri))
|
433
|
+
|
434
|
+
@cm.parse("bar=; path=/", uri)
|
435
|
+
c = @cm.cookies.first
|
436
|
+
assert_equal(nil, c.value)
|
437
|
+
assert_equal('bar=', @cm.find(uri))
|
438
|
+
end
|
439
|
+
|
440
|
+
def test_load_cookies_escaped
|
441
|
+
uri = urify('http://example.org/')
|
442
|
+
f = Tempfile.new('test_cookie')
|
443
|
+
File.open(f.path, 'w') do |out|
|
444
|
+
out.write <<EOF
|
445
|
+
http://example.org/ key "value" 0 .example.org / 13 0
|
446
|
+
http://example.org/ key "" .example.org / 13 0
|
447
|
+
http://example.org/ key .example.org / 13 0
|
448
|
+
EOF
|
449
|
+
end
|
450
|
+
@cm.cookies_file = f.path
|
451
|
+
@cm.load_cookies
|
452
|
+
c0, c1, c2 = @cm.cookies
|
453
|
+
assert_equal('"value"', c0.value)
|
454
|
+
assert_equal('""', c1.value)
|
455
|
+
assert_equal('', c2.value)
|
456
|
+
assert_equal('key="value"', @cm.find(uri))
|
457
|
+
c0.value = ''
|
458
|
+
assert_equal('key=', @cm.find(uri))
|
459
|
+
c0.value = '""'
|
460
|
+
assert_equal('key=""', @cm.find(uri))
|
461
|
+
end
|
462
|
+
|
463
|
+
end
|
464
|
+
|
465
|
+
end
|
metadata
CHANGED
@@ -1,70 +1,111 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: httpclient
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.8.3
|
5
5
|
platform: ruby
|
6
|
-
authors:
|
7
|
-
-
|
6
|
+
authors:
|
7
|
+
- Hiroshi Nakamura
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
|
12
|
-
date: 2009-05-25 00:00:00 +09:00
|
13
|
-
default_executable:
|
11
|
+
date: 2016-12-09 00:00:00.000000000 Z
|
14
12
|
dependencies: []
|
15
|
-
|
16
13
|
description:
|
17
14
|
email: nahi@ruby-lang.org
|
18
|
-
executables:
|
19
|
-
|
15
|
+
executables:
|
16
|
+
- httpclient
|
20
17
|
extensions: []
|
21
|
-
|
22
18
|
extra_rdoc_files: []
|
23
|
-
|
24
|
-
|
25
|
-
-
|
26
|
-
-
|
27
|
-
- lib/
|
19
|
+
files:
|
20
|
+
- README.md
|
21
|
+
- bin/httpclient
|
22
|
+
- bin/jsonclient
|
23
|
+
- lib/hexdump.rb
|
24
|
+
- lib/http-access2.rb
|
28
25
|
- lib/http-access2/cookie.rb
|
29
|
-
- lib/
|
26
|
+
- lib/http-access2/http.rb
|
27
|
+
- lib/httpclient.rb
|
28
|
+
- lib/httpclient/auth.rb
|
29
|
+
- lib/httpclient/cacert.pem
|
30
|
+
- lib/httpclient/cacert1024.pem
|
30
31
|
- lib/httpclient/connection.rb
|
32
|
+
- lib/httpclient/cookie.rb
|
31
33
|
- lib/httpclient/http.rb
|
32
|
-
- lib/httpclient/
|
33
|
-
- lib/httpclient/
|
34
|
+
- lib/httpclient/include_client.rb
|
35
|
+
- lib/httpclient/jruby_ssl_socket.rb
|
34
36
|
- lib/httpclient/session.rb
|
35
37
|
- lib/httpclient/ssl_config.rb
|
38
|
+
- lib/httpclient/ssl_socket.rb
|
36
39
|
- lib/httpclient/timeout.rb
|
37
|
-
- lib/httpclient/
|
38
|
-
- lib/httpclient/
|
39
|
-
- lib/httpclient/
|
40
|
-
- lib/
|
41
|
-
- lib/
|
42
|
-
-
|
43
|
-
|
44
|
-
|
40
|
+
- lib/httpclient/util.rb
|
41
|
+
- lib/httpclient/version.rb
|
42
|
+
- lib/httpclient/webagent-cookie.rb
|
43
|
+
- lib/jsonclient.rb
|
44
|
+
- lib/oauthclient.rb
|
45
|
+
- sample/async.rb
|
46
|
+
- sample/auth.rb
|
47
|
+
- sample/cookie.rb
|
48
|
+
- sample/dav.rb
|
49
|
+
- sample/howto.rb
|
50
|
+
- sample/jsonclient.rb
|
51
|
+
- sample/oauth_buzz.rb
|
52
|
+
- sample/oauth_friendfeed.rb
|
53
|
+
- sample/oauth_twitter.rb
|
54
|
+
- sample/ssl/0cert.pem
|
55
|
+
- sample/ssl/0key.pem
|
56
|
+
- sample/ssl/1000cert.pem
|
57
|
+
- sample/ssl/1000key.pem
|
58
|
+
- sample/ssl/htdocs/index.html
|
59
|
+
- sample/ssl/ssl_client.rb
|
60
|
+
- sample/ssl/webrick_httpsd.rb
|
61
|
+
- sample/stream.rb
|
62
|
+
- sample/thread.rb
|
63
|
+
- sample/wcat.rb
|
64
|
+
- test/ca-chain.pem
|
65
|
+
- test/ca.cert
|
66
|
+
- test/client-pass.key
|
67
|
+
- test/client.cert
|
68
|
+
- test/client.key
|
69
|
+
- test/helper.rb
|
70
|
+
- test/htdigest
|
71
|
+
- test/htpasswd
|
72
|
+
- test/jruby_ssl_socket/test_pemutils.rb
|
73
|
+
- test/runner.rb
|
74
|
+
- test/server.cert
|
75
|
+
- test/server.key
|
76
|
+
- test/sslsvr.rb
|
77
|
+
- test/subca.cert
|
78
|
+
- test/test_auth.rb
|
79
|
+
- test/test_cookie.rb
|
80
|
+
- test/test_hexdump.rb
|
81
|
+
- test/test_http-access2.rb
|
82
|
+
- test/test_httpclient.rb
|
83
|
+
- test/test_include_client.rb
|
84
|
+
- test/test_jsonclient.rb
|
85
|
+
- test/test_ssl.rb
|
86
|
+
- test/test_webagent-cookie.rb
|
87
|
+
homepage: https://github.com/nahi/httpclient
|
88
|
+
licenses:
|
89
|
+
- ruby
|
90
|
+
metadata: {}
|
45
91
|
post_install_message:
|
46
92
|
rdoc_options: []
|
47
|
-
|
48
|
-
require_paths:
|
93
|
+
require_paths:
|
49
94
|
- lib
|
50
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
52
97
|
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version:
|
55
|
-
|
56
|
-
|
57
|
-
requirements:
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
58
102
|
- - ">="
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
version:
|
61
|
-
version:
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
62
105
|
requirements: []
|
63
|
-
|
64
106
|
rubyforge_project:
|
65
|
-
rubygems_version:
|
107
|
+
rubygems_version: 2.6.8
|
66
108
|
signing_key:
|
67
|
-
specification_version:
|
109
|
+
specification_version: 4
|
68
110
|
summary: gives something like the functionality of libwww-perl (LWP) in Ruby
|
69
111
|
test_files: []
|
70
|
-
|