rufus-verbs 0.10 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.txt +64 -0
- data/CREDITS.txt +9 -0
- data/LICENSE.txt +21 -0
- data/README.txt +4 -4
- data/Rakefile +80 -0
- data/doc/rdoc-style.css +320 -0
- data/lib/rufus-verbs.rb +3 -0
- data/lib/rufus/verbs.rb +67 -76
- data/lib/rufus/verbs/conditional.rb +78 -88
- data/lib/rufus/verbs/cookies.rb +214 -224
- data/lib/rufus/verbs/digest.rb +173 -182
- data/lib/rufus/verbs/endpoint.rb +496 -502
- data/lib/rufus/verbs/verbose.rb +52 -61
- data/lib/rufus/verbs/version.rb +6 -16
- data/rufus-verbs.gemspec +87 -0
- data/test/auth0_test.rb +22 -25
- data/test/auth1_test.rb +1 -4
- data/test/base.rb +56 -0
- data/test/block_test.rb +25 -27
- data/test/conditional_test.rb +24 -26
- data/test/cookie0_test.rb +98 -100
- data/test/cookie1_test.rb +28 -30
- data/test/dryrun_test.rb +53 -40
- data/test/escape_test.rb +16 -18
- data/test/fopen_test.rb +31 -33
- data/test/https_test.rb +19 -22
- data/test/iconditional_test.rb +36 -38
- data/test/items.rb +189 -189
- data/test/proxy_test.rb +53 -55
- data/test/redir_test.rb +16 -18
- data/test/simple_test.rb +77 -82
- data/test/test.rb +22 -26
- data/test/timeout_test.rb +15 -19
- data/test/uri_test.rb +12 -14
- metadata +38 -17
- data/test/testbase.rb +0 -47
data/test/proxy_test.rb
CHANGED
@@ -7,85 +7,83 @@
|
|
7
7
|
# Thu Jan 17 10:15:52 JST 2008
|
8
8
|
#
|
9
9
|
|
10
|
-
require 'timeout'
|
11
|
-
require 'test/unit'
|
12
10
|
|
13
|
-
require '
|
11
|
+
require File.dirname(__FILE__) + '/base.rb'
|
14
12
|
|
15
13
|
|
16
14
|
class ProxyTest < Test::Unit::TestCase
|
17
15
|
|
18
|
-
|
16
|
+
include Rufus::Verbs
|
19
17
|
|
20
18
|
|
21
|
-
|
19
|
+
def test_0
|
22
20
|
|
23
|
-
|
21
|
+
uri = "http://rufus.rubyforge.org/rufus-verbs/index.html"
|
24
22
|
|
25
|
-
|
23
|
+
res0 = get(uri, :proxy => false)
|
26
24
|
|
27
|
-
|
25
|
+
assert_not_nil res0.body # just displaying the test dot
|
28
26
|
|
29
|
-
|
27
|
+
proxies = find_proxies
|
30
28
|
|
31
|
-
|
29
|
+
res1 = nil
|
32
30
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
end
|
38
|
-
break if res1.code.to_i == 200
|
39
|
-
rescue Exception => e
|
40
|
-
puts "skipped proxy '#{proxy}'"
|
41
|
-
end
|
31
|
+
proxies.each do |proxy|
|
32
|
+
begin
|
33
|
+
Timeout::timeout 2 do
|
34
|
+
res1 = get(uri, :proxy => proxy)
|
42
35
|
end
|
36
|
+
break if res1.code.to_i == 200
|
37
|
+
rescue Exception => e
|
38
|
+
puts "skipped proxy '#{proxy}'"
|
39
|
+
end
|
40
|
+
end
|
43
41
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
42
|
+
if res1.code.to_i != 200
|
43
|
+
puts
|
44
|
+
puts
|
45
|
+
puts "sorry, couldn't find an open proxy, couldn't test the"
|
46
|
+
puts "proxy feature of 'rufus-verbs'"
|
47
|
+
puts
|
48
|
+
puts
|
49
|
+
return
|
50
|
+
end
|
53
51
|
|
54
|
-
|
52
|
+
assert_equal res0.body.length, res1.body.length
|
55
53
|
|
56
|
-
|
57
|
-
|
54
|
+
#p res0.to_hash
|
55
|
+
#p res1.to_hash
|
58
56
|
|
59
|
-
|
57
|
+
via1 = res1["via"]
|
60
58
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
59
|
+
unless via1
|
60
|
+
puts
|
61
|
+
puts
|
62
|
+
puts "seems like no open proxy could be found... no via..."
|
63
|
+
puts "can't test for now"
|
64
|
+
puts
|
65
|
+
puts
|
66
|
+
return
|
67
|
+
end
|
70
68
|
|
71
|
-
|
72
|
-
|
69
|
+
via1 = res1["via"].split(", ")[-1]
|
70
|
+
# last proxy
|
73
71
|
|
74
|
-
|
75
|
-
|
76
|
-
|
72
|
+
assert_no_match /wikimedia\.org/, via1
|
73
|
+
# making sure that the proxy was not one of wikipedia
|
74
|
+
end
|
77
75
|
|
78
|
-
|
76
|
+
protected
|
79
77
|
|
80
|
-
|
78
|
+
def find_proxies
|
81
79
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
80
|
+
res = get "http://freeproxy.ch/proxy.txt"
|
81
|
+
lines = res.body.split "\n"
|
82
|
+
lines[4..-1].collect do |line|
|
83
|
+
l = line.split("\t")
|
84
|
+
'http://' + l[0]
|
85
|
+
end
|
86
|
+
end
|
89
87
|
|
90
88
|
end
|
91
89
|
|
data/test/redir_test.rb
CHANGED
@@ -7,34 +7,32 @@
|
|
7
7
|
# Sun Jan 13 20:02:25 JST 2008
|
8
8
|
#
|
9
9
|
|
10
|
-
require 'test/unit'
|
11
|
-
require 'testbase'
|
12
10
|
|
13
|
-
require '
|
11
|
+
require File.dirname(__FILE__) + '/base.rb'
|
14
12
|
|
15
13
|
|
16
14
|
class RedirTest < Test::Unit::TestCase
|
17
|
-
|
15
|
+
include TestBaseMixin
|
18
16
|
|
19
|
-
|
17
|
+
include Rufus::Verbs
|
20
18
|
|
21
19
|
|
22
|
-
|
20
|
+
def test_0
|
23
21
|
|
24
|
-
|
25
|
-
|
22
|
+
expect 200, {}, get(:uri => "http://localhost:7777/things")
|
23
|
+
end
|
26
24
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
25
|
+
#
|
26
|
+
# testing the :no_redirections directive
|
27
|
+
#
|
28
|
+
def test_1
|
31
29
|
|
32
|
-
|
33
|
-
|
30
|
+
res = get "http://localhost:7777/things", :no_redirections => true
|
31
|
+
assert_equal 303, res.code.to_i
|
34
32
|
|
35
|
-
|
36
|
-
|
33
|
+
res = get("http://localhost:7777/things", :noredir => true)
|
34
|
+
assert_equal 303, res.code.to_i
|
37
35
|
|
38
|
-
|
39
|
-
|
36
|
+
expect 200, {}, get("http://localhost:7777/items", :noredir => true)
|
37
|
+
end
|
40
38
|
end
|
data/test/simple_test.rb
CHANGED
@@ -7,121 +7,116 @@
|
|
7
7
|
# Sun Jan 13 12:33:03 JST 2008
|
8
8
|
#
|
9
9
|
|
10
|
-
require '
|
11
|
-
|
12
|
-
require 'test/unit'
|
13
|
-
require 'testbase'
|
14
|
-
|
15
|
-
require 'rufus/verbs'
|
10
|
+
require File.dirname(__FILE__) + '/base.rb'
|
16
11
|
|
17
12
|
|
18
13
|
class SimpleTest < Test::Unit::TestCase
|
19
|
-
|
20
|
-
|
21
|
-
include Rufus::Verbs
|
14
|
+
include TestBaseMixin
|
22
15
|
|
16
|
+
include Rufus::Verbs
|
23
17
|
|
24
|
-
def test_0
|
25
18
|
|
26
|
-
|
27
|
-
#assert_equal 200, res.code.to_i
|
28
|
-
#assert_equal "{}", res.body.strip
|
29
|
-
expect 200, {}, get(:uri => "http://localhost:7777/items")
|
19
|
+
def test_0
|
30
20
|
|
31
|
-
|
32
|
-
|
33
|
-
|
21
|
+
#res = get :uri => "http://localhost:7777/items"
|
22
|
+
#assert_equal 200, res.code.to_i
|
23
|
+
#assert_equal "{}", res.body.strip
|
24
|
+
expect 200, {}, get(:uri => "http://localhost:7777/items")
|
34
25
|
|
35
|
-
|
26
|
+
res = post :uri => "http://localhost:7777/items/0", :d => "Toto"
|
27
|
+
assert_equal 201, res.code.to_i
|
28
|
+
assert_equal "http://localhost:7777/items/0", res['Location']
|
36
29
|
|
37
|
-
|
38
|
-
assert_equal 200, res.code.to_i
|
39
|
-
assert_equal ({ 0 => "Toto" }), eval(res.body)
|
30
|
+
expect 200, { 0 => "Toto" }, get(:uri => "http://localhost:7777/items")
|
40
31
|
|
41
|
-
|
42
|
-
|
32
|
+
res = get :host => "localhost", :port => 7777, :path => "/items"
|
33
|
+
assert_equal 200, res.code.to_i
|
34
|
+
assert_equal ({ 0 => "Toto" }), eval(res.body)
|
43
35
|
|
44
|
-
|
36
|
+
res = put :uri => "http://localhost:7777/items/0", :d => "Toto2"
|
37
|
+
assert_equal 200, res.code.to_i
|
45
38
|
|
46
|
-
|
47
|
-
assert_equal 200, res.code.to_i
|
39
|
+
expect 200, { 0 => "Toto2" }, get(:uri => "http://localhost:7777/items")
|
48
40
|
|
49
|
-
|
50
|
-
|
41
|
+
res = put :uri => "http://localhost:7777/items/0", :d => "Toto3", :fake_put => true
|
42
|
+
assert_equal 200, res.code.to_i
|
51
43
|
|
52
|
-
|
44
|
+
expect 200, { 0 => "Toto3" }, get(:uri => "http://localhost:7777/items")
|
45
|
+
end
|
53
46
|
|
54
|
-
|
47
|
+
def test_0b
|
55
48
|
|
56
|
-
|
57
|
-
assert_equal 201, res.code.to_i
|
58
|
-
assert_equal "http://localhost:7777/items/0", res['Location']
|
49
|
+
expect 200, {}, get(:uri => "http://localhost:7777/items")
|
59
50
|
|
60
|
-
|
51
|
+
res = post :uri => "http://localhost:7777/items", :d => "Toto"
|
52
|
+
assert_equal 201, res.code.to_i
|
53
|
+
assert_equal "http://localhost:7777/items/0", res['Location']
|
61
54
|
|
62
|
-
|
63
|
-
assert_equal 201, res.code.to_i
|
64
|
-
assert_equal "http://localhost:7777/items/1", res['Location']
|
55
|
+
expect 200, "\"Toto\"", get(:uri => "http://localhost:7777/items/0")
|
65
56
|
|
66
|
-
|
67
|
-
|
57
|
+
res = post :uri => "http://localhost:7777/items", :d => "Smurf"
|
58
|
+
assert_equal 201, res.code.to_i
|
59
|
+
assert_equal "http://localhost:7777/items/1", res['Location']
|
68
60
|
|
69
|
-
|
61
|
+
expect 200, "\"Smurf\"", get(:uri => "http://localhost:7777/items/1")
|
62
|
+
end
|
70
63
|
|
71
|
-
|
72
|
-
expect 200, {}, ep.get(:resource => "items")
|
64
|
+
def test_1
|
73
65
|
|
74
|
-
|
75
|
-
|
76
|
-
end
|
77
|
-
assert_equal 404, res.code.to_i
|
66
|
+
ep = EndPoint.new(:host => "localhost", :port => 7777)
|
67
|
+
expect 200, {}, ep.get(:resource => "items")
|
78
68
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
assert_equal "http://localhost:7777/items/0", res['Location']
|
69
|
+
res = ep.put :resource => "items", :id => 0 do
|
70
|
+
"blockdata"
|
71
|
+
end
|
72
|
+
assert_equal 404, res.code.to_i
|
84
73
|
|
85
|
-
|
74
|
+
res = ep.post :resource => "items", :id => 0 do
|
75
|
+
"blockdata"
|
86
76
|
end
|
77
|
+
assert_equal 201, res.code.to_i
|
78
|
+
assert_equal "http://localhost:7777/items/0", res['Location']
|
87
79
|
|
88
|
-
|
80
|
+
expect 200, { 0 => "blockdata" }, ep.get(:res => "items")
|
81
|
+
end
|
89
82
|
|
90
|
-
|
91
|
-
assert_equal "{}", s.strip
|
92
|
-
end
|
83
|
+
def test_2
|
93
84
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
def test_3
|
85
|
+
s = get(:uri => "http://localhost:7777/items", :body => true)
|
86
|
+
assert_equal "{}", s.strip
|
87
|
+
end
|
98
88
|
|
99
|
-
|
100
|
-
|
101
|
-
|
89
|
+
#
|
90
|
+
# The "no-path" test
|
91
|
+
#
|
92
|
+
def test_3
|
102
93
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
def test_4
|
94
|
+
r = get "http://rufus.rubyforge.org"
|
95
|
+
assert_kind_of Net::HTTPOK, r
|
96
|
+
end
|
107
97
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
98
|
+
#
|
99
|
+
# HEAD
|
100
|
+
#
|
101
|
+
def test_4
|
112
102
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
103
|
+
res = head "http://localhost:7777/items"
|
104
|
+
assert_equal 200, res.code.to_i
|
105
|
+
assert_nil res.body
|
106
|
+
end
|
117
107
|
|
118
|
-
|
119
|
-
|
120
|
-
|
108
|
+
#
|
109
|
+
# OPTIONS
|
110
|
+
#
|
111
|
+
def test_5
|
121
112
|
|
122
|
-
|
113
|
+
r = options "http://localhost:7777/items"
|
114
|
+
assert_equal [ :delete, :get, :head, :options, :post, :put], r
|
115
|
+
end
|
123
116
|
|
124
|
-
|
125
|
-
|
126
|
-
|
117
|
+
def test_6
|
118
|
+
|
119
|
+
r = Rufus::Verbs::options "http://localhost:7777/items"
|
120
|
+
assert_equal [ :delete, :get, :head, :options, :post, :put], r
|
121
|
+
end
|
127
122
|
end
|
data/test/test.rb
CHANGED
@@ -1,28 +1,24 @@
|
|
1
1
|
|
2
|
-
require '
|
3
|
-
|
4
|
-
|
5
|
-
require '
|
6
|
-
require '
|
7
|
-
|
8
|
-
require '
|
9
|
-
|
10
|
-
require '
|
11
|
-
require '
|
12
|
-
|
13
|
-
require '
|
14
|
-
require '
|
15
|
-
require '
|
16
|
-
require '
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
require 'uri_test'
|
25
|
-
require 'fopen_test'
|
26
|
-
|
27
|
-
require 'timeout_test'
|
2
|
+
#require 'dryrun_test'
|
3
|
+
#require 'iconditional_test'
|
4
|
+
#require 'simple_test'
|
5
|
+
#require 'auth0_test'
|
6
|
+
#require 'auth1_test'
|
7
|
+
#require 'redir_test'
|
8
|
+
#require 'block_test'
|
9
|
+
#require 'https_test'
|
10
|
+
#require 'proxy_test'
|
11
|
+
#require 'conditional_test'
|
12
|
+
#require 'cookie0_test'
|
13
|
+
#require 'cookie1_test'
|
14
|
+
#require 'escape_test'
|
15
|
+
#require 'uri_test'
|
16
|
+
#require 'fopen_test'
|
17
|
+
#require 'timeout_test'
|
18
|
+
|
19
|
+
dirpath = File.dirname(__FILE__)
|
20
|
+
|
21
|
+
tests = Dir.new(dirpath).entries.select { |e| e.match(/\_test\.rb$/) }.sort
|
22
|
+
|
23
|
+
tests.each { |t| load "#{dirpath}/#{t}" }
|
28
24
|
|
data/test/timeout_test.rb
CHANGED
@@ -7,32 +7,28 @@
|
|
7
7
|
# Mon May 26 17:04:25 JST 2008
|
8
8
|
#
|
9
9
|
|
10
|
-
require '
|
11
|
-
|
12
|
-
require 'test/unit'
|
13
|
-
require 'testbase'
|
14
|
-
|
15
|
-
require 'rufus/verbs'
|
10
|
+
require File.dirname(__FILE__) + '/base.rb'
|
16
11
|
|
17
12
|
|
18
13
|
class TimeoutTest < Test::Unit::TestCase
|
19
|
-
|
20
|
-
|
21
|
-
include Rufus::Verbs
|
14
|
+
include TestBaseMixin
|
22
15
|
|
16
|
+
include Rufus::Verbs
|
23
17
|
|
24
|
-
def test_0
|
25
18
|
|
26
|
-
|
27
|
-
t = Time.now
|
19
|
+
def test_0
|
28
20
|
|
29
|
-
|
30
|
-
|
31
|
-
rescue Timeout::Error => e
|
32
|
-
error = e
|
33
|
-
end
|
21
|
+
error = nil
|
22
|
+
t = Time.now
|
34
23
|
|
35
|
-
|
36
|
-
|
24
|
+
begin
|
25
|
+
get :uri => "http://localhost:7777/lost", :to => 1
|
26
|
+
rescue Timeout::Error => e
|
27
|
+
error = e
|
37
28
|
end
|
29
|
+
|
30
|
+
assert_not_nil error
|
31
|
+
assert (Time.now - t < 2)
|
32
|
+
end
|
38
33
|
end
|
34
|
+
|