emonti-rbkb 0.6.2.1 → 0.6.6
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +32 -0
- data/README.rdoc +10 -7
- data/Rakefile +47 -0
- data/bin/feed +5 -0
- data/bin/plugsrv +3 -3
- data/cli_usage.rdoc +44 -9
- data/doctor-bag.jpg +0 -0
- data/lib/rbkb.rb +47 -2
- data/lib/rbkb/cli.rb +8 -6
- data/lib/rbkb/cli/b64.rb +5 -0
- data/lib/rbkb/cli/bgrep.rb +14 -9
- data/lib/rbkb/cli/chars.rb +2 -1
- data/lib/rbkb/cli/crc32.rb +4 -1
- data/lib/rbkb/cli/d64.rb +3 -0
- data/lib/rbkb/cli/dedump.rb +5 -3
- data/lib/rbkb/cli/feed.rb +223 -0
- data/lib/rbkb/cli/hexify.rb +3 -3
- data/lib/rbkb/cli/len.rb +12 -9
- data/lib/rbkb/cli/rstrings.rb +13 -10
- data/lib/rbkb/cli/slice.rb +1 -0
- data/lib/rbkb/cli/telson.rb +21 -57
- data/lib/rbkb/cli/unhexify.rb +2 -6
- data/lib/rbkb/cli/urldec.rb +1 -0
- data/lib/rbkb/cli/urlenc.rb +1 -0
- data/lib/rbkb/extends.rb +41 -6
- data/lib/rbkb/http.rb +20 -0
- data/lib/rbkb/http/base.rb +172 -0
- data/lib/rbkb/http/body.rb +214 -0
- data/lib/rbkb/http/common.rb +74 -0
- data/lib/rbkb/http/headers.rb +356 -0
- data/lib/rbkb/http/parameters.rb +101 -0
- data/lib/rbkb/http/request.rb +58 -0
- data/lib/rbkb/http/response.rb +86 -0
- data/lib/rbkb/plug.rb +3 -3
- data/lib/rbkb/plug/cli.rb +83 -0
- data/lib/rbkb/plug/feed_import.rb +74 -0
- data/lib/rbkb/plug/plug.rb +36 -19
- data/lib/rbkb/plug/unix_domain.rb +75 -0
- data/rbkb.gemspec +38 -0
- data/spec/rbkb_spec.rb +7 -0
- data/spec/spec_helper.rb +16 -0
- data/tasks/ann.rake +80 -0
- data/tasks/bones.rake +20 -0
- data/tasks/gem.rake +201 -0
- data/tasks/git.rake +40 -0
- data/tasks/notes.rake +27 -0
- data/tasks/post_load.rake +34 -0
- data/tasks/rdoc.rake +51 -0
- data/tasks/rubyforge.rake +55 -0
- data/tasks/setup.rb +292 -0
- data/tasks/spec.rake +54 -0
- data/tasks/svn.rake +47 -0
- data/tasks/test.rake +40 -0
- data/test/test_cli_b64.rb +35 -0
- data/test/test_cli_bgrep.rb +137 -0
- data/test/test_cli_blit.rb +11 -0
- data/test/test_cli_chars.rb +21 -0
- data/test/test_cli_crc32.rb +108 -0
- data/test/test_cli_d64.rb +22 -0
- data/test/test_cli_dedump.rb +118 -0
- data/test/test_cli_feed.rb +11 -0
- data/test/test_cli_helper.rb +96 -0
- data/test/test_cli_hexify.rb +63 -0
- data/test/test_cli_len.rb +96 -0
- data/test/test_cli_rstrings.rb +15 -0
- data/test/test_cli_slice.rb +73 -0
- data/test/test_cli_telson.rb +11 -0
- data/test/test_cli_unhexify.rb +43 -0
- data/test/test_cli_urldec.rb +50 -0
- data/test/test_cli_urlenc.rb +44 -0
- data/test/test_cli_xor.rb +71 -0
- data/test/test_helper.rb +5 -0
- data/test/test_http.rb +27 -0
- data/test/test_http_helper.rb +60 -0
- data/test/test_http_request.rb +136 -0
- data/test/test_http_response.rb +222 -0
- data/test/test_rbkb.rb +19 -0
- metadata +127 -21
@@ -0,0 +1,44 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "test_cli_helper.rb")
|
2
|
+
require 'rbkb/cli/urlenc'
|
3
|
+
|
4
|
+
class TestCliUrlenc < Test::Unit::TestCase
|
5
|
+
include CliTest
|
6
|
+
|
7
|
+
def setup
|
8
|
+
@cli_class = Rbkb::Cli::Urlenc
|
9
|
+
super()
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_basic_string_arg
|
13
|
+
assert_equal 0, run_with_args(["foo"])
|
14
|
+
assert_equal "foo\n", @stdout_io.string
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_basic_string_arg_space_default
|
18
|
+
assert_equal 0, run_with_args(["fo o"])
|
19
|
+
assert_equal "fo%20o\n", @stdout_io.string
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_basic_string_arg_space_with_p
|
23
|
+
assert_equal 0, run_with_args(["-p", "fo o"])
|
24
|
+
assert_equal "fo+o\n", @stdout_io.string
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_basic_string_arg_space_with_plus
|
28
|
+
assert_equal 0, run_with_args(["--plus", "fo o"])
|
29
|
+
assert_equal "fo+o\n", @stdout_io.string
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_basic_string_arg_space_with_noplus
|
33
|
+
assert_equal 0, run_with_args(["--no-plus", "fo o"])
|
34
|
+
assert_equal "fo%20o\n", @stdout_io.string
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_allchars
|
38
|
+
allchars_dec = (0..255).map {|c| c.chr}.join
|
39
|
+
allchars_enc = "%00%01%02%03%04%05%06%07%08%09%0a%0b%0c%0d%0e%0f%10%11%12%13%14%15%16%17%18%19%1a%1b%1c%1d%1e%1f%20%21%22%23%24%25%26%27%28%29%2a%2b%2c-.%2f0123456789%3a%3b%3c%3d%3e%3f%40ABCDEFGHIJKLMNOPQRSTUVWXYZ%5b%5c%5d%5e_%60abcdefghijklmnopqrstuvwxyz%7b%7c%7d~%7f%80%81%82%83%84%85%86%87%88%89%8a%8b%8c%8d%8e%8f%90%91%92%93%94%95%96%97%98%99%9a%9b%9c%9d%9e%9f%a0%a1%a2%a3%a4%a5%a6%a7%a8%a9%aa%ab%ac%ad%ae%af%b0%b1%b2%b3%b4%b5%b6%b7%b8%b9%ba%bb%bc%bd%be%bf%c0%c1%c2%c3%c4%c5%c6%c7%c8%c9%ca%cb%cc%cd%ce%cf%d0%d1%d2%d3%d4%d5%d6%d7%d8%d9%da%db%dc%dd%de%df%e0%e1%e2%e3%e4%e5%e6%e7%e8%e9%ea%eb%ec%ed%ee%ef%f0%f1%f2%f3%f4%f5%f6%f7%f8%f9%fa%fb%fc%fd%fe%ff"
|
40
|
+
assert_equal 0, run_with_args([allchars_dec])
|
41
|
+
assert_equal allchars_enc, @stdout_io.string.chomp
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "test_cli_helper.rb")
|
2
|
+
require 'rbkb/cli/xor'
|
3
|
+
|
4
|
+
class TestCliXor < Test::Unit::TestCase
|
5
|
+
include CliTest
|
6
|
+
|
7
|
+
def setup
|
8
|
+
@cli_class = Rbkb::Cli::Xor
|
9
|
+
super()
|
10
|
+
|
11
|
+
@tst_dat = "my secrets are very secret"
|
12
|
+
@tst_key_str = "sneaky"
|
13
|
+
@tst_key_hex = "736e65616b79"
|
14
|
+
@tst_xored = "\036\027E\022\016\032\001\v\021\022K\030\001\vE\027\016\v\nN\026\004\b\v\026\032"
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_string_arg_str_key
|
18
|
+
assert_equal 0, go_with_args(["-s", @tst_key_str, @tst_dat])
|
19
|
+
assert_equal @tst_xored, @stdout_io.string
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_string_arg_str_key
|
23
|
+
assert_equal 0, go_with_args(["-x", @tst_key_hex, @tst_dat])
|
24
|
+
assert_equal @tst_xored, @stdout_io.string
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_string_arg_xor_zeroes_out
|
28
|
+
assert_equal 0, go_with_args(%w(-s foo foo))
|
29
|
+
assert_equal "\x00"*3, @stdout_io.string
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_string_arg_xor_zeroes_out_repeating
|
33
|
+
assert_equal 0, go_with_args(%w(-s A AAAAAAAAAA))
|
34
|
+
assert_equal "\x00"*10, @stdout_io.string
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_string_arg_str_key_reverse
|
38
|
+
assert_equal 0, go_with_args(["-s", @tst_key_str, @tst_xored])
|
39
|
+
assert_equal @tst_dat, @stdout_io.string
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_string_arg_str_key_reverse
|
43
|
+
assert_equal 0, go_with_args(["-x", @tst_key_hex, @tst_xored])
|
44
|
+
assert_equal @tst_dat, @stdout_io.string
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_stdin
|
48
|
+
@stdin_io.write(@tst_dat) ; @stdin_io.rewind
|
49
|
+
assert_equal 0, go_with_args(["-s", @tst_key_str])
|
50
|
+
assert_equal @tst_xored, @stdout_io.string
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_file_input
|
54
|
+
with_testfile do |fname, f|
|
55
|
+
f.write(@tst_dat); f.close
|
56
|
+
assert_equal 0, go_with_args(["-s", @tst_key_str, "-f", fname])
|
57
|
+
assert_equal @tst_xored, @stdout_io.string
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_string_arg_no_key_error
|
62
|
+
assert_equal 1, go_with_args(%w(foo))
|
63
|
+
assert_match(/you must specify a key/i, @stderr_io.string)
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_one_key_opt_error
|
67
|
+
assert_equal 1, go_with_args(%w(-x foo -s foo foo))
|
68
|
+
assert_match(/only one key option/i, @stderr_io.string)
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
data/test/test_helper.rb
ADDED
data/test/test_http.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_http_helper.rb'
|
2
|
+
|
3
|
+
class TestHttp < Test::Unit::TestCase
|
4
|
+
include Rbkb::Http
|
5
|
+
|
6
|
+
def test_names
|
7
|
+
assert_equal CommonInterface, Rbkb::Http::CommonInterface
|
8
|
+
assert_equal Base, Rbkb::Http::Base
|
9
|
+
|
10
|
+
assert_equal Response, Rbkb::Http::Response
|
11
|
+
assert_equal Request, Rbkb::Http::Request
|
12
|
+
assert_equal Parameters, Rbkb::Http::Parameters
|
13
|
+
assert_equal FormUrlencodedParams, Rbkb::Http::FormUrlencodedParams
|
14
|
+
|
15
|
+
assert_equal Headers, Rbkb::Http::Headers
|
16
|
+
assert_equal RequestHeaders, Rbkb::Http::RequestHeaders
|
17
|
+
assert_equal RequestAction, Rbkb::Http::RequestAction
|
18
|
+
assert_equal ResponseHeaders, Rbkb::Http::ResponseHeaders
|
19
|
+
assert_equal ResponseStatus, Rbkb::Http::ResponseStatus
|
20
|
+
|
21
|
+
assert_equal Body, Rbkb::Http::Body
|
22
|
+
assert_equal BoundBody, Rbkb::Http::BoundBody
|
23
|
+
assert_equal ChunkedBody, Rbkb::Http::ChunkedBody
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'test_helper.rb')
|
2
|
+
require 'rbkb/http'
|
3
|
+
|
4
|
+
module HttpTestHelper
|
5
|
+
# contains various test cases to test common interface features
|
6
|
+
module CommonInterfaceTests
|
7
|
+
|
8
|
+
def setup()
|
9
|
+
raise "Helper stub called. Override setup() in TestCase"
|
10
|
+
end
|
11
|
+
|
12
|
+
def do_type_tests(x)
|
13
|
+
raise "Helper stub called. Override do_type_tests() in TestCase"
|
14
|
+
end
|
15
|
+
|
16
|
+
def do_type_tests(x)
|
17
|
+
raise "Helper stub called. Override do_capture_value_tests() in TestCase"
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_init_parse
|
21
|
+
req = @obj_klass.new(@rawdat, @obj_opts)
|
22
|
+
do_capture_value_tests(req)
|
23
|
+
do_type_tests(req)
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_parse
|
27
|
+
req = @obj_klass.parse(@rawdat, @obj_opts)
|
28
|
+
do_capture_value_tests(req)
|
29
|
+
do_type_tests(req)
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_capture
|
33
|
+
req = @obj.capture(@rawdat)
|
34
|
+
do_capture_value_tests(req)
|
35
|
+
do_type_tests(req)
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_back_to_raw
|
39
|
+
req = @obj.capture(@rawdat)
|
40
|
+
assert_equal @rawdat_crlf, req.to_raw
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_capture_and_reuse_nondestructive
|
44
|
+
@obj.capture(@rawdat_crlf)
|
45
|
+
@obj.reset_capture
|
46
|
+
@obj.capture(@rawdat_crlf)
|
47
|
+
do_capture_value_tests(@obj)
|
48
|
+
do_type_tests(@obj)
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_capture_and_reuse_destructive
|
52
|
+
@obj.capture(@rawdat_crlf)
|
53
|
+
@obj.reset_capture!
|
54
|
+
@obj.capture(@rawdat_crlf)
|
55
|
+
do_capture_value_tests(@obj)
|
56
|
+
do_type_tests(@obj)
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,136 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_http_helper.rb'
|
2
|
+
|
3
|
+
class TestHttpRequest < Test::Unit::TestCase
|
4
|
+
include HttpTestHelper::CommonInterfaceTests
|
5
|
+
|
6
|
+
include Rbkb::Http
|
7
|
+
|
8
|
+
def setup
|
9
|
+
@obj_klass = Request
|
10
|
+
@obj = @obj_klass.new
|
11
|
+
|
12
|
+
@rawdat =<<_EOF_
|
13
|
+
GET /csi?v=3&s=webhp&action=&tran=undefined HTTP/1.1
|
14
|
+
Host: www.google.com
|
15
|
+
User-Agent: Mozilla/5.0
|
16
|
+
Accept: image/png,image/*;q=0.8,*/*;q=0.5
|
17
|
+
Accept-Language: en-us,en;q=0.5
|
18
|
+
Accept-Encoding: gzip,deflate
|
19
|
+
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
|
20
|
+
Keep-Alive: 300
|
21
|
+
Proxy-Connection: keep-alive
|
22
|
+
Referer: http://www.google.com/
|
23
|
+
Cookie: PREFID=NNNN:LM=1237996892:S=YYYYY; NID=111
|
24
|
+
|
25
|
+
_EOF_
|
26
|
+
|
27
|
+
@hstr, @body = @rawdat.split(/^\n/, 2)
|
28
|
+
@rawdat_crlf = @hstr.gsub("\n", "\r\n") + "\r\n" + @body
|
29
|
+
|
30
|
+
@verb = "GET"
|
31
|
+
@uri = "/csi?v=3&s=webhp&action=&tran=undefined"
|
32
|
+
@path, @query = @uri.split('?',2)
|
33
|
+
@req_parameters = [
|
34
|
+
["v", "3"],
|
35
|
+
["s", "webhp"],
|
36
|
+
["action", ""],
|
37
|
+
["tran", "undefined"]
|
38
|
+
]
|
39
|
+
@version = "HTTP/1.1"
|
40
|
+
|
41
|
+
@headers = [
|
42
|
+
["Host", "www.google.com"],
|
43
|
+
["User-Agent", "Mozilla/5.0"],
|
44
|
+
["Accept", "image/png,image/*;q=0.8,*/*;q=0.5"],
|
45
|
+
["Accept-Language", "en-us,en;q=0.5"],
|
46
|
+
["Accept-Encoding", "gzip,deflate"],
|
47
|
+
["Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7"],
|
48
|
+
["Keep-Alive", "300"],
|
49
|
+
["Proxy-Connection", "keep-alive"],
|
50
|
+
["Referer", "http://www.google.com/"],
|
51
|
+
["Cookie", "PREFID=NNNN:LM=1237996892:S=YYYYY; NID=111"],
|
52
|
+
]
|
53
|
+
end
|
54
|
+
|
55
|
+
def do_type_tests(req)
|
56
|
+
assert_kind_of Request, req
|
57
|
+
assert_kind_of Headers, req.headers
|
58
|
+
assert_kind_of Body, req.body
|
59
|
+
assert_kind_of RequestAction, req.action
|
60
|
+
assert_kind_of RequestHeaders, req.headers
|
61
|
+
end
|
62
|
+
|
63
|
+
def do_capture_value_tests(req)
|
64
|
+
assert_equal @headers, req.headers
|
65
|
+
assert_equal @body, req.body.to_s
|
66
|
+
assert_equal @uri, req.action.uri.to_s
|
67
|
+
assert_equal @path, req.action.uri.path
|
68
|
+
assert_equal @query, req.action.uri.query
|
69
|
+
assert_equal @verb, req.action.verb
|
70
|
+
assert_equal @version, req.action.version
|
71
|
+
assert_equal @req_parameters, req.request_parameters
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_capture_crlf_headers
|
75
|
+
req = @obj.capture(@rawdat_crlf)
|
76
|
+
do_capture_value_tests(req)
|
77
|
+
do_type_tests(req)
|
78
|
+
assert_equal @rawdat_crlf, req.to_raw
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_captured_body_type
|
82
|
+
@obj.capture(@rawdat)
|
83
|
+
assert_kind_of Body, @obj.body
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
|
88
|
+
|
89
|
+
class TestHttpPostRequest < TestHttpRequest
|
90
|
+
|
91
|
+
def setup
|
92
|
+
@obj_klass = Request
|
93
|
+
@obj = @obj_klass.new
|
94
|
+
|
95
|
+
@rawdat =<<_EOF_
|
96
|
+
POST /path/script.cgi?qtype=foo HTTP/1.0
|
97
|
+
From: frog@jmarshall.com
|
98
|
+
HasColon: this_has_a_colon:yikes
|
99
|
+
User-Agent: HTTPTool/1.0
|
100
|
+
Content-Type: application/x-www-form-urlencoded
|
101
|
+
Content-Length: 32
|
102
|
+
|
103
|
+
home=Cosby&favorite+flavor=flies
|
104
|
+
_EOF_
|
105
|
+
@rawdat.chomp!
|
106
|
+
|
107
|
+
@hstr, @body = @rawdat.split(/^\n/, 2)
|
108
|
+
@rawdat_crlf = @hstr.gsub("\n", "\r\n") + "\r\n" + @body
|
109
|
+
|
110
|
+
@verb = "POST"
|
111
|
+
@uri = "/path/script.cgi?qtype=foo"
|
112
|
+
@path, @query = @uri.split('?',2)
|
113
|
+
@req_parameters = [
|
114
|
+
["qtype", "foo"],
|
115
|
+
]
|
116
|
+
@version = "HTTP/1.0"
|
117
|
+
|
118
|
+
@headers = [
|
119
|
+
["From", "frog@jmarshall.com"],
|
120
|
+
["HasColon", "this_has_a_colon:yikes"],
|
121
|
+
["User-Agent", "HTTPTool/1.0"],
|
122
|
+
["Content-Type", "application/x-www-form-urlencoded"],
|
123
|
+
["Content-Length", "32"],
|
124
|
+
]
|
125
|
+
|
126
|
+
@post_parameters = [["home", "Cosby"], ["favorite+flavor", "flies"]]
|
127
|
+
end
|
128
|
+
|
129
|
+
def test_captured_body_type
|
130
|
+
@obj.capture(@rawdat)
|
131
|
+
assert_kind_of BoundBody, @obj.body
|
132
|
+
end
|
133
|
+
|
134
|
+
|
135
|
+
end
|
136
|
+
|
@@ -0,0 +1,222 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_http_helper.rb'
|
2
|
+
|
3
|
+
class TestHttpResponse < Test::Unit::TestCase
|
4
|
+
include HttpTestHelper::CommonInterfaceTests
|
5
|
+
|
6
|
+
include Rbkb::Http
|
7
|
+
|
8
|
+
def setup
|
9
|
+
@obj_klass = Response
|
10
|
+
@obj_opts = nil
|
11
|
+
@obj = @obj_klass.new(nil, @obj_opts)
|
12
|
+
|
13
|
+
@rawdat =<<_EOF_
|
14
|
+
HTTP/1.0 404 Not Found
|
15
|
+
Date: Thu, 26 Mar 2009 01:18:52 GMT
|
16
|
+
Server: Apache
|
17
|
+
Content-Type: text/html; charset=iso-8859-1
|
18
|
+
Content-Length: 190
|
19
|
+
Connection: Keep-Alive
|
20
|
+
|
21
|
+
<html><head>
|
22
|
+
<title>Error report</title></head>
|
23
|
+
<body><h1>HTTP Status 404</h1><HR size="1" noshade><p><u>The requested resource is not available.</u></p><HR size="1" noshade>
|
24
|
+
</body></html>
|
25
|
+
_EOF_
|
26
|
+
|
27
|
+
@hstr, @body = @rawdat.split(/^\n/, 2)
|
28
|
+
@rawdat_crlf = @hstr.gsub("\n", "\r\n") + "\r\n" + @body
|
29
|
+
|
30
|
+
@code = 404
|
31
|
+
@text = "Not Found"
|
32
|
+
@version = "HTTP/1.0"
|
33
|
+
|
34
|
+
@headers = [
|
35
|
+
["Date", "Thu, 26 Mar 2009 01:18:52 GMT"],
|
36
|
+
["Server", "Apache"],
|
37
|
+
["Content-Type", "text/html; charset=iso-8859-1"],
|
38
|
+
["Content-Length", "190"],
|
39
|
+
["Connection", "Keep-Alive"]
|
40
|
+
]
|
41
|
+
|
42
|
+
@content_length = 190
|
43
|
+
end
|
44
|
+
|
45
|
+
def do_type_tests(rsp)
|
46
|
+
assert_kind_of Response, rsp
|
47
|
+
assert_kind_of Headers, rsp.headers
|
48
|
+
assert_kind_of Body, rsp.body
|
49
|
+
assert_kind_of ResponseStatus, rsp.status
|
50
|
+
assert_kind_of ResponseHeaders, rsp.headers
|
51
|
+
end
|
52
|
+
|
53
|
+
def do_capture_value_tests(rsp)
|
54
|
+
assert_equal @headers, rsp.headers
|
55
|
+
assert_equal @body, rsp.body
|
56
|
+
assert_equal @code, rsp.status.code
|
57
|
+
assert_equal @text, rsp.status.text
|
58
|
+
assert_equal @version, rsp.status.version
|
59
|
+
assert_equal @content_length, rsp.content_length
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_capture_crlf_headers
|
63
|
+
@obj.capture(@rawdat_crlf)
|
64
|
+
do_capture_value_tests(@obj)
|
65
|
+
do_type_tests(@obj)
|
66
|
+
assert_equal @rawdat_crlf, @obj.to_raw
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_captured_body_type
|
70
|
+
@obj.capture(@rawdat)
|
71
|
+
assert_kind_of BoundBody, @obj.body
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
class TestHttpResponseChunked < TestHttpResponse
|
77
|
+
include Rbkb::Http
|
78
|
+
|
79
|
+
def setup
|
80
|
+
@obj_klass = Response
|
81
|
+
@obj_opts = {}
|
82
|
+
@obj = @obj_klass.new
|
83
|
+
|
84
|
+
@rawdat =<<_EOF_
|
85
|
+
HTTP/1.1 200 OK
|
86
|
+
Date: Thu, 26 Mar 2009 01:18:52 GMT
|
87
|
+
Server: Apache
|
88
|
+
Content-Type: text/html; charset=iso-8859-1
|
89
|
+
Transfer-Encoding: chunked
|
90
|
+
Connection: Keep-Alive
|
91
|
+
|
92
|
+
20
|
93
|
+
This is a test of a chunked-enco
|
94
|
+
|
95
|
+
10
|
96
|
+
ded HTTP request
|
97
|
+
|
98
|
+
0
|
99
|
+
_EOF_
|
100
|
+
|
101
|
+
@hstr, @rawbody = @rawdat.split(/^\n/, 2)
|
102
|
+
@rawdat_crlf = @rawdat.gsub("\n", "\r\n")
|
103
|
+
@hdrs_crlf = @hstr.gsub("\n", "\r\n")
|
104
|
+
|
105
|
+
@body = "This is a test of a chunked-encoded HTTP request"
|
106
|
+
|
107
|
+
@code = 200
|
108
|
+
@text = "OK"
|
109
|
+
@version = "HTTP/1.1"
|
110
|
+
|
111
|
+
@headers = [
|
112
|
+
["Date", "Thu, 26 Mar 2009 01:18:52 GMT"],
|
113
|
+
["Server", "Apache"],
|
114
|
+
["Content-Type", "text/html; charset=iso-8859-1"],
|
115
|
+
["Transfer-Encoding", "chunked"],
|
116
|
+
["Connection", "Keep-Alive"]
|
117
|
+
]
|
118
|
+
|
119
|
+
@content_length = nil
|
120
|
+
@tc_chunk_size = 0x20
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_captured_body_type
|
124
|
+
@obj.capture(@rawdat)
|
125
|
+
assert_kind_of ChunkedBody, @obj.body
|
126
|
+
end
|
127
|
+
|
128
|
+
def test_back_to_raw
|
129
|
+
@obj.capture(@rawdat)
|
130
|
+
do_capture_value_tests(@obj)
|
131
|
+
do_type_tests(@obj)
|
132
|
+
@obj.body.opts[:output_chunk_size] = @tc_chunk_size
|
133
|
+
assert_equal @rawdat_crlf, @obj.to_raw
|
134
|
+
end
|
135
|
+
|
136
|
+
def test_capture_crlf_headers
|
137
|
+
@obj.capture(@rawdat_crlf)
|
138
|
+
do_capture_value_tests(@obj)
|
139
|
+
do_type_tests(@obj)
|
140
|
+
@obj.body.opts[:output_chunk_size] = @tc_chunk_size
|
141
|
+
assert_equal @rawdat_crlf, @obj.to_raw
|
142
|
+
end
|
143
|
+
|
144
|
+
def test_default_chunk_size
|
145
|
+
if @body.size > ChunkedBody::DEFAULT_CHUNK_SIZE
|
146
|
+
assert "TESTCASE ERROR!!!", "make the setup() @body < DEFAULT_CHUNK_SIZE"
|
147
|
+
end
|
148
|
+
raw_tc = "#{@hdrs_crlf}\r\n#{@body.size.to_s(16)}\r\n#{@body}\r\n\r\n0\r\n"
|
149
|
+
@obj.capture(@rawdat_crlf)
|
150
|
+
do_capture_value_tests(@obj)
|
151
|
+
do_type_tests(@obj)
|
152
|
+
assert_equal raw_tc, @obj.to_raw
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
# This test-case simulates a HTTP response to a HEAD request. This type of
|
157
|
+
# response is special since it returns Content-Length: NNN or
|
158
|
+
# Transfer-Encoding: chunked headers without any actual body data.
|
159
|
+
# To handle this special situation, we use the 'ignore_content_length' and
|
160
|
+
# 'ignore_chunked_encoding' options.
|
161
|
+
class TestHttpResponseToHead < TestHttpResponse
|
162
|
+
def setup
|
163
|
+
@obj_klass = Response
|
164
|
+
|
165
|
+
# Technically, a server should only respond to HEAD with one of
|
166
|
+
# content length *or* chunked encoding. However, we ignore them both.
|
167
|
+
@obj_opts = {
|
168
|
+
:ignore_content_length => true,
|
169
|
+
:ignore_chunked_encoding => true
|
170
|
+
}
|
171
|
+
@obj = @obj_klass.new(nil, @obj_opts)
|
172
|
+
|
173
|
+
# Note, our test-case includes both content length and chunked encoding.
|
174
|
+
# A real server probably wouldn't do this, but we want to make sure
|
175
|
+
# we handle both.
|
176
|
+
@rawdat =<<_EOF_
|
177
|
+
HTTP/1.1 200 OK
|
178
|
+
Cache-Control: private, max-age=0
|
179
|
+
Date: Fri, 27 Mar 2009 04:27:27 GMT
|
180
|
+
Expires: -1
|
181
|
+
Content-Length: 9140
|
182
|
+
Content-Type: text/html; charset=ISO-8859-1
|
183
|
+
Server: Booble
|
184
|
+
Transfer-Encoding: chunked
|
185
|
+
|
186
|
+
_EOF_
|
187
|
+
|
188
|
+
@hstr, @body = @rawdat.split(/^\n/, 2)
|
189
|
+
@rawdat_crlf = @hstr.gsub("\n", "\r\n") + "\r\n" + @body
|
190
|
+
|
191
|
+
@code = 200
|
192
|
+
@text = "OK"
|
193
|
+
@version = "HTTP/1.1"
|
194
|
+
|
195
|
+
@headers = [
|
196
|
+
["Cache-Control", "private, max-age=0"],
|
197
|
+
["Date", "Fri, 27 Mar 2009 04:27:27 GMT"],
|
198
|
+
["Expires", "-1"],
|
199
|
+
["Content-Length", "9140"],
|
200
|
+
["Content-Type", "text/html; charset=ISO-8859-1"],
|
201
|
+
["Server", "Booble"],
|
202
|
+
["Transfer-Encoding", "chunked"]
|
203
|
+
]
|
204
|
+
|
205
|
+
# Content length should get ignored
|
206
|
+
@content_length = nil
|
207
|
+
end
|
208
|
+
|
209
|
+
def test_capture_crlf_headers
|
210
|
+
@obj.capture(@rawdat_crlf)
|
211
|
+
do_capture_value_tests(@obj)
|
212
|
+
do_type_tests(@obj)
|
213
|
+
assert_equal @rawdat_crlf, @obj.to_raw
|
214
|
+
end
|
215
|
+
|
216
|
+
def test_captured_body_type
|
217
|
+
@obj.capture(@rawdat)
|
218
|
+
assert_kind_of Body, @obj.body
|
219
|
+
end
|
220
|
+
|
221
|
+
end
|
222
|
+
|