httpclient 2.8.2.4 → 2.9.0

Sign up to get free protection for your applications and to get access to all the features.
data/test/test_auth.rb CHANGED
@@ -127,6 +127,10 @@ class TestAuth < Test::Unit::TestCase
127
127
  def data_size
128
128
  @active && @value ? @value.size : 0
129
129
  end
130
+
131
+ def value
132
+ @value ||= ""
133
+ end
130
134
  end
131
135
  end
132
136
  end
@@ -176,7 +180,7 @@ class TestAuth < Test::Unit::TestCase
176
180
  c.www_auth.basic_auth.instance_eval { @scheme = "BASIC" }
177
181
  #
178
182
  c.force_basic_auth = true
179
- c.debug_dev = str = ''
183
+ c.debug_dev = str = ''.dup
180
184
  c.set_auth("http://localhost:#{serverport}/", 'admin', 'admin')
181
185
  assert_equal('basic_auth OK', c.get_content("http://localhost:#{serverport}/basic_auth"))
182
186
  assert_equal('Authorization: Basic YWRtaW46YWRtaW4='.upcase, str.split(/\r?\n/)[5].upcase)
@@ -230,11 +234,11 @@ class TestAuth < Test::Unit::TestCase
230
234
  c.www_auth.basic_auth.instance_eval { @scheme = "BASIC" }
231
235
  c.set_auth("http://localhost:#{serverport}/", 'admin', 'admin')
232
236
 
