webrick 1.3.1 → 1.4.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of webrick might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/lib/webrick.rb +6 -6
- data/lib/webrick/accesslog.rb +9 -1
- data/lib/webrick/cgi.rb +51 -2
- data/lib/webrick/compat.rb +2 -1
- data/lib/webrick/config.rb +42 -5
- data/lib/webrick/cookie.rb +68 -6
- data/lib/webrick/htmlutils.rb +4 -2
- data/lib/webrick/httpauth.rb +1 -0
- data/lib/webrick/httpauth/authenticator.rb +13 -8
- data/lib/webrick/httpauth/basicauth.rb +3 -3
- data/lib/webrick/httpauth/digestauth.rb +25 -9
- data/lib/webrick/httpauth/htdigest.rb +8 -4
- data/lib/webrick/httpauth/htgroup.rb +1 -0
- data/lib/webrick/httpauth/htpasswd.rb +7 -3
- data/lib/webrick/httpauth/userdb.rb +1 -0
- data/lib/webrick/httpproxy.rb +47 -14
- data/lib/webrick/httprequest.rb +142 -16
- data/lib/webrick/httpresponse.rb +96 -24
- data/lib/webrick/https.rb +24 -1
- data/lib/webrick/httpserver.rb +20 -4
- data/lib/webrick/httpservlet.rb +1 -0
- data/lib/webrick/httpservlet/abstract.rb +2 -1
- data/lib/webrick/httpservlet/cgi_runner.rb +1 -0
- data/lib/webrick/httpservlet/cgihandler.rb +19 -5
- data/lib/webrick/httpservlet/erbhandler.rb +2 -1
- data/lib/webrick/httpservlet/filehandler.rb +87 -34
- data/lib/webrick/httpservlet/prochandler.rb +14 -0
- data/lib/webrick/httpstatus.rb +24 -10
- data/lib/webrick/httputils.rb +129 -13
- data/lib/webrick/httpversion.rb +28 -1
- data/lib/webrick/log.rb +22 -2
- data/lib/webrick/server.rb +203 -60
- data/lib/webrick/ssl.rb +80 -5
- data/lib/webrick/utils.rb +97 -67
- data/lib/webrick/version.rb +6 -1
- metadata +59 -69
- data/README.txt +0 -21
- data/sample/webrick/demo-app.rb +0 -66
- data/sample/webrick/demo-multipart.cgi +0 -12
- data/sample/webrick/demo-servlet.rb +0 -6
- data/sample/webrick/demo-urlencoded.cgi +0 -12
- data/sample/webrick/hello.cgi +0 -11
- data/sample/webrick/hello.rb +0 -8
- data/sample/webrick/httpd.rb +0 -23
- data/sample/webrick/httpproxy.rb +0 -25
- data/sample/webrick/httpsd.rb +0 -33
- data/test/openssl/utils.rb +0 -313
- data/test/ruby/envutil.rb +0 -208
- data/test/webrick/test_cgi.rb +0 -134
- data/test/webrick/test_cookie.rb +0 -131
- data/test/webrick/test_filehandler.rb +0 -285
- data/test/webrick/test_httpauth.rb +0 -167
- data/test/webrick/test_httpproxy.rb +0 -282
- data/test/webrick/test_httprequest.rb +0 -411
- data/test/webrick/test_httpresponse.rb +0 -49
- data/test/webrick/test_httpserver.rb +0 -305
- data/test/webrick/test_httputils.rb +0 -96
- data/test/webrick/test_httpversion.rb +0 -40
- data/test/webrick/test_server.rb +0 -67
- data/test/webrick/test_utils.rb +0 -64
- data/test/webrick/utils.rb +0 -58
- data/test/webrick/webrick.cgi +0 -36
- data/test/webrick/webrick_long_filename.cgi +0 -36
@@ -1,49 +0,0 @@
|
|
1
|
-
require "webrick"
|
2
|
-
require "minitest/autorun"
|
3
|
-
|
4
|
-
module WEBrick
|
5
|
-
class TestHTTPResponse < MiniTest::Unit::TestCase
|
6
|
-
class FakeLogger
|
7
|
-
attr_reader :messages
|
8
|
-
|
9
|
-
def initialize
|
10
|
-
@messages = []
|
11
|
-
end
|
12
|
-
|
13
|
-
def warn msg
|
14
|
-
@messages << msg
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
attr_reader :config, :logger, :res
|
19
|
-
|
20
|
-
def setup
|
21
|
-
super
|
22
|
-
@logger = FakeLogger.new
|
23
|
-
@config = Config::HTTP
|
24
|
-
@config[:Logger] = logger
|
25
|
-
@res = HTTPResponse.new config
|
26
|
-
@res.keep_alive = true
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_304_does_not_log_warning
|
30
|
-
res.status = 304
|
31
|
-
res.setup_header
|
32
|
-
assert_equal 0, logger.messages.length
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_204_does_not_log_warning
|
36
|
-
res.status = 204
|
37
|
-
res.setup_header
|
38
|
-
|
39
|
-
assert_equal 0, logger.messages.length
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_1xx_does_not_log_warnings
|
43
|
-
res.status = 105
|
44
|
-
res.setup_header
|
45
|
-
|
46
|
-
assert_equal 0, logger.messages.length
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
@@ -1,305 +0,0 @@
|
|
1
|
-
require "test/unit"
|
2
|
-
require "net/http"
|
3
|
-
require "webrick"
|
4
|
-
require_relative "utils"
|
5
|
-
|
6
|
-
class TestWEBrickHTTPServer < Test::Unit::TestCase
|
7
|
-
def test_mount
|
8
|
-
httpd = WEBrick::HTTPServer.new(
|
9
|
-
:Logger => WEBrick::Log.new(TestWEBrick::NullWriter),
|
10
|
-
:DoNotListen=>true
|
11
|
-
)
|
12
|
-
httpd.mount("/", :Root)
|
13
|
-
httpd.mount("/foo", :Foo)
|
14
|
-
httpd.mount("/foo/bar", :Bar, :bar1)
|
15
|
-
httpd.mount("/foo/bar/baz", :Baz, :baz1, :baz2)
|
16
|
-
|
17
|
-
serv, opts, script_name, path_info = httpd.search_servlet("/")
|
18
|
-
assert_equal(:Root, serv)
|
19
|
-
assert_equal([], opts)
|
20
|
-
assert_equal(script_name, "")
|
21
|
-
assert_equal(path_info, "/")
|
22
|
-
|
23
|
-
serv, opts, script_name, path_info = httpd.search_servlet("/sub")
|
24
|
-
assert_equal(:Root, serv)
|
25
|
-
assert_equal([], opts)
|
26
|
-
assert_equal(script_name, "")
|
27
|
-
assert_equal(path_info, "/sub")
|
28
|
-
|
29
|
-
serv, opts, script_name, path_info = httpd.search_servlet("/sub/")
|
30
|
-
assert_equal(:Root, serv)
|
31
|
-
assert_equal([], opts)
|
32
|
-
assert_equal(script_name, "")
|
33
|
-
assert_equal(path_info, "/sub/")
|
34
|
-
|
35
|
-
serv, opts, script_name, path_info = httpd.search_servlet("/foo")
|
36
|
-
assert_equal(:Foo, serv)
|
37
|
-
assert_equal([], opts)
|
38
|
-
assert_equal(script_name, "/foo")
|
39
|
-
assert_equal(path_info, "")
|
40
|
-
|
41
|
-
serv, opts, script_name, path_info = httpd.search_servlet("/foo/")
|
42
|
-
assert_equal(:Foo, serv)
|
43
|
-
assert_equal([], opts)
|
44
|
-
assert_equal(script_name, "/foo")
|
45
|
-
assert_equal(path_info, "/")
|
46
|
-
|
47
|
-
serv, opts, script_name, path_info = httpd.search_servlet("/foo/sub")
|
48
|
-
assert_equal(:Foo, serv)
|
49
|
-
assert_equal([], opts)
|
50
|
-
assert_equal(script_name, "/foo")
|
51
|
-
assert_equal(path_info, "/sub")
|
52
|
-
|
53
|
-
serv, opts, script_name, path_info = httpd.search_servlet("/foo/bar")
|
54
|
-
assert_equal(:Bar, serv)
|
55
|
-
assert_equal([:bar1], opts)
|
56
|
-
assert_equal(script_name, "/foo/bar")
|
57
|
-
assert_equal(path_info, "")
|
58
|
-
|
59
|
-
serv, opts, script_name, path_info = httpd.search_servlet("/foo/bar/baz")
|
60
|
-
assert_equal(:Baz, serv)
|
61
|
-
assert_equal([:baz1, :baz2], opts)
|
62
|
-
assert_equal(script_name, "/foo/bar/baz")
|
63
|
-
assert_equal(path_info, "")
|
64
|
-
end
|
65
|
-
|
66
|
-
class Req
|
67
|
-
attr_reader :port, :host
|
68
|
-
def initialize(addr, port, host)
|
69
|
-
@addr, @port, @host = addr, port, host
|
70
|
-
end
|
71
|
-
def addr
|
72
|
-
[0,0,0,@addr]
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
def httpd(addr, port, host, ali)
|
77
|
-
config ={
|
78
|
-
:Logger => WEBrick::Log.new(TestWEBrick::NullWriter),
|
79
|
-
:DoNotListen => true,
|
80
|
-
:BindAddress => addr,
|
81
|
-
:Port => port,
|
82
|
-
:ServerName => host,
|
83
|
-
:ServerAlias => ali,
|
84
|
-
}
|
85
|
-
return WEBrick::HTTPServer.new(config)
|
86
|
-
end
|
87
|
-
|
88
|
-
def assert_eql?(v1, v2)
|
89
|
-
assert_equal(v1.object_id, v2.object_id)
|
90
|
-
end
|
91
|
-
|
92
|
-
def test_lookup_server
|
93
|
-
addr1 = "192.168.100.1"
|
94
|
-
addr2 = "192.168.100.2"
|
95
|
-
addrz = "192.168.100.254"
|
96
|
-
local = "127.0.0.1"
|
97
|
-
port1 = 80
|
98
|
-
port2 = 8080
|
99
|
-
port3 = 10080
|
100
|
-
portz = 32767
|
101
|
-
name1 = "www.example.com"
|
102
|
-
name2 = "www2.example.com"
|
103
|
-
name3 = "www3.example.com"
|
104
|
-
namea = "www.example.co.jp"
|
105
|
-
nameb = "www.example.jp"
|
106
|
-
namec = "www2.example.co.jp"
|
107
|
-
named = "www2.example.jp"
|
108
|
-
namez = "foobar.example.com"
|
109
|
-
alias1 = [namea, nameb]
|
110
|
-
alias2 = [namec, named]
|
111
|
-
|
112
|
-
host1 = httpd(nil, port1, name1, nil)
|
113
|
-
hosts = [
|
114
|
-
host2 = httpd(addr1, port1, name1, nil),
|
115
|
-
host3 = httpd(addr1, port1, name2, alias1),
|
116
|
-
host4 = httpd(addr1, port2, name1, nil),
|
117
|
-
host5 = httpd(addr1, port2, name2, alias1),
|
118
|
-
host6 = httpd(addr1, port2, name3, alias2),
|
119
|
-
host7 = httpd(addr2, nil, name1, nil),
|
120
|
-
host8 = httpd(addr2, nil, name2, alias1),
|
121
|
-
host9 = httpd(addr2, nil, name3, alias2),
|
122
|
-
host10 = httpd(local, nil, nil, nil),
|
123
|
-
host11 = httpd(nil, port3, nil, nil),
|
124
|
-
].sort_by{ rand }
|
125
|
-
hosts.each{|h| host1.virtual_host(h) }
|
126
|
-
|
127
|
-
# connect to addr1
|
128
|
-
assert_eql?(host2, host1.lookup_server(Req.new(addr1, port1, name1)))
|
129
|
-
assert_eql?(host3, host1.lookup_server(Req.new(addr1, port1, name2)))
|
130
|
-
assert_eql?(host3, host1.lookup_server(Req.new(addr1, port1, namea)))
|
131
|
-
assert_eql?(host3, host1.lookup_server(Req.new(addr1, port1, nameb)))
|
132
|
-
assert_eql?(nil, host1.lookup_server(Req.new(addr1, port1, namez)))
|
133
|
-
assert_eql?(host4, host1.lookup_server(Req.new(addr1, port2, name1)))
|
134
|
-
assert_eql?(host5, host1.lookup_server(Req.new(addr1, port2, name2)))
|
135
|
-
assert_eql?(host5, host1.lookup_server(Req.new(addr1, port2, namea)))
|
136
|
-
assert_eql?(host5, host1.lookup_server(Req.new(addr1, port2, nameb)))
|
137
|
-
assert_eql?(nil, host1.lookup_server(Req.new(addr1, port2, namez)))
|
138
|
-
assert_eql?(host11, host1.lookup_server(Req.new(addr1, port3, name1)))
|
139
|
-
assert_eql?(host11, host1.lookup_server(Req.new(addr1, port3, name2)))
|
140
|
-
assert_eql?(host11, host1.lookup_server(Req.new(addr1, port3, namea)))
|
141
|
-
assert_eql?(host11, host1.lookup_server(Req.new(addr1, port3, nameb)))
|
142
|
-
assert_eql?(host11, host1.lookup_server(Req.new(addr1, port3, namez)))
|
143
|
-
assert_eql?(nil, host1.lookup_server(Req.new(addr1, portz, name1)))
|
144
|
-
assert_eql?(nil, host1.lookup_server(Req.new(addr1, portz, name2)))
|
145
|
-
assert_eql?(nil, host1.lookup_server(Req.new(addr1, portz, namea)))
|
146
|
-
assert_eql?(nil, host1.lookup_server(Req.new(addr1, portz, nameb)))
|
147
|
-
assert_eql?(nil, host1.lookup_server(Req.new(addr1, portz, namez)))
|
148
|
-
|
149
|
-
# connect to addr2
|
150
|
-
assert_eql?(host7, host1.lookup_server(Req.new(addr2, port1, name1)))
|
151
|
-
assert_eql?(host8, host1.lookup_server(Req.new(addr2, port1, name2)))
|
152
|
-
assert_eql?(host8, host1.lookup_server(Req.new(addr2, port1, namea)))
|
153
|
-
assert_eql?(host8, host1.lookup_server(Req.new(addr2, port1, nameb)))
|
154
|
-
assert_eql?(nil, host1.lookup_server(Req.new(addr2, port1, namez)))
|
155
|
-
assert_eql?(host7, host1.lookup_server(Req.new(addr2, port2, name1)))
|
156
|
-
assert_eql?(host8, host1.lookup_server(Req.new(addr2, port2, name2)))
|
157
|
-
assert_eql?(host8, host1.lookup_server(Req.new(addr2, port2, namea)))
|
158
|
-
assert_eql?(host8, host1.lookup_server(Req.new(addr2, port2, nameb)))
|
159
|
-
assert_eql?(nil, host1.lookup_server(Req.new(addr2, port2, namez)))
|
160
|
-
assert_eql?(host7, host1.lookup_server(Req.new(addr2, port3, name1)))
|
161
|
-
assert_eql?(host8, host1.lookup_server(Req.new(addr2, port3, name2)))
|
162
|
-
assert_eql?(host8, host1.lookup_server(Req.new(addr2, port3, namea)))
|
163
|
-
assert_eql?(host8, host1.lookup_server(Req.new(addr2, port3, nameb)))
|
164
|
-
assert_eql?(host11, host1.lookup_server(Req.new(addr2, port3, namez)))
|
165
|
-
assert_eql?(host7, host1.lookup_server(Req.new(addr2, portz, name1)))
|
166
|
-
assert_eql?(host8, host1.lookup_server(Req.new(addr2, portz, name2)))
|
167
|
-
assert_eql?(host8, host1.lookup_server(Req.new(addr2, portz, namea)))
|
168
|
-
assert_eql?(host8, host1.lookup_server(Req.new(addr2, portz, nameb)))
|
169
|
-
assert_eql?(nil, host1.lookup_server(Req.new(addr2, portz, namez)))
|
170
|
-
|
171
|
-
# connect to addrz
|
172
|
-
assert_eql?(nil, host1.lookup_server(Req.new(addrz, port1, name1)))
|
173
|
-
assert_eql?(nil, host1.lookup_server(Req.new(addrz, port1, name2)))
|
174
|
-
assert_eql?(nil, host1.lookup_server(Req.new(addrz, port1, namea)))
|
175
|
-
assert_eql?(nil, host1.lookup_server(Req.new(addrz, port1, nameb)))
|
176
|
-
assert_eql?(nil, host1.lookup_server(Req.new(addrz, port1, namez)))
|
177
|
-
assert_eql?(nil, host1.lookup_server(Req.new(addrz, port2, name1)))
|
178
|
-
assert_eql?(nil, host1.lookup_server(Req.new(addrz, port2, name2)))
|
179
|
-
assert_eql?(nil, host1.lookup_server(Req.new(addrz, port2, namea)))
|
180
|
-
assert_eql?(nil, host1.lookup_server(Req.new(addrz, port2, nameb)))
|
181
|
-
assert_eql?(nil, host1.lookup_server(Req.new(addrz, port2, namez)))
|
182
|
-
assert_eql?(host11, host1.lookup_server(Req.new(addrz, port3, name1)))
|
183
|
-
assert_eql?(host11, host1.lookup_server(Req.new(addrz, port3, name2)))
|
184
|
-
assert_eql?(host11, host1.lookup_server(Req.new(addrz, port3, namea)))
|
185
|
-
assert_eql?(host11, host1.lookup_server(Req.new(addrz, port3, nameb)))
|
186
|
-
assert_eql?(host11, host1.lookup_server(Req.new(addrz, port3, namez)))
|
187
|
-
assert_eql?(nil, host1.lookup_server(Req.new(addrz, portz, name1)))
|
188
|
-
assert_eql?(nil, host1.lookup_server(Req.new(addrz, portz, name2)))
|
189
|
-
assert_eql?(nil, host1.lookup_server(Req.new(addrz, portz, namea)))
|
190
|
-
assert_eql?(nil, host1.lookup_server(Req.new(addrz, portz, nameb)))
|
191
|
-
assert_eql?(nil, host1.lookup_server(Req.new(addrz, portz, namez)))
|
192
|
-
|
193
|
-
# connect to localhost
|
194
|
-
assert_eql?(host10, host1.lookup_server(Req.new(local, port1, name1)))
|
195
|
-
assert_eql?(host10, host1.lookup_server(Req.new(local, port1, name2)))
|
196
|
-
assert_eql?(host10, host1.lookup_server(Req.new(local, port1, namea)))
|
197
|
-
assert_eql?(host10, host1.lookup_server(Req.new(local, port1, nameb)))
|
198
|
-
assert_eql?(host10, host1.lookup_server(Req.new(local, port1, namez)))
|
199
|
-
assert_eql?(host10, host1.lookup_server(Req.new(local, port2, name1)))
|
200
|
-
assert_eql?(host10, host1.lookup_server(Req.new(local, port2, name2)))
|
201
|
-
assert_eql?(host10, host1.lookup_server(Req.new(local, port2, namea)))
|
202
|
-
assert_eql?(host10, host1.lookup_server(Req.new(local, port2, nameb)))
|
203
|
-
assert_eql?(host10, host1.lookup_server(Req.new(local, port2, namez)))
|
204
|
-
assert_eql?(host10, host1.lookup_server(Req.new(local, port3, name1)))
|
205
|
-
assert_eql?(host10, host1.lookup_server(Req.new(local, port3, name2)))
|
206
|
-
assert_eql?(host10, host1.lookup_server(Req.new(local, port3, namea)))
|
207
|
-
assert_eql?(host10, host1.lookup_server(Req.new(local, port3, nameb)))
|
208
|
-
assert_eql?(host10, host1.lookup_server(Req.new(local, port3, namez)))
|
209
|
-
assert_eql?(host10, host1.lookup_server(Req.new(local, portz, name1)))
|
210
|
-
assert_eql?(host10, host1.lookup_server(Req.new(local, portz, name2)))
|
211
|
-
assert_eql?(host10, host1.lookup_server(Req.new(local, portz, namea)))
|
212
|
-
assert_eql?(host10, host1.lookup_server(Req.new(local, portz, nameb)))
|
213
|
-
assert_eql?(host10, host1.lookup_server(Req.new(local, portz, namez)))
|
214
|
-
end
|
215
|
-
|
216
|
-
def test_callbacks
|
217
|
-
accepted = started = stopped = 0
|
218
|
-
requested0 = requested1 = 0
|
219
|
-
config = {
|
220
|
-
:ServerName => "localhost",
|
221
|
-
:AcceptCallback => Proc.new{ accepted += 1 },
|
222
|
-
:StartCallback => Proc.new{ started += 1 },
|
223
|
-
:StopCallback => Proc.new{ stopped += 1 },
|
224
|
-
:RequestCallback => Proc.new{|req, res| requested0 += 1 },
|
225
|
-
}
|
226
|
-
TestWEBrick.start_httpserver(config){|server, addr, port, log|
|
227
|
-
vhost_config = {
|
228
|
-
:ServerName => "myhostname",
|
229
|
-
:BindAddress => addr,
|
230
|
-
:Port => port,
|
231
|
-
:DoNotListen => true,
|
232
|
-
:Logger => WEBrick::Log.new(TestWEBrick::NullWriter),
|
233
|
-
:AccessLog => [],
|
234
|
-
:RequestCallback => Proc.new{|req, res| requested1 += 1 },
|
235
|
-
}
|
236
|
-
server.virtual_host(WEBrick::HTTPServer.new(vhost_config))
|
237
|
-
|
238
|
-
true while server.status != :Running
|
239
|
-
assert_equal(started, 1, log.call)
|
240
|
-
assert_equal(stopped, 0, log.call)
|
241
|
-
assert_equal(accepted, 0, log.call)
|
242
|
-
|
243
|
-
http = Net::HTTP.new(addr, port)
|
244
|
-
req = Net::HTTP::Get.new("/")
|
245
|
-
req["Host"] = "myhostname:#{port}"
|
246
|
-
http.request(req){|res| assert_equal("404", res.code, log.call)}
|
247
|
-
http.request(req){|res| assert_equal("404", res.code, log.call)}
|
248
|
-
http.request(req){|res| assert_equal("404", res.code, log.call)}
|
249
|
-
req["Host"] = "localhost:#{port}"
|
250
|
-
http.request(req){|res| assert_equal("404", res.code, log.call)}
|
251
|
-
http.request(req){|res| assert_equal("404", res.code, log.call)}
|
252
|
-
http.request(req){|res| assert_equal("404", res.code, log.call)}
|
253
|
-
assert_equal(6, accepted, log.call)
|
254
|
-
assert_equal(3, requested0, log.call)
|
255
|
-
assert_equal(3, requested1, log.call)
|
256
|
-
}
|
257
|
-
assert_equal(started, 1)
|
258
|
-
assert_equal(stopped, 1)
|
259
|
-
end
|
260
|
-
|
261
|
-
def test_response_io_without_chunked_set
|
262
|
-
config = {
|
263
|
-
:ServerName => "localhost"
|
264
|
-
}
|
265
|
-
TestWEBrick.start_httpserver(config){|server, addr, port, log|
|
266
|
-
server.mount_proc("/", lambda { |req, res|
|
267
|
-
r,w = IO.pipe
|
268
|
-
# Test for not setting chunked...
|
269
|
-
# res.chunked = true
|
270
|
-
res.body = r
|
271
|
-
w << "foo"
|
272
|
-
w.close
|
273
|
-
})
|
274
|
-
Thread.pass while server.status != :Running
|
275
|
-
http = Net::HTTP.new(addr, port)
|
276
|
-
req = Net::HTTP::Get.new("/")
|
277
|
-
req['Connection'] = 'Keep-Alive'
|
278
|
-
begin
|
279
|
-
timeout(2) do
|
280
|
-
http.request(req){|res| assert_equal("foo", res.body) }
|
281
|
-
end
|
282
|
-
rescue Timeout::Error
|
283
|
-
flunk('corrupted reponse')
|
284
|
-
end
|
285
|
-
}
|
286
|
-
end
|
287
|
-
|
288
|
-
def test_request_handler_callback_is_deprecated
|
289
|
-
requested = 0
|
290
|
-
config = {
|
291
|
-
:ServerName => "localhost",
|
292
|
-
:RequestHandler => Proc.new{|req, res| requested += 1 },
|
293
|
-
}
|
294
|
-
TestWEBrick.start_httpserver(config){|server, addr, port, log|
|
295
|
-
true while server.status != :Running
|
296
|
-
|
297
|
-
http = Net::HTTP.new(addr, port)
|
298
|
-
req = Net::HTTP::Get.new("/")
|
299
|
-
req["Host"] = "localhost:#{port}"
|
300
|
-
http.request(req){|res| assert_equal("404", res.code, log.call)}
|
301
|
-
assert_match(%r{:RequestHandler is deprecated, please use :RequestCallback$}, log.call, log.call)
|
302
|
-
}
|
303
|
-
assert_equal(requested, 1)
|
304
|
-
end
|
305
|
-
end
|
@@ -1,96 +0,0 @@
|
|
1
|
-
require "test/unit"
|
2
|
-
require "webrick/httputils"
|
3
|
-
|
4
|
-
class TestWEBrickHTTPUtils < Test::Unit::TestCase
|
5
|
-
include WEBrick::HTTPUtils
|
6
|
-
|
7
|
-
def test_normilize_path
|
8
|
-
assert_equal("/foo", normalize_path("/foo"))
|
9
|
-
assert_equal("/foo/bar/", normalize_path("/foo/bar/"))
|
10
|
-
|
11
|
-
assert_equal("/", normalize_path("/foo/../"))
|
12
|
-
assert_equal("/", normalize_path("/foo/.."))
|
13
|
-
assert_equal("/", normalize_path("/foo/bar/../../"))
|
14
|
-
assert_equal("/", normalize_path("/foo/bar/../.."))
|
15
|
-
assert_equal("/", normalize_path("/foo/bar/../.."))
|
16
|
-
assert_equal("/baz", normalize_path("/foo/bar/../../baz"))
|
17
|
-
assert_equal("/baz", normalize_path("/foo/../bar/../baz"))
|
18
|
-
assert_equal("/baz/", normalize_path("/foo/../bar/../baz/"))
|
19
|
-
assert_equal("/...", normalize_path("/bar/../..."))
|
20
|
-
assert_equal("/.../", normalize_path("/bar/../.../"))
|
21
|
-
|
22
|
-
assert_equal("/foo/", normalize_path("/foo/./"))
|
23
|
-
assert_equal("/foo/", normalize_path("/foo/."))
|
24
|
-
assert_equal("/foo/", normalize_path("/foo/././"))
|
25
|
-
assert_equal("/foo/", normalize_path("/foo/./."))
|
26
|
-
assert_equal("/foo/bar", normalize_path("/foo/./bar"))
|
27
|
-
assert_equal("/foo/bar/", normalize_path("/foo/./bar/."))
|
28
|
-
assert_equal("/foo/bar/", normalize_path("/./././foo/./bar/."))
|
29
|
-
|
30
|
-
assert_equal("/foo/bar/", normalize_path("//foo///.//bar/.///.//"))
|
31
|
-
assert_equal("/", normalize_path("//foo///..///bar/.///..//.//"))
|
32
|
-
|
33
|
-
assert_raise(RuntimeError){ normalize_path("foo/bar") }
|
34
|
-
assert_raise(RuntimeError){ normalize_path("..") }
|
35
|
-
assert_raise(RuntimeError){ normalize_path("/..") }
|
36
|
-
assert_raise(RuntimeError){ normalize_path("/./..") }
|
37
|
-
assert_raise(RuntimeError){ normalize_path("/./../") }
|
38
|
-
assert_raise(RuntimeError){ normalize_path("/./../..") }
|
39
|
-
assert_raise(RuntimeError){ normalize_path("/./../../") }
|
40
|
-
assert_raise(RuntimeError){ normalize_path("/./../") }
|
41
|
-
assert_raise(RuntimeError){ normalize_path("/../..") }
|
42
|
-
assert_raise(RuntimeError){ normalize_path("/../../") }
|
43
|
-
assert_raise(RuntimeError){ normalize_path("/../../..") }
|
44
|
-
assert_raise(RuntimeError){ normalize_path("/../../../") }
|
45
|
-
assert_raise(RuntimeError){ normalize_path("/../foo/../") }
|
46
|
-
assert_raise(RuntimeError){ normalize_path("/../foo/../../") }
|
47
|
-
assert_raise(RuntimeError){ normalize_path("/foo/bar/../../../../") }
|
48
|
-
assert_raise(RuntimeError){ normalize_path("/foo/../bar/../../") }
|
49
|
-
assert_raise(RuntimeError){ normalize_path("/./../bar/") }
|
50
|
-
assert_raise(RuntimeError){ normalize_path("/./../") }
|
51
|
-
end
|
52
|
-
|
53
|
-
def test_split_header_value
|
54
|
-
assert_equal(['foo', 'bar'], split_header_value('foo, bar'))
|
55
|
-
assert_equal(['"foo"', 'bar'], split_header_value('"foo", bar'))
|
56
|
-
assert_equal(['foo', '"bar"'], split_header_value('foo, "bar"'))
|
57
|
-
assert_equal(['*'], split_header_value('*'))
|
58
|
-
assert_equal(['W/"xyzzy"', 'W/"r2d2xxxx"', 'W/"c3piozzzz"'],
|
59
|
-
split_header_value('W/"xyzzy", W/"r2d2xxxx", W/"c3piozzzz"'))
|
60
|
-
end
|
61
|
-
|
62
|
-
def test_escape
|
63
|
-
assert_equal("/foo/bar", escape("/foo/bar"))
|
64
|
-
assert_equal("/~foo/bar", escape("/~foo/bar"))
|
65
|
-
assert_equal("/~foo%20bar", escape("/~foo bar"))
|
66
|
-
assert_equal("/~foo%20bar", escape("/~foo bar"))
|
67
|
-
assert_equal("/~foo%09bar", escape("/~foo\tbar"))
|
68
|
-
assert_equal("/~foo+bar", escape("/~foo+bar"))
|
69
|
-
end
|
70
|
-
|
71
|
-
def test_escape_form
|
72
|
-
assert_equal("%2Ffoo%2Fbar", escape_form("/foo/bar"))
|
73
|
-
assert_equal("%2F~foo%2Fbar", escape_form("/~foo/bar"))
|
74
|
-
assert_equal("%2F~foo+bar", escape_form("/~foo bar"))
|
75
|
-
assert_equal("%2F~foo+%2B+bar", escape_form("/~foo + bar"))
|
76
|
-
end
|
77
|
-
|
78
|
-
def test_unescape
|
79
|
-
assert_equal("/foo/bar", unescape("%2ffoo%2fbar"))
|
80
|
-
assert_equal("/~foo/bar", unescape("/%7efoo/bar"))
|
81
|
-
assert_equal("/~foo/bar", unescape("%2f%7efoo%2fbar"))
|
82
|
-
assert_equal("/~foo+bar", unescape("/%7efoo+bar"))
|
83
|
-
end
|
84
|
-
|
85
|
-
def test_unescape_form
|
86
|
-
assert_equal("//foo/bar", unescape_form("/%2Ffoo/bar"))
|
87
|
-
assert_equal("//foo/bar baz", unescape_form("/%2Ffoo/bar+baz"))
|
88
|
-
assert_equal("/~foo/bar baz", unescape_form("/%7Efoo/bar+baz"))
|
89
|
-
end
|
90
|
-
|
91
|
-
def test_escape_path
|
92
|
-
assert_equal("/foo/bar", escape_path("/foo/bar"))
|
93
|
-
assert_equal("/foo/bar/", escape_path("/foo/bar/"))
|
94
|
-
assert_equal("/%25foo/bar/", escape_path("/%foo/bar/"))
|
95
|
-
end
|
96
|
-
end
|