httpclient-fixcerts 2.8.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +98 -0
  3. data/bin/httpclient +77 -0
  4. data/bin/jsonclient +85 -0
  5. data/lib/hexdump.rb +50 -0
  6. data/lib/http-access2/cookie.rb +1 -0
  7. data/lib/http-access2/http.rb +1 -0
  8. data/lib/http-access2.rb +55 -0
  9. data/lib/httpclient/auth.rb +924 -0
  10. data/lib/httpclient/cacert.pem +3952 -0
  11. data/lib/httpclient/cacert1024.pem +3866 -0
  12. data/lib/httpclient/connection.rb +88 -0
  13. data/lib/httpclient/cookie.rb +220 -0
  14. data/lib/httpclient/http.rb +1082 -0
  15. data/lib/httpclient/include_client.rb +85 -0
  16. data/lib/httpclient/jruby_ssl_socket.rb +594 -0
  17. data/lib/httpclient/session.rb +960 -0
  18. data/lib/httpclient/ssl_config.rb +433 -0
  19. data/lib/httpclient/ssl_socket.rb +150 -0
  20. data/lib/httpclient/timeout.rb +140 -0
  21. data/lib/httpclient/util.rb +222 -0
  22. data/lib/httpclient/version.rb +3 -0
  23. data/lib/httpclient/webagent-cookie.rb +459 -0
  24. data/lib/httpclient.rb +1332 -0
  25. data/lib/jsonclient.rb +66 -0
  26. data/lib/oauthclient.rb +111 -0
  27. data/sample/async.rb +8 -0
  28. data/sample/auth.rb +11 -0
  29. data/sample/cookie.rb +18 -0
  30. data/sample/dav.rb +103 -0
  31. data/sample/howto.rb +49 -0
  32. data/sample/jsonclient.rb +67 -0
  33. data/sample/oauth_buzz.rb +57 -0
  34. data/sample/oauth_friendfeed.rb +59 -0
  35. data/sample/oauth_twitter.rb +61 -0
  36. data/sample/ssl/0cert.pem +22 -0
  37. data/sample/ssl/0key.pem +30 -0
  38. data/sample/ssl/1000cert.pem +19 -0
  39. data/sample/ssl/1000key.pem +18 -0
  40. data/sample/ssl/htdocs/index.html +10 -0
  41. data/sample/ssl/ssl_client.rb +22 -0
  42. data/sample/ssl/webrick_httpsd.rb +29 -0
  43. data/sample/stream.rb +21 -0
  44. data/sample/thread.rb +27 -0
  45. data/sample/wcat.rb +21 -0
  46. data/test/ca-chain.pem +44 -0
  47. data/test/ca.cert +23 -0
  48. data/test/client-pass.key +18 -0
  49. data/test/client.cert +19 -0
  50. data/test/client.key +15 -0
  51. data/test/helper.rb +131 -0
  52. data/test/htdigest +1 -0
  53. data/test/htpasswd +2 -0
  54. data/test/jruby_ssl_socket/test_pemutils.rb +32 -0
  55. data/test/runner.rb +2 -0
  56. data/test/server.cert +19 -0
  57. data/test/server.key +15 -0
  58. data/test/sslsvr.rb +65 -0
  59. data/test/subca.cert +21 -0
  60. data/test/test_auth.rb +492 -0
  61. data/test/test_cookie.rb +309 -0
  62. data/test/test_hexdump.rb +14 -0
  63. data/test/test_http-access2.rb +508 -0
  64. data/test/test_httpclient.rb +2145 -0
  65. data/test/test_include_client.rb +52 -0
  66. data/test/test_jsonclient.rb +98 -0
  67. data/test/test_ssl.rb +562 -0
  68. data/test/test_webagent-cookie.rb +465 -0
  69. metadata +124 -0
