curb 0.9.4 → 0.9.10

Sign up to get free protection for your applications and to get access to all the features.
data/tests/tc_curl.rb CHANGED
@@ -31,7 +31,37 @@ class TestCurl < Test::Unit::TestCase
31
31
  assert_equal "OPTIONSfoo=bar", curl.body_str
32
32
  end
33
33
 
34
- include TestServerMethods
34
+ def test_urlalize_without_extra_params
35
+ url_no_params = 'http://localhost/test'
36
+ url_with_params = 'http://localhost/test?a=1'
37
+
38
+ assert_equal(url_no_params, Curl.urlalize(url_no_params))
39
+ assert_equal(url_with_params, Curl.urlalize(url_with_params))
40
+ end
41
+
42
+ def test_urlalize_with_nil_as_params
43
+ url = 'http://localhost/test'
44
+ assert_equal(url, Curl.urlalize(url, nil))
45
+ end
46
+
47
+ def test_urlalize_with_extra_params
48
+ url_no_params = 'http://localhost/test'
49
+ url_with_params = 'http://localhost/test?a=1'
50
+ extra_params = { :b => 2 }
51
+
52
+ expected_url_no_params = 'http://localhost/test?b=2'
53
+ expected_url_with_params = 'http://localhost/test?a=1&b=2'
54
+
55
+ assert_equal(expected_url_no_params, Curl.urlalize(url_no_params, extra_params))
56
+ assert_equal(expected_url_with_params, Curl.urlalize(url_with_params, extra_params))
57
+ end
58
+
59
+ def test_urlalize_does_not_strip_trailing_?
60
+ url_empty_params = 'http://localhost/test?'
61
+ assert_equal(url_empty_params, Curl.urlalize(url_empty_params))
62
+ end
63
+
64
+ include TestServerMethods
35
65
 
36
66
  def setup
37
67
  server_setup
@@ -10,6 +10,76 @@ class TestCurbCurlEasy < Test::Unit::TestCase
10
10
  Curl.reset
11
11
  end
12
12
 
13
+ def test_curlopt_stderr_with_file
14
+ # does not work with Tempfile directly
15
+ path = Tempfile.new('curb_test_curlopt_stderr').path
16
+ File.open(path, 'w') do |file|
17
+ easy = Curl::Easy.new(TestServlet.url)
18
+ easy.verbose = true
19
+ easy.setopt(Curl::CURLOPT_STDERR, file)
20
+ easy.perform
21
+ end
22
+ output = File.read(path)
23
+
24
+ assert_match('HTTP/1.1 200 OK ', output)
25
+ assert_match('Host: 127.0.0.1:9129', output)
26
+ end
27
+
28
+ def test_curlopt_stderr_with_io
29
+ path = Tempfile.new('curb_test_curlopt_stderr').path
30
+ fd = IO.sysopen(path, 'w')
31
+ io = IO.for_fd(fd)
32
+
33
+ easy = Curl::Easy.new(TestServlet.url)
34
+ easy.verbose = true
35
+ easy.setopt(Curl::CURLOPT_STDERR, io)
36
+ easy.perform
37
+
38
+
39
+ output = File.read(path)
40
+
41
+ assert_match(output, 'HTTP/1.1 200 OK')
42
+ assert_match(output, 'Host: 127.0.0.1:9129')
43
+ end
44
+
45
+ def test_curlopt_stderr_fails_with_tempdir
46
+ Tempfile.open('curb_test_curlopt_stderr') do |tempfile|
47
+ easy = Curl::Easy.new(TestServlet.url)
48
+
49
+ assert_raise(TypeError) do
50
+ easy.setopt(Curl::CURLOPT_STDERR, tempfile)
51
+ end
52
+ end
53
+ end
54
+
55
+ def test_curlopt_stderr_fails_with_stringio
56
+ stringio = StringIO.new
57
+ easy = Curl::Easy.new(TestServlet.url)
58
+
59
+ assert_raise(TypeError) do
60
+ easy.setopt(Curl::CURLOPT_STDERR, stringio)
61
+ end
62
+ end
63
+
64
+ def test_curlopt_stderr_fails_with_string
65
+ string = String.new
66
+ easy = Curl::Easy.new(TestServlet.url)
67
+
68
+ assert_raise(TypeError) do
69
+ easy.setopt(Curl::CURLOPT_STDERR, string)
70
+ end
71
+ end
72
+
73
+ def test_exception
74
+ begin
75
+ Curl.get('NOT_FOUND_URL')
76
+ rescue
77
+ assert true
78
+ rescue Exception
79
+ assert false, "We should raise StandardError"
80
+ end
81
+ end
82
+
13
83
  def test_threads