233
- 100.times.map { |idx|
237
+ 20.times.map { |idx|
234
238
  Thread.new(idx) { |idx2|
235
239
  Thread.abort_on_exception = true
236
240
  Thread.pass
237
- c.get("http://localhost:#{serverport}/basic_auth?#{idx2}")
241
+ assert_equal('basic_auth OK', c.get("http://localhost:#{serverport}/basic_auth?#{idx2}").body)
238
242
  }
239
243
  }.map { |t|
240
244
  t.join
@@ -249,7 +253,7 @@ class TestAuth < Test::Unit::TestCase
249
253
  c.set_auth("http://localhost:#{serverport}/", 'admin', 'admin')
250
254
  assert_equal('basic_auth OK', c.get_content("http://localhost:#{serverport}/basic_auth/"))
251
255
  c.test_loopback_http_response << "HTTP/1.0 200 OK\nContent-Length: 2\n\nOK"
252
- c.debug_dev = str = ''
256
+ c.debug_dev = str = ''.dup
253
257
  c.get_content("http://localhost:#{serverport}/basic_auth/sub/dir/")
254
258
  assert_match(/Authorization: Basic YWRtaW46YWRtaW4=/, str)
255
259
  end
@@ -265,7 +269,7 @@ class TestAuth < Test::Unit::TestCase
265
269
  c.set_auth("http://localhost:#{serverport}/", 'admin', 'admin')
266
270
  assert_equal('digest_auth OK', c.get_content("http://localhost:#{serverport}/digest_auth/"))
267
271
  c.test_loopback_http_response << "HTTP/1.0 200 OK\nContent-Length: 2\n\nOK"
268
- c.debug_dev = str = ''
272
+ c.debug_dev = str = ''.dup
269
273
  c.get_content("http://localhost:#{serverport}/digest_auth/sub/dir/")
270
274
  assert_match(/Authorization: Digest/, str)
271
275
  end
@@ -311,7 +315,7 @@ class TestAuth < Test::Unit::TestCase
311
315
  c.set_auth('http://example.com/', 'admin', 'admin')
312
316
  c.test_loopback_http_response << "HTTP/1.0 401 Unauthorized\nWWW-Authenticate: Basic realm=\"foo\"\nWWW-Authenticate: Digest realm=\"foo\", nonce=\"nonce\", stale=false\nContent-Length: 2\n\nNG"
313
317
  c.test_loopback_http_response << "HTTP/1.0 200 OK\nContent-Length: 2\n\nOK"
314
- c.debug_dev = str = ''
318
+ c.debug_dev = str = ''.dup
315
319
  c.get_content('http://example.com/')
316
320
  assert_match(/^Authorization: Digest/, str)
317
321
  end
@@ -327,7 +331,7 @@ class TestAuth < Test::Unit::TestCase
327
331
  c.set_proxy_auth('admin', 'admin')
328
332
  c.test_loopback_http_response << "HTTP/1.0 407 Unauthorized\nProxy-Authenticate: Basic realm=\"foo\"\nContent-Length: 2\n\nNG"
329
333
  c.test_loopback_http_response << "HTTP/1.0 200 OK\nContent-Length: 2\n\nOK"
330
- c.debug_dev = str = ''
334
+ c.debug_dev = str = ''.dup
331
335
  c.get_content('http://example.com/')
332
336
  assert_match(/Proxy-Authorization: Basic YWRtaW46YWRtaW4=/, str)
333
337
  end
@@ -337,7 +341,7 @@ class TestAuth < Test::Unit::TestCase
337
341
  c.set_proxy_auth('admin', 'admin')
338
342
  c.force_basic_auth = true
339
343
  c.test_loopback_http_response << "HTTP/1.0 200 OK\nContent-Length: 2\n\nOK"
340
- c.debug_dev = str = ''
344
+ c.debug_dev = str = ''.dup
341
345
  c.get_content('http://example.com/')
342
346
  assert_match(/Proxy-Authorization: Basic YWRtaW46YWRtaW4=/, str)
343
347
  end
@@ -349,7 +353,7 @@ class TestAuth < Test::Unit::TestCase
349
353
  c.test_loopback_http_response << "HTTP/1.0 200 OK\nContent-Length: 2\n\nOK"
350
354
  c.test_loopback_http_response << "HTTP/1.0 200 OK\nContent-Length: 2\n\nOK"
351
355
  c.get_content('http://www1.example.com/')
352
- c.debug_dev = str = ''
356
+ c.debug_dev = str = ''.dup
353
357
  c.get_content('http://www2.example.com/')
354
358
  assert_match(/Proxy-Authorization: Basic YWRtaW46YWRtaW4=/, str)
355
359
  end
@@ -363,7 +367,7 @@ class TestAuth < Test::Unit::TestCase
363
367
  ha1 = md5.hexdigest("admin:foo:admin")
364
368
  ha2 = md5.hexdigest("GET:/")
365
369
  response = md5.hexdigest("#{ha1}:nonce:#{ha2}")
366
- c.debug_dev = str = ''
370
+ c.debug_dev = str = ''.dup
367
371
  c.get_content('http://example.com/')
368
372
  assert_match(/Proxy-Authorization: Digest/, str)
369
373
  assert_match(%r"response=\"#{response}\"", str)
@@ -394,7 +398,7 @@ class TestAuth < Test::Unit::TestCase
394
398
  ha1 = md5.hexdigest("admin:foo:admin")
395
399
  ha2 = md5.hexdigest("GET:/")
396
400
  response = md5.hexdigest("#{ha1}:nonce:#{ha2}")
397
- c.debug_dev = str = ''
401
+ c.debug_dev = str = ''.dup
398
402
  c.get_content('http://example.com/')
399
403
  assert_match(/Proxy-Authorization: Digest/, str)
400
404
  assert_match(%r"response=\"#{response}\"", str)
@@ -411,7 +415,7 @@ class TestAuth < Test::Unit::TestCase
411
415
  ha2 = md5.hexdigest("GET:/")
412
416
  response = md5.hexdigest("#{ha1}:nonce:#{ha2}")
413
417
  c.get_content('http://www1.example.com/')
414
- c.debug_dev = str = ''
418
+ c.debug_dev = str = ''.dup
415
419
  c.get_content('http://www2.example.com/')
416
420
  assert_match(/Proxy-Authorization: Digest/, str)
417
421
  assert_match(%r"response=\"#{response}\"", str)
@@ -433,19 +437,19 @@ class TestAuth < Test::Unit::TestCase
433
437
  c.www_auth.oauth.set_config('http://photos.example.net/', config)
434
438
  c.www_auth.oauth.challenge('http://photos.example.net/')
435
439
  c.test_loopback_http_response << "HTTP/1.0 200 OK\nContent-Length: 2\n\nOK"
436
- c.debug_dev = str = ''
440
+ c.debug_dev = str = ''.dup
437
441
  c.get_content('http://photos.example.net/photos', [[:file, 'vacation.jpg'], [:size, 'original']])
438
442
  assert(str.index(%q(GET /photos?file=vacation.jpg&size=original)))
439
443
  assert(str.index(%q(Authorization: OAuth realm="http://photos.example.net/", oauth_consumer_key="dpf43f3p2l4k3l03", oauth_nonce="kllo9940pd9333jh", oauth_signature="tR3%2BTy81lMeYAr%2FFid0kMTYa%2FWM%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1191242096", oauth_token="nnch734d00sl2jdk", oauth_version="1.0")))
440
444
  #
441
445
  c.test_loopback_http_response << "HTTP/1.0 200 OK\nContent-Length: 2\n\nOK"
442
- c.debug_dev = str = ''
446
+ c.debug_dev = str = ''.dup
443
447
  c.get_content('http://photos.example.net/photos?file=vacation.jpg&size=original')
444
448
  assert(str.index(%q(GET /photos?file=vacation.jpg&size=original)))
445
449
  assert(str.index(%q(Authorization: OAuth realm="http://photos.example.net/", oauth_consumer_key="dpf43f3p2l4k3l03", oauth_nonce="kllo9940pd9333jh", oauth_signature="tR3%2BTy81lMeYAr%2FFid0kMTYa%2FWM%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1191242096", oauth_token="nnch734d00sl2jdk", oauth_version="1.0")))
446
450
  #
447
451
  c.test_loopback_http_response << "HTTP/1.0 200 OK\nContent-Length: 2\n\nOK"
448
- c.debug_dev = str = ''
452
+ c.debug_dev = str = ''.dup
449
453
  c.post_content('http://photos.example.net/photos', [[:file, 'vacation.jpg'], [:size, 'original']])
450
454
  assert(str.index(%q(POST /photos)))
451
455
  assert(str.index(%q(Authorization: OAuth realm="http://photos.example.net/", oauth_consumer_key="dpf43f3p2l4k3l03", oauth_nonce="kllo9940pd9333jh", oauth_signature="wPkvxykrw%2BBTdCcGqKr%2B3I%2BPsiM%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1191242096", oauth_token="nnch734d00sl2jdk", oauth_version="1.0")))
@@ -475,7 +479,7 @@ class TestAuth < Test::Unit::TestCase
475
479
  c.test_loopback_http_response << %Q(HTTP/1.1 401 Unauthorized\r\nWWW-Authenticate: NTLM TlRMTVNTUAACAAAAAAAAACgAAAABAAAAAAAAAAAAAAA=\r\nConnection: Keep-Alive\r\nContent-Length: 0\r\n\r\n)
476
480
  c.test_loopback_http_response << %Q(HTTP/1.0 200 OK\r\nConnection: Keep-Alive\r\nContent-Length: 1\r\n\r\na)
477
481
  c.test_loopback_http_response << %Q(HTTP/1.0 200 OK\r\nConnection: Keep-Alive\r\nContent-Length: 1\r\n\r\nb)
478
- c.debug_dev = str = ''
482
+ c.debug_dev = str = ''.dup
479
483
  c.set_auth('http://www.example.org/', 'admin', 'admin')
480
484
  # Do NTLM negotiation
481
485
  c.get('http://www.example.org/foo')
@@ -484,7 +488,7 @@ class TestAuth < Test::Unit::TestCase
484
488
  assert_match(%r(Authorization: NTLM), str)
485
489
  assert_not_match(%r(Authorization: Basic), str)
486
490
  # ditto for other resource that is protected with NTLM
487
- c.debug_dev = str = ''
491
+ c.debug_dev = str = ''.dup
488
492
  c.get('http://www.example.org/foo/subdir')
489
493
  assert_not_match(%r(Authorization: NTLM), str)
490
494
  assert_not_match(%r(Authorization: Basic), str)
data/test/test_hexdump.rb CHANGED
@@ -5,8 +5,7 @@ require 'hexdump'
5
5
 
6
6
  class TestHexDump < Test::Unit::TestCase
7
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)
8
+ str = "\032l\277\370\2429\216\236\351[{\{\262\350\274\376".b
10
9
  assert_equal(["00000000 1a6cbff8 a2398e9e e95b7b7b b2e8bcfe .l...9...[{{...."], HexDump.encode(str))
11
10
  end
12
11
  end if defined?(RUBY_ENGINE) && RUBY_ENGINE != "rbx" && RUBY_VERSION >= "1.9.0"
@@ -24,7 +24,7 @@ class TestClient < Test::Unit::TestCase
24
24
  def test_initialize
25
25
  setup_proxyserver
26
26
  escape_noproxy do
27
- @proxyio.string = ""
27
+ @proxyio.truncate(0)
28
28
  @client = HTTPAccess2::Client.new(proxyurl)
29
29
  assert_equal(urify(proxyurl), @client.proxy)
30
30
  assert_equal(200, @client.head(serverurl).status)
@@ -34,7 +34,7 @@ class TestClient < Test::Unit::TestCase
34
34
 
35
35
  def test_agent_name
36
36
  @client = HTTPAccess2::Client.new(nil, "agent_name_foo")
37
- str = ""
37
+ str = "".dup
38
38
  @client.debug_dev = str
39
39
  @client.get(serverurl)
40
40
  lines = str.split(/(?:\r?\n)+/)
@@ -44,7 +44,7 @@ class TestClient < Test::Unit::TestCase
44
44
 
45
45
  def test_from
46
46
  @client = HTTPAccess2::Client.new(nil, nil, "from_bar")
47
- str = ""
47
+ str = "".dup
48
48
  @client.debug_dev = str
49
49
  @client.get(serverurl)
50
50
  lines = str.split(/(?:\r?\n)+/)
@@ -53,7 +53,7 @@ class TestClient < Test::Unit::TestCase
53
53
  end
54
54
 
55
55
  def test_debug_dev
56
- str = ""
56
+ str = "".dup
57
57
  @client.debug_dev = str
58
58
  assert(str.empty?)
59
59
  @client.get(serverurl)
@@ -62,7 +62,7 @@ class TestClient < Test::Unit::TestCase
62
62
 
63
63
  def _test_protocol_version_http09
64
64
  @client.protocol_version = 'HTTP/0.9'
65
- str = ""
65
+ str = "".dup
66
66
  @client.debug_dev = str
67
67
  @client.get(serverurl + 'hello')
68
68
  lines = str.split(/(?:\r?\n)+/)
@@ -76,7 +76,7 @@ class TestClient < Test::Unit::TestCase
76
76
 
77
77
  def test_protocol_version_http10
78
78
  @client.protocol_version = 'HTTP/1.0'
79
- str = ""
79
+ str = "".dup
80
80
  @client.debug_dev = str
81
81
  @client.get(serverurl + 'hello')
82
82
  lines = str.split(/(?:\r?\n)+/)
@@ -88,7 +88,7 @@ class TestClient < Test::Unit::TestCase
88
88
  end
89
89
 
90
90
  def test_protocol_version_http11
91
- str = ""
91
+ str = "".dup
92
92
  @client.debug_dev = str
93
93
  @client.get(serverurl)
94
94
  lines = str.split(/(?:\r?\n)+/)
@@ -97,7 +97,7 @@ class TestClient < Test::Unit::TestCase
97
97
  assert_equal("GET / HTTP/1.1", lines[3])
98
98
  assert_equal("Host: localhost:#{serverport}", lines[7])
99
99
  @client.protocol_version = 'HTTP/1.1'
100
- str = ""
100
+ str = "".dup
101
101
  @client.debug_dev = str
102
102
  @client.get(serverurl)
103
103
  lines = str.split(/(?:\r?\n)+/)
@@ -105,7 +105,7 @@ class TestClient < Test::Unit::TestCase
105
105
  assert_equal("! CONNECTION ESTABLISHED", lines[2])
106
106
  assert_equal("GET / HTTP/1.1", lines[3])
107
107
  @client.protocol_version = 'HTTP/1.0'
108
- str = ""
108
+ str = "".dup
109
109
  @client.debug_dev = str
110
110
  @client.get(serverurl)
111
111
  lines = str.split(/(?:\r?\n)+/)
@@ -130,12 +130,12 @@ class TestClient < Test::Unit::TestCase
130
130
  @client.proxy = uri
131
131
  assert_equal(uri, @client.proxy)
132
132
  #
133
- @proxyio.string = ""
133
+ @proxyio.truncate(0)
134
134
  @client.proxy = nil
135
135
  assert_equal(200, @client.head(serverurl).status)
136
136
  assert(@proxyio.string.empty?)
137
137
  #
138
- @proxyio.string = ""
138
+ @proxyio.truncate(0)
139
139
  @client.proxy = proxyurl
140
140
  assert_equal(200, @client.head(serverurl).status)
141
141
  assert(!@proxyio.string.empty?)
@@ -143,7 +143,7 @@ class TestClient < Test::Unit::TestCase
143
143
  end
144
144
 
145
145
  def test_noproxy_for_localhost
146
- @proxyio.string = ""
146
+ @proxyio.truncate(0)
147
147
  @client.proxy = proxyurl
148
148
  assert_equal(200, @client.head(serverurl).status)
149
149
  assert(@proxyio.string.empty?)
@@ -154,36 +154,36 @@ class TestClient < Test::Unit::TestCase
154
154
  escape_noproxy do
155
155
  # proxy is not set.
156
156
  @client.no_proxy = 'localhost'
157
- @proxyio.string = ""
157
+ @proxyio.truncate(0)
158
158
  @client.proxy = nil
159
159
  assert_equal(200, @client.head(serverurl).status)
160
160
  assert(/accept/ !~ @proxyio.string)
161
161
  #
162
- @proxyio.string = ""
162
+ @proxyio.truncate(0)
163
163
  @client.proxy = proxyurl
164
164
  assert_equal(200, @client.head(serverurl).status)
165
165
  assert(/accept/ !~ @proxyio.string)
166
166
  #
167
167
  @client.no_proxy = 'foobar'
168
- @proxyio.string = ""
168
+ @proxyio.truncate(0)
169
169
  @client.proxy = proxyurl
170
170
  assert_equal(200, @client.head(serverurl).status)
171
171
  assert(/accept/ =~ @proxyio.string)
172
172
  #
173
173
  @client.no_proxy = 'foobar,localhost:baz'
174
- @proxyio.string = ""
174
+ @proxyio.truncate(0)
175
175
  @client.proxy = proxyurl
176
176
  assert_equal(200, @client.head(serverurl).status)
177
177
  assert(/accept/ !~ @proxyio.string)
178
178
  #
179
179
  @client.no_proxy = 'foobar,localhost:443'
180
- @proxyio.string = ""
180
+ @proxyio.truncate(0)
181
181
  @client.proxy = proxyurl
182
182
  assert_equal(200, @client.head(serverurl).status)
183
183
  assert(/accept/ =~ @proxyio.string)
184
184
  #
185
185
  @client.no_proxy = "foobar,localhost:443:localhost:#{serverport},baz"
186
- @proxyio.string = ""
186
+ @proxyio.truncate(0)
187
187
  @client.proxy = proxyurl
188
188
  assert_equal(200, @client.head(serverurl).status)
189
189
  assert(/accept/ !~ @proxyio.string)
@@ -314,14 +314,14 @@ class TestClient < Test::Unit::TestCase
314
314
  end
315
315
 
316
316
  def test_extra_headers
317
- str = ""
317
+ str = "".dup
318
318
  @client.debug_dev = str
319
319
  @client.head(serverurl, nil, {"ABC" => "DEF"})
320
320
  lines = str.split(/(?:\r?\n)+/)
321
321
  assert_equal("= Request", lines[0])
322
322
  assert_match("ABC: DEF", lines[4])
323
323
  #
324
- str = ""
324
+ str = "".dup
325
325
  @client.debug_dev = str
326
326
  @client.get(serverurl, nil, [["ABC", "DEF"], ["ABC", "DEF"]])
327
327
  lines = str.split(/(?:\r?\n)+/)
@@ -331,9 +331,17 @@ class TestClient < Test::Unit::TestCase
331
331
  end
332
332
 
333
333
  def test_timeout
334
- assert_equal(60, @client.connect_timeout)
335
- assert_equal(120, @client.send_timeout)
336
- assert_equal(60, @client.receive_timeout)
334
+ client = HTTPClient.new
335
+ assert_equal(60, client.connect_timeout)
336
+ assert_equal(120, client.send_timeout)
337
+ assert_equal(60, client.receive_timeout)
338
+ #
339
+ client.connect_timeout = 1
340
+ client.send_timeout = 2
341
+ client.receive_timeout = 3
342
+ assert_equal(1, client.connect_timeout)
343
+ assert_equal(2, client.send_timeout)
344
+ assert_equal(3, client.receive_timeout)
337
345
  end
338
346
 
339
347
  def test_connect_timeout