@@ -0,0 +1,309 @@
1
+ require 'test/unit'
2
+ require 'uri'
3
+ require 'tempfile'
4
+
5
+ require 'httpclient/util'
6
+ require 'httpclient/cookie'
7
+
8
+ class TestCookie < Test::Unit::TestCase
9
+ include HTTPClient::Util
10
+
11
+ def setup()
12
+ @c = WebAgent::Cookie.new('hoge', 'funi')
13
+ end
14
+
15
+ def test_s_new()
16
+ assert_instance_of(WebAgent::Cookie, @c)
17
+ end
18
+ end
19
+
20
+ class TestCookieManager < Test::Unit::TestCase
21
+ include HTTPClient::Util
22
+
23
+ def setup()
24
+ @cm = WebAgent::CookieManager.new()
25
+ end
26
+
27
+ def teardown()
28
+ end
29
+
30
+ def test_parse()
31
+ str = "inkid=n92b0ADOgACIgUb9lsjHqAAAHu2a; expires=Wed, 01-Dec-2999 00:00:00 GMT; path=/"
32
+ @cm.parse(str, urify('http://www.test.jp'))
33
+ cookie = @cm.cookies[0]
34
+ assert_instance_of(WebAgent::Cookie, cookie)
35
+ assert_equal("inkid", cookie.name)
36
+ assert_equal("n92b0ADOgACIgUb9lsjHqAAAHu2a", cookie.value)
37
+ assert_equal(Time.gm(2999, 12, 1, 0,0,0), cookie.expires)
38
+ assert_equal("/", cookie.path)
39
+ end
40
+
41
+ def test_parse2()
42
+ str = "xmen=off,0,0,1; path=/; domain=.excite.co.jp; expires=Wednesday, 31-Dec-2037 12:00:00 GMT"
43
+ @cm.parse(str, urify('http://www.excite.co.jp'))
44
+ cookie = @cm.cookies[0]
45
+ assert_instance_of(WebAgent::Cookie, cookie)
46
+ assert_equal("xmen", cookie.name)
47
+ assert_equal("off,0,0,1", cookie.value)
48
+ assert_equal("/", cookie.path)
49
+ assert_equal("excite.co.jp", cookie.domain)
50
+ assert_equal(".excite.co.jp", cookie.dot_domain)
51
+ assert_equal(Time.gm(2037,12,31,12,0,0), cookie.expires)
52
+ end
53
+
54
+ def test_parse3()
55
+ str = "xmen=off,0,0,1; path=/; domain=.excite.co.jp; expires=Wednesday, 31-Dec-2037 12:00:00 GMT;Secure;HTTPOnly"
56
+ @cm.parse(str, urify('http://www.excite.co.jp'))
57
+ cookie = @cm.cookies[0]
58
+ assert_instance_of(WebAgent::Cookie, cookie)
59
+ assert_equal("xmen", cookie.name)
60
+ assert_equal("off,0,0,1", cookie.value)
61
+ assert_equal("/", cookie.path)
62
+ assert_equal("excite.co.jp", cookie.domain)
63
+ assert_equal(".excite.co.jp", cookie.dot_domain)
64
+ assert_equal(Time.gm(2037,12,31,12,0,0), cookie.expires)
65
+ assert_equal(true, cookie.secure?)
66
+ assert_equal(true, cookie.http_only?)
67
+ end
68
+
69
+ def test_parse_double_semicolon()
70
+ str = "xmen=off,0,0,1;; path=\"/;;\"; domain=.excite.co.jp; expires=Wednesday, 31-Dec-2037 12:00:00 GMT"
71
+ @cm.parse(str, urify('http://www.excite.co.jp'))
72
+ cookie = @cm.cookies[0]
73
+ assert_instance_of(WebAgent::Cookie, cookie)
74
+ assert_equal("xmen", cookie.name)
75
+ assert_equal("off,0,0,1", cookie.value)
76
+ assert_equal("/;;", cookie.path)
77
+ assert_equal("excite.co.jp", cookie.domain)
78
+ assert_equal(".excite.co.jp", cookie.dot_domain)
79
+ assert_equal(Time.gm(2037,12,31,12,0,0), cookie.expires)
80
+ end
81
+
82
+ # def test_make_portlist()
83
+ # assert_equal([80,8080], @cm.instance_eval{make_portlist("80,8080")})
84
+ # assert_equal([80], @cm.instance_eval{make_portlist("80")})
85
+ # assert_equal([80,8080,10080], @cm.instance_eval{make_portlist(" 80, 8080, 10080 \n")})
86
+ # end
87
+
88
+ def test_check_expired_cookies()
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)
97
+ c4.expires = nil
98
+ cookies = [c1,c2,c3,c4]
99
+ @cm.cookies = 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)
104
+ end
105
+
106
+ def test_parse_expires
107
+ str = "inkid=n92b0ADOgACIgUb9lsjHqAAAHu2a; expires=; path=/"
108
+ @cm.parse(str, urify('http://www.test.jp'))
109
+ cookie = @cm.cookies[0]
110
+ assert_equal("inkid", cookie.name)
111
+ assert_equal("n92b0ADOgACIgUb9lsjHqAAAHu2a", cookie.value)
112
+ assert_equal(nil, cookie.expires)
113
+ assert_equal("/", cookie.path)
114
+ #
115
+ str = "inkid=n92b0ADOgACIgUb9lsjHqAAAHu2a; path=/; expires="
116
+ @cm.parse(str, urify('http://www.test.jp'))
117
+ cookie = @cm.cookies[0]
118
+ assert_equal("inkid", cookie.name)
119
+ assert_equal("n92b0ADOgACIgUb9lsjHqAAAHu2a", cookie.value)
120
+ assert_equal(nil, cookie.expires)
121
+ assert_equal("/", cookie.path)
122
+ #
123
+ str = "inkid=n92b0ADOgACIgUb9lsjHqAAAHu2a; path=/; expires=\"\""
124
+ @cm.parse(str, urify('http://www.test.jp'))
125
+ cookie = @cm.cookies[0]
126
+ assert_equal("inkid", cookie.name)
127
+ assert_equal("n92b0ADOgACIgUb9lsjHqAAAHu2a", cookie.value)
128
+ assert_equal(nil, cookie.expires)
129
+ assert_equal("/", cookie.path)
130
+ end
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
+
153
+ def test_find_cookie()
154
+ str = "xmen=off,0,0,1; path=/; domain=.excite2.co.jp; expires=Wednesday, 31-Dec-2037 12:00:00 GMT"
155
+ @cm.parse(str, urify("http://www.excite2.co.jp/"))
156
+
157
+ str = "xmen=off,0,0,2; 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
+
160
+ url = urify('http://www.excite.co.jp/hoge/funi/')
161
+ cookie_str = @cm.find(url)
162
+ assert_equal("xmen=\"off,0,0,2\"", cookie_str)
163
+ end
164
+
165
+ def test_load_cookies()
166
+ cookiefile = Tempfile.new('test_cookie')
167
+ File.open(cookiefile.path, 'w') do |f|
168
+ f.write <<EOF
169
+ http://www.zdnet.co.jp/news/0106/08/e_gibson.html NGUserID d29b8f49-10875-992421294-1 2145801600 www.zdnet.co.jp / 9 0
170
+ http://www.zdnet.co.jp/news/0106/08/e_gibson.html PACK zd3-992421294-7436 2293839999 .zdnet.co.jp / 13 0
171
+ http://example.org/ key value 0 .example.org / 13 0
172
+ http://example.org/ key value .example.org / 13 0
173
+ EOF
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)
197
+ end
198
+
199
+ def test_save_cookie()
200
+ str = <<EOF
201
+ http://www.zdnet.co.jp/news/0106/08/e_gibson.html NGUserID d29b8f49-10875-992421294-1 2145801600 www.zdnet.co.jp / 9
202
+ http://www.zdnet.co.jp/news/0106/08/e_gibson.html PACK zd3-992421294-7436 2145801600 .zdnet.co.jp / 13
203
+ EOF
204
+ cookiefile = Tempfile.new('test_cookie')
205
+ cookiefile2 = Tempfile.new('test_cookie2')
206
+ File.open(cookiefile.path, 'w') do |f|
207
+ f.write str
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))
224
+ end
225
+
226
+ def test_not_saved_expired_cookies
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
238
+ end
239
+
240
+ def test_add()
241
+ c = WebAgent::Cookie.new('hoge', 'funi')
242
+ c.url = urify("http://www.inac.co.jp/hoge")
243
+ @cm.add(c)
244
+ c = @cm.cookies[0]
245
+ assert_equal('hoge', c.name)
246
+ assert_equal('funi', c.value)
247
+ assert_equal(nil, c.expires)
248
+ end
249
+
250
+ def test_add2()
251
+ c = WebAgent::Cookie.new('hoge', 'funi')
252
+ c.path = ''
253
+ c.url = urify("http://www.inac.co.jp/hoge/hoge2/hoge3")
254
+ @cm.add(c)
255
+ #
256
+ c = WebAgent::Cookie.new('hoge', 'funi')
257
+ #c.path = '' NO path given -> same as URL
258
+ c.url = urify("http://www.inac.co.jp/hoge/hoge2/hoge3")
259
+ @cm.add(c)
260
+ #
261
+ c1, c2 = @cm.cookies
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))
288
+ end
289
+
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))
307
+ end
308
+
309
+ end
@@ -0,0 +1,14 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('helper', File.dirname(__FILE__))
3
+ require 'hexdump'
4
+
5
+
6
+ class TestHexDump < Test::Unit::TestCase
7
+ def test_encode
8
+ str = "\032l\277\370\2429\216\236\351[{\{\262\350\274\376"
9
+ str.force_encoding('BINARY') if str.respond_to?(:force_encoding)
10
+ assert_equal(["00000000 1a6cbff8 a2398e9e e95b7b7b b2e8bcfe .l...9...[{{...."], HexDump.encode(str))
11
+ end
12
+ end if defined?(RUBY_ENGINE) && RUBY_ENGINE != "rbx" && RUBY_VERSION >= "1.9.0"
13
+ # Rubinius 1.8 mode does not support Regexp.quote(raw, 'n') I don't want put
14
+ # a pressure on supporting it because 1.9 mode works fine.