14
84
  t = []
15
85
  5.times do
@@ -18,8 +88,6 @@ class TestCurbCurlEasy < Test::Unit::TestCase
18
88
  c = Curl.get($TEST_URL)
19
89
  assert_match(/^# DO NOT REMOVE THIS COMMENT/, c.body_str)
20
90
  assert_match(/^# DO NOT REMOVE THIS COMMENT/, c.body)
21
- assert_equal "", c.header_str
22
- assert_equal "", c.head
23
91
  end
24
92
  end
25
93
  end
@@ -31,7 +99,6 @@ class TestCurbCurlEasy < Test::Unit::TestCase
31
99
  assert_instance_of Curl::Easy, c = Curl::Easy.perform($TEST_URL)
32
100
  assert_match(/^# DO NOT REMOVE THIS COMMENT/, c.body_str)
33
101
  assert_match(/^# DO NOT REMOVE THIS COMMENT/, c.body)
34
- assert_equal "", c.header_str
35
102
  end
36
103
 
37
104
  def test_class_perform_02
@@ -39,7 +106,6 @@ class TestCurbCurlEasy < Test::Unit::TestCase
39
106
  assert_instance_of Curl::Easy, c = Curl::Easy.perform($TEST_URL) { |curl| curl.on_body { |d| data << d; d.length } }
40
107
 
41
108
  assert_nil c.body_str
42
- assert_equal "", c.header_str
43
109
  assert_match(/^# DO NOT REMOVE THIS COMMENT/, data)
44
110
  end
45
111
 
@@ -134,7 +200,6 @@ class TestCurbCurlEasy < Test::Unit::TestCase
134
200
  c = Curl::Easy.new($TEST_URL)
135
201
  assert_equal true, c.http_get
136
202
  assert_match(/^# DO NOT REMOVE THIS COMMENT/, c.body_str)
137
- assert_equal "", c.header_str
138
203
  end
139
204
 
140
205
  def test_get_02
@@ -146,7 +211,6 @@ class TestCurbCurlEasy < Test::Unit::TestCase
146
211
  assert_equal true, c.http_get
147
212
 
148
213
  assert_nil c.body_str
149
- assert_equal "", c.header_str
150
214
  assert_match(/^# DO NOT REMOVE THIS COMMENT/, data)
151
215
  end
152
216
 
@@ -329,29 +393,69 @@ class TestCurbCurlEasy < Test::Unit::TestCase
329
393
  c.max_redirects = nil
330
394
  assert_nil c.max_redirects
331
395
  end
332
-
396
+
397
+ def test_timeout_with_floats
398
+ c = Curl::Easy.new($TEST_URL)
399
+
400
+ c.timeout = 1.5
401
+ assert_equal 1500, c.timeout_ms
402
+ assert_equal 1.5, c.timeout
403
+ end
404
+
405
+ def test_timeout_with_negative
406
+ c = Curl::Easy.new($TEST_URL)
407
+
408
+ c.timeout = -1.5
409
+ assert_equal 0, c.timeout
410
+ assert_equal 0, c.timeout_ms
411
+
412
+ c.timeout = -4.8
413
+ assert_equal 0, c.timeout
414
+ assert_equal 0, c.timeout_ms
415
+ end
416
+
333
417
  def test_timeout_01
334
418
  c = Curl::Easy.new($TEST_URL)
335
-
336
- assert_nil c.timeout
337
-
419
+
420
+ assert_equal 0, c.timeout
421
+
338
422
  c.timeout = 3
339
423
  assert_equal 3, c.timeout
340
-
341
- c.timeout = nil
342
- assert_nil c.timeout
424
+
425
+ c.timeout = 0
426
+ assert_equal 0, c.timeout
343
427
  end
344
428
 
345
429
  def test_timeout_ms_01
346
430
  c = Curl::Easy.new($TEST_URL)
347
431
 
348
- assert_nil c.timeout_ms
432
+ assert_equal 0, c.timeout_ms
349
433
 
350
434
  c.timeout_ms = 100
351
435
  assert_equal 100, c.timeout_ms
352
436
 
353
437
  c.timeout_ms = nil
354
- assert_nil c.timeout_ms
438
+ assert_equal 0, c.timeout_ms
439
+ end
440
+
441
+ def test_timeout_ms_with_floats
442
+ c = Curl::Easy.new($TEST_URL)
443
+
444
+ c.timeout_ms = 55.5
445
+ assert_equal 55, c.timeout_ms
446
+ assert_equal 0.055, c.timeout
447
+ end
448
+
449
+ def test_timeout_ms_with_negative
450
+ c = Curl::Easy.new($TEST_URL)
451
+
452
+ c.timeout_ms = -1.5
453
+ assert_equal 0, c.timeout
454
+ assert_equal 0, c.timeout_ms
455
+
456
+ c.timeout_ms = -4.8
457
+ assert_equal 0, c.timeout
458
+ assert_equal 0, c.timeout_ms
355
459
  end
356
460
 
357
461
  def test_connect_timeout_01
@@ -598,7 +702,7 @@ class TestCurbCurlEasy < Test::Unit::TestCase
598
702
  def test_cookielist
599
703
  c = Curl::Easy.new TestServlet.url
600
704
  c.enable_cookies = true
601
- c.post_body = URI.encode_www_form c: 'somename=somevalue'
705
+ c.post_body = URI.encode_www_form('c' => 'somename=somevalue')
602
706
  assert_nil c.cookielist
603
707
  c.perform
604
708
  assert_match(/somevalue/, c.cookielist.join(''))
@@ -0,0 +1,16 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
2
+
3
+ class TestCurbCurlEasyResolve < Test::Unit::TestCase
4
+ def setup
5
+ @easy = Curl::Easy.new
6
+ end
7
+
8
+ def test_resolve
9
+ @easy.resolve = [ "example.com:80:127.0.0.1" ]
10
+ assert_equal @easy.resolve, [ "example.com:80:127.0.0.1" ]
11
+ end
12
+
13
+ def test_empty_resolve
14
+ assert_equal @easy.resolve, nil
15
+ end
16
+ end
@@ -0,0 +1,12 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
2
+
3
+ class TestCurbCurlMaxFileSize < Test::Unit::TestCase
4
+ def setup
5
+ @easy = Curl::Easy.new
6
+ end
7
+
8
+ def test_maxfilesize
9
+ @easy.set(Curl::CURLOPT_MAXFILESIZE, 5000000)
10
+ end
11
+
12
+ end
@@ -6,6 +6,70 @@ class TestCurbCurlMulti < Test::Unit::TestCase
6
6
  ObjectSpace.garbage_collect
7
7
  end
8
8
 
9
+ # for https://github.com/taf2/curb/issues/277
10
+ # must connect to an external
11
+ def test_connection_keepalive
12
+ # 0123456 default & reserved RubyVM. It will probably include 7 from Dir.glob
13
+ lsof=`/usr/bin/which lsof`.strip
14
+ open_fds = lambda do
15
+ `#{lsof} -p #{Process.pid} | egrep "TCP|UDP" | wc -l`.strip.to_i
16
+ end
17
+ before_open = open_fds.call
18
+ assert !Curl::Multi.autoclose
19
+ multi = Curl::Multi.new
20
+ multi.max_connects = 1 # limit to 1 connection within the multi handle
21
+
22
+ did_complete = false
23
+ 5.times do |n|
24
+ # NOTE: we use google here because connecting to our TEST_URL as a local host address appears to not register correctly with lsof as a socket... if anyone knows a better way would be great to not have an external dependency here in the test
25
+ easy = Curl::Easy.new("http://google.com/") do |curl|
26
+ curl.timeout = 5 # ensure we don't hang for ever connecting to an external host
27
+ curl.on_complete {
28
+ did_complete = true
29
+ }
30
+ end
31
+ multi.add(easy)
32
+ end
33
+
34
+ multi.perform
35
+ assert did_complete
36
+ after_open = open_fds.call
37
+ assert_equal (after_open - before_open), 1, "with max connections set to 1 at this point the connection to google should still be open"
38
+ multi.close
39
+
40
+ after_open = open_fds.call
41
+ assert_equal (after_open - before_open), 0, "after closing the multi handle all connections should be closed"
42
+
43
+ Curl::Multi.autoclose = true
44
+ multi = Curl::Multi.new
45
+ did_complete = false
46
+ 5.times do |n|
47
+ # NOTE: we use google here because connecting to our TEST_URL as a local host address appears to not register correctly with lsof as a socket... if anyone knows a better way would be great to not have an external dependency here in the test
48
+ easy = Curl::Easy.new("http://google.com/") do |curl|
49
+ curl.timeout = 5 # ensure we don't hang for ever connecting to an external host
50
+ curl.on_complete {
51
+ did_complete = true
52
+ }
53
+ end
54
+ multi.add(easy)
55
+ end
56
+
57
+ multi.perform
58
+ assert did_complete
59
+ after_open = open_fds.call
60
+ assert_equal (after_open - before_open), 0, "auto close the connections"
61
+ ensure
62
+ Curl::Multi.autoclose = false # restore default
63
+ end
64
+
65
+ def test_connection_autoclose
66
+ assert !Curl::Multi.autoclose
67
+ Curl::Multi.autoclose = true
68
+ assert Curl::Multi.autoclose
69
+ ensure
70
+ Curl::Multi.autoclose = false # restore default
71
+ end
72
+
9
73
  def test_new_multi_01
10
74
  d1 = ""
11
75
  c1 = Curl::Easy.new($TEST_URL) do |curl|
@@ -125,7 +189,7 @@ class TestCurbCurlMulti < Test::Unit::TestCase
125
189
  def test_requests
126
190
  m = Curl::Multi.new
127
191
 
128
- assert_equal([], m.requests, 'A new Curl::Multi handle should have no requests')
192
+ assert_equal(0, m.requests.length, 'A new Curl::Multi handle should have no requests')
129
193
 
130
194
  10.times do
131
195
  m.add(Curl::Easy.new($TEST_URL))
@@ -135,7 +199,7 @@ class TestCurbCurlMulti < Test::Unit::TestCase
135
199
 
136
200
  m.perform
137
201
 
138
- assert_equal([], m.requests, 'A new Curl::Multi handle should have no requests after a perform')
202
+ assert_equal(0, m.requests.length, 'A new Curl::Multi handle should have no requests after a perform')
139
203
  end
140
204
 
141
205
  def test_cancel
@@ -148,7 +212,7 @@ class TestCurbCurlMulti < Test::Unit::TestCase
148
212
 
149
213
  m.cancel!
150
214
 
151
- assert_equal([], m.requests, 'A new Curl::Multi handle should have no requests after being canceled')
215
+ assert_equal(0, m.requests.size, 'A new Curl::Multi handle should have no requests after being canceled')
152
216
  end
153
217
 
154
218
  def test_with_success
@@ -192,7 +256,7 @@ class TestCurbCurlMulti < Test::Unit::TestCase
192
256
  c1.on_success do|c|
193
257
  success_called1 = true
194
258
  #puts "success 1 called: #{c.body_str.inspect}"
195
- #assert_match(/^# DO NOT REMOVE THIS COMMENT/, c.body_str)
259
+ assert_match(/^# DO NOT REMOVE THIS COMMENT/, c.body_str)
196
260
  end
197
261
 
198
262
  c1.on_failure do|c,rc|
@@ -484,5 +548,4 @@ class TestCurbCurlMulti < Test::Unit::TestCase
484
548
  def setup
485
549
  server_setup
486
550
  end
487
-
488
551
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: curb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.4
4
+ version: 0.9.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ross Bamford
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-08-26 00:00:00.000000000 Z
12
+ date: 2019-04-18 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Curb (probably CUrl-RuBy or something) provides Ruby-language bindings
15
15
  for the libcurl(3), a fully-featured client-side URL transfer library. cURL and
@@ -51,6 +51,7 @@ files:
51
51
  - tests/bug_curb_easy_post_with_string_no_content_length_header.rb
52
52
  - tests/bug_instance_post_differs_from_class_post.rb
53
53
  - tests/bug_issue102.rb
54
+ - tests/bug_issue277.rb
54
55
  - tests/bug_multi_segfault.rb
55
56
  - tests/bug_postfields_crash.rb
56
57
  - tests/bug_postfields_crash2.rb
@@ -63,13 +64,15 @@ files:
63
64
  - tests/tc_curl.rb
64
65
  - tests/tc_curl_download.rb
65
66
  - tests/tc_curl_easy.rb
67
+ - tests/tc_curl_easy_resolve.rb
66
68
  - tests/tc_curl_easy_setopt.rb
69
+ - tests/tc_curl_maxfilesize.rb
67
70
  - tests/tc_curl_multi.rb
68
71
  - tests/tc_curl_postfield.rb
69
72
  - tests/timeout.rb
70
73
  - tests/timeout_server.rb
71
74
  - tests/unittests.rb
72
- homepage: http://curb.rubyforge.org/
75
+ homepage: https://github.com/taf2/curb
73
76
  licenses:
74
77
  - MIT
75
78
  metadata: {}
@@ -92,33 +95,36 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
95
  version: '0'
93
96
  requirements: []
94
97
  rubyforge_project: curb
95
- rubygems_version: 2.4.3
98
+ rubygems_version: 2.7.9
96
99
  signing_key:
97
100
  specification_version: 4
98
101
  summary: Ruby libcurl bindings
99
102
  test_files:
103
+ - tests/tc_curl_multi.rb
100
104
  - tests/alltests.rb
101
- - tests/bug_crash_on_debug.rb
102
- - tests/bug_crash_on_progress.rb
103
- - tests/bug_curb_easy_blocks_ruby_threads.rb
104
- - tests/bug_curb_easy_post_with_string_no_content_length_header.rb
105
- - tests/bug_instance_post_differs_from_class_post.rb
106
- - tests/bug_issue102.rb
107
- - tests/bug_multi_segfault.rb
105
+ - tests/tc_curl_easy_setopt.rb
106
+ - tests/tc_curl.rb
108
107
  - tests/bug_postfields_crash.rb
108
+ - tests/bug_crash_on_progress.rb
109
+ - tests/helper.rb
110
+ - tests/bug_issue277.rb
109
111
  - tests/bug_postfields_crash2.rb
110
112
  - tests/bug_require_last_or_segfault.rb
111
- - tests/bugtests.rb
112
- - tests/helper.rb
113
- - tests/mem_check.rb
113
+ - tests/timeout.rb
114
+ - tests/bug_crash_on_debug.rb
115
+ - tests/unittests.rb
116
+ - tests/bug_issue102.rb
117
+ - tests/bug_curb_easy_blocks_ruby_threads.rb
118
+ - tests/bug_multi_segfault.rb
119
+ - tests/bug_instance_post_differs_from_class_post.rb
114
120
  - tests/require_last_or_segfault_script.rb
115
- - tests/signals.rb
116
- - tests/tc_curl.rb
121
+ - tests/timeout_server.rb
117
122
  - tests/tc_curl_download.rb
118
123
  - tests/tc_curl_easy.rb
119
- - tests/tc_curl_easy_setopt.rb
120
- - tests/tc_curl_multi.rb
124
+ - tests/mem_check.rb
121
125
  - tests/tc_curl_postfield.rb
122
- - tests/timeout.rb
123
- - tests/timeout_server.rb
124
- - tests/unittests.rb
126
+ - tests/tc_curl_maxfilesize.rb
127
+ - tests/bugtests.rb
128
+ - tests/tc_curl_easy_resolve.rb
129
+ - tests/signals.rb
130
+ - tests/bug_curb_easy_post_with_string_no_content_length_header.rb