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
data/test/ruby/envutil.rb
DELETED
@@ -1,208 +0,0 @@
|
|
1
|
-
require "open3"
|
2
|
-
require "timeout"
|
3
|
-
|
4
|
-
module EnvUtil
|
5
|
-
def rubybin
|
6
|
-
unless ENV["RUBYOPT"]
|
7
|
-
|
8
|
-
end
|
9
|
-
if ruby = ENV["RUBY"]
|
10
|
-
return ruby
|
11
|
-
end
|
12
|
-
ruby = "ruby"
|
13
|
-
rubyexe = ruby+".exe"
|
14
|
-
3.times do
|
15
|
-
if File.exist? ruby and File.executable? ruby and !File.directory? ruby
|
16
|
-
return File.expand_path(ruby)
|
17
|
-
end
|
18
|
-
if File.exist? rubyexe and File.executable? rubyexe
|
19
|
-
return File.expand_path(rubyexe)
|
20
|
-
end
|
21
|
-
ruby = File.join("..", ruby)
|
22
|
-
end
|
23
|
-
if defined?(RbConfig.ruby)
|
24
|
-
RbConfig.ruby
|
25
|
-
else
|
26
|
-
"ruby"
|
27
|
-
end
|
28
|
-
end
|
29
|
-
module_function :rubybin
|
30
|
-
|
31
|
-
LANG_ENVS = %w"LANG LC_ALL LC_CTYPE"
|
32
|
-
|
33
|
-
def invoke_ruby(args, stdin_data="", capture_stdout=false, capture_stderr=false, opt={})
|
34
|
-
in_c, in_p = IO.pipe
|
35
|
-
out_p, out_c = IO.pipe if capture_stdout
|
36
|
-
err_p, err_c = IO.pipe if capture_stderr && capture_stderr != :merge_to_stdout
|
37
|
-
opt = opt.dup
|
38
|
-
opt[:in] = in_c
|
39
|
-
opt[:out] = out_c if capture_stdout
|
40
|
-
opt[:err] = capture_stderr == :merge_to_stdout ? out_c : err_c if capture_stderr
|
41
|
-
if enc = opt.delete(:encoding)
|
42
|
-
out_p.set_encoding(enc) if out_p
|
43
|
-
err_p.set_encoding(enc) if err_p
|
44
|
-
end
|
45
|
-
timeout = opt.delete(:timeout) || 10
|
46
|
-
c = "C"
|
47
|
-
child_env = {}
|
48
|
-
LANG_ENVS.each {|lc| child_env[lc] = c}
|
49
|
-
if Array === args and Hash === args.first
|
50
|
-
child_env.update(args.shift)
|
51
|
-
end
|
52
|
-
args = [args] if args.kind_of?(String)
|
53
|
-
pid = spawn(child_env, EnvUtil.rubybin, *args, opt)
|
54
|
-
in_c.close
|
55
|
-
out_c.close if capture_stdout
|
56
|
-
err_c.close if capture_stderr && capture_stderr != :merge_to_stdout
|
57
|
-
if block_given?
|
58
|
-
return yield in_p, out_p, err_p
|
59
|
-
else
|
60
|
-
th_stdout = Thread.new { out_p.read } if capture_stdout
|
61
|
-
th_stderr = Thread.new { err_p.read } if capture_stderr && capture_stderr != :merge_to_stdout
|
62
|
-
in_p.write stdin_data.to_str
|
63
|
-
in_p.close
|
64
|
-
if (!th_stdout || th_stdout.join(timeout)) && (!th_stderr || th_stderr.join(timeout))
|
65
|
-
stdout = th_stdout.value if capture_stdout
|
66
|
-
stderr = th_stderr.value if capture_stderr && capture_stderr != :merge_to_stdout
|
67
|
-
else
|
68
|
-
raise Timeout::Error
|
69
|
-
end
|
70
|
-
out_p.close if capture_stdout
|
71
|
-
err_p.close if capture_stderr && capture_stderr != :merge_to_stdout
|
72
|
-
Process.wait pid
|
73
|
-
status = $?
|
74
|
-
return stdout, stderr, status
|
75
|
-
end
|
76
|
-
ensure
|
77
|
-
[in_c, in_p, out_c, out_p, err_c, err_p].each do |io|
|
78
|
-
io.close if io && !io.closed?
|
79
|
-
end
|
80
|
-
[th_stdout, th_stderr].each do |th|
|
81
|
-
(th.kill; th.join) if th
|
82
|
-
end
|
83
|
-
end
|
84
|
-
module_function :invoke_ruby
|
85
|
-
|
86
|
-
alias rubyexec invoke_ruby
|
87
|
-
class << self
|
88
|
-
alias rubyexec invoke_ruby
|
89
|
-
end
|
90
|
-
|
91
|
-
def verbose_warning
|
92
|
-
class << (stderr = "")
|
93
|
-
alias write <<
|
94
|
-
end
|
95
|
-
stderr, $stderr, verbose, $VERBOSE = $stderr, stderr, $VERBOSE, true
|
96
|
-
yield stderr
|
97
|
-
ensure
|
98
|
-
stderr, $stderr, $VERBOSE = $stderr, stderr, verbose
|
99
|
-
return stderr
|
100
|
-
end
|
101
|
-
module_function :verbose_warning
|
102
|
-
|
103
|
-
def suppress_warning
|
104
|
-
verbose, $VERBOSE = $VERBOSE, nil
|
105
|
-
yield
|
106
|
-
ensure
|
107
|
-
$VERBOSE = verbose
|
108
|
-
end
|
109
|
-
module_function :suppress_warning
|
110
|
-
|
111
|
-
def under_gc_stress
|
112
|
-
stress, GC.stress = GC.stress, true
|
113
|
-
yield
|
114
|
-
ensure
|
115
|
-
GC.stress = stress
|
116
|
-
end
|
117
|
-
module_function :under_gc_stress
|
118
|
-
end
|
119
|
-
|
120
|
-
module Test
|
121
|
-
module Unit
|
122
|
-
module Assertions
|
123
|
-
public
|
124
|
-
def assert_normal_exit(testsrc, message = '', opt = {})
|
125
|
-
if opt.include?(:child_env)
|
126
|
-
opt = opt.dup
|
127
|
-
child_env = [opt.delete(:child_env)] || []
|
128
|
-
else
|
129
|
-
child_env = []
|
130
|
-
end
|
131
|
-
out, _, status = EnvUtil.invoke_ruby(child_env + %W'-W0', testsrc, true, :merge_to_stdout, opt)
|
132
|
-
pid = status.pid
|
133
|
-
faildesc = proc do
|
134
|
-
signo = status.termsig
|
135
|
-
signame = Signal.list.invert[signo]
|
136
|
-
sigdesc = "signal #{signo}"
|
137
|
-
if signame
|
138
|
-
sigdesc = "SIG#{signame} (#{sigdesc})"
|
139
|
-
end
|
140
|
-
if status.coredump?
|
141
|
-
sigdesc << " (core dumped)"
|
142
|
-
end
|
143
|
-
full_message = ''
|
144
|
-
if !message.empty?
|
145
|
-
full_message << message << "\n"
|
146
|
-
end
|
147
|
-
full_message << "pid #{pid} killed by #{sigdesc}"
|
148
|
-
if !out.empty?
|
149
|
-
out << "\n" if /\n\z/ !~ out
|
150
|
-
full_message << "\n#{out.gsub(/^/, '| ')}"
|
151
|
-
end
|
152
|
-
full_message
|
153
|
-
end
|
154
|
-
assert !status.signaled?, faildesc
|
155
|
-
end
|
156
|
-
|
157
|
-
def assert_in_out_err(args, test_stdin = "", test_stdout = [], test_stderr = [], message = nil, opt={})
|
158
|
-
stdout, stderr, status = EnvUtil.invoke_ruby(args, test_stdin, true, true, opt)
|
159
|
-
if block_given?
|
160
|
-
yield(stdout.lines.map {|l| l.chomp }, stderr.lines.map {|l| l.chomp })
|
161
|
-
else
|
162
|
-
if test_stdout.is_a?(Regexp)
|
163
|
-
assert_match(test_stdout, stdout, message)
|
164
|
-
else
|
165
|
-
assert_equal(test_stdout, stdout.lines.map {|l| l.chomp }, message)
|
166
|
-
end
|
167
|
-
if test_stderr.is_a?(Regexp)
|
168
|
-
assert_match(test_stderr, stderr, message)
|
169
|
-
else
|
170
|
-
assert_equal(test_stderr, stderr.lines.map {|l| l.chomp }, message)
|
171
|
-
end
|
172
|
-
status
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
def assert_ruby_status(args, test_stdin="", message=nil, opt={})
|
177
|
-
_, _, status = EnvUtil.invoke_ruby(args, test_stdin, false, false, opt)
|
178
|
-
m = message ? "#{message} (#{status.inspect})" : "ruby exit status is not success: #{status.inspect}"
|
179
|
-
assert(status.success?, m)
|
180
|
-
end
|
181
|
-
|
182
|
-
def assert_warn(msg)
|
183
|
-
stderr = EnvUtil.verbose_warning { yield }
|
184
|
-
assert(msg === stderr, "warning message #{stderr.inspect} is expected to match #{msg.inspect}")
|
185
|
-
end
|
186
|
-
|
187
|
-
end
|
188
|
-
end
|
189
|
-
end
|
190
|
-
|
191
|
-
begin
|
192
|
-
require 'rbconfig'
|
193
|
-
rescue LoadError
|
194
|
-
else
|
195
|
-
module RbConfig
|
196
|
-
@ruby = EnvUtil.rubybin
|
197
|
-
class << self
|
198
|
-
undef ruby if method_defined?(:ruby)
|
199
|
-
attr_reader :ruby
|
200
|
-
end
|
201
|
-
dir = File.dirname(ruby)
|
202
|
-
name = File.basename(ruby, CONFIG['EXEEXT'])
|
203
|
-
CONFIG['bindir'] = dir
|
204
|
-
CONFIG['ruby_install_name'] = name
|
205
|
-
CONFIG['RUBY_INSTALL_NAME'] = name
|
206
|
-
Gem::ConfigMap[:bindir] = dir if defined?(Gem::ConfigMap)
|
207
|
-
end
|
208
|
-
end
|
data/test/webrick/test_cgi.rb
DELETED
@@ -1,134 +0,0 @@
|
|
1
|
-
require_relative "utils"
|
2
|
-
require "webrick"
|
3
|
-
require "test/unit"
|
4
|
-
|
5
|
-
class TestWEBrickCGI < Test::Unit::TestCase
|
6
|
-
CRLF = "\r\n"
|
7
|
-
|
8
|
-
def start_cgi_server(&block)
|
9
|
-
config = {
|
10
|
-
:CGIInterpreter => TestWEBrick::RubyBin,
|
11
|
-
:DocumentRoot => File.dirname(__FILE__),
|
12
|
-
:DirectoryIndex => ["webrick.cgi"],
|
13
|
-
:RequestCallback => Proc.new{|req, res|
|
14
|
-
def req.meta_vars
|
15
|
-
meta = super
|
16
|
-
meta["RUBYLIB"] = $:.join(File::PATH_SEPARATOR)
|
17
|
-
meta[RbConfig::CONFIG['LIBPATHENV']] = ENV[RbConfig::CONFIG['LIBPATHENV']] if RbConfig::CONFIG['LIBPATHENV']
|
18
|
-
return meta
|
19
|
-
end
|
20
|
-
},
|
21
|
-
}
|
22
|
-
if RUBY_PLATFORM =~ /mswin32|mingw|cygwin|bccwin32/
|
23
|
-
config[:CGIPathEnv] = ENV['PATH'] # runtime dll may not be in system dir.
|
24
|
-
end
|
25
|
-
TestWEBrick.start_httpserver(config){|server, addr, port, log|
|
26
|
-
block.call(server, addr, port, log)
|
27
|
-
}
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_cgi
|
31
|
-
start_cgi_server{|server, addr, port, log|
|
32
|
-
http = Net::HTTP.new(addr, port)
|
33
|
-
req = Net::HTTP::Get.new("/webrick.cgi")
|
34
|
-
http.request(req){|res| assert_equal("/webrick.cgi", res.body, log.call)}
|
35
|
-
req = Net::HTTP::Get.new("/webrick.cgi/path/info")
|
36
|
-
http.request(req){|res| assert_equal("/path/info", res.body, log.call)}
|
37
|
-
req = Net::HTTP::Get.new("/webrick.cgi/%3F%3F%3F?foo=bar")
|
38
|
-
http.request(req){|res| assert_equal("/???", res.body, log.call)}
|
39
|
-
req = Net::HTTP::Get.new("/webrick.cgi/%A4%DB%A4%B2/%A4%DB%A4%B2")
|
40
|
-
http.request(req){|res|
|
41
|
-
assert_equal("/\xA4\xDB\xA4\xB2/\xA4\xDB\xA4\xB2", res.body, log.call)}
|
42
|
-
req = Net::HTTP::Get.new("/webrick.cgi?a=1;a=2;b=x")
|
43
|
-
http.request(req){|res| assert_equal("a=1, a=2, b=x", res.body, log.call)}
|
44
|
-
req = Net::HTTP::Get.new("/webrick.cgi?a=1&a=2&b=x")
|
45
|
-
http.request(req){|res| assert_equal("a=1, a=2, b=x", res.body, log.call)}
|
46
|
-
|
47
|
-
req = Net::HTTP::Post.new("/webrick.cgi?a=x;a=y;b=1")
|
48
|
-
req["Content-Type"] = "application/x-www-form-urlencoded"
|
49
|
-
http.request(req, "a=1;a=2;b=x"){|res|
|
50
|
-
assert_equal("a=1, a=2, b=x", res.body, log.call)}
|
51
|
-
req = Net::HTTP::Post.new("/webrick.cgi?a=x&a=y&b=1")
|
52
|
-
req["Content-Type"] = "application/x-www-form-urlencoded"
|
53
|
-
http.request(req, "a=1&a=2&b=x"){|res|
|
54
|
-
assert_equal("a=1, a=2, b=x", res.body, log.call)}
|
55
|
-
req = Net::HTTP::Get.new("/")
|
56
|
-
http.request(req){|res|
|
57
|
-
ary = res.body.lines.to_a
|
58
|
-
assert_match(%r{/$}, ary[0], log.call)
|
59
|
-
assert_match(%r{/webrick.cgi$}, ary[1], log.call)
|
60
|
-
}
|
61
|
-
|
62
|
-
req = Net::HTTP::Get.new("/webrick.cgi")
|
63
|
-
req["Cookie"] = "CUSTOMER=WILE_E_COYOTE; PART_NUMBER=ROCKET_LAUNCHER_0001"
|
64
|
-
http.request(req){|res|
|
65
|
-
assert_equal(
|
66
|
-
"CUSTOMER=WILE_E_COYOTE\nPART_NUMBER=ROCKET_LAUNCHER_0001\n",
|
67
|
-
res.body, log.call)
|
68
|
-
}
|
69
|
-
|
70
|
-
req = Net::HTTP::Get.new("/webrick.cgi")
|
71
|
-
cookie = %{$Version="1"; }
|
72
|
-
cookie << %{Customer="WILE_E_COYOTE"; $Path="/acme"; }
|
73
|
-
cookie << %{Part_Number="Rocket_Launcher_0001"; $Path="/acme"; }
|
74
|
-
cookie << %{Shipping="FedEx"; $Path="/acme"}
|
75
|
-
req["Cookie"] = cookie
|
76
|
-
http.request(req){|res|
|
77
|
-
assert_equal("Customer=WILE_E_COYOTE, Shipping=FedEx",
|
78
|
-
res["Set-Cookie"], log.call)
|
79
|
-
assert_equal("Customer=WILE_E_COYOTE\n" +
|
80
|
-
"Part_Number=Rocket_Launcher_0001\n" +
|
81
|
-
"Shipping=FedEx\n", res.body, log.call)
|
82
|
-
}
|
83
|
-
}
|
84
|
-
end
|
85
|
-
|
86
|
-
def test_bad_request
|
87
|
-
start_cgi_server{|server, addr, port, log|
|
88
|
-
sock = TCPSocket.new(addr, port)
|
89
|
-
begin
|
90
|
-
sock << "POST /webrick.cgi HTTP/1.0" << CRLF
|
91
|
-
sock << "Content-Type: application/x-www-form-urlencoded" << CRLF
|
92
|
-
sock << "Content-Length: 1024" << CRLF
|
93
|
-
sock << CRLF
|
94
|
-
sock << "a=1&a=2&b=x"
|
95
|
-
sock.close_write
|
96
|
-
assert_match(%r{\AHTTP/\d.\d 400 Bad Request}, sock.read, log.call)
|
97
|
-
ensure
|
98
|
-
sock.close
|
99
|
-
end
|
100
|
-
}
|
101
|
-
end
|
102
|
-
|
103
|
-
CtrlSeq = [0x7f, *(1..31)].pack("C*").gsub(/\s+/, '')
|
104
|
-
CtrlPat = /#{Regexp.quote(CtrlSeq)}/o
|
105
|
-
DumpPat = /#{Regexp.quote(CtrlSeq.dump[1...-1])}/o
|
106
|
-
|
107
|
-
def test_bad_uri
|
108
|
-
start_cgi_server{|server, addr, port, log|
|
109
|
-
res = TCPSocket.open(addr, port) {|sock|
|
110
|
-
sock << "GET /#{CtrlSeq}#{CRLF}#{CRLF}"
|
111
|
-
sock.close_write
|
112
|
-
sock.read
|
113
|
-
}
|
114
|
-
assert_match(%r{\AHTTP/\d.\d 400 Bad Request}, res)
|
115
|
-
s = log.call.each_line.grep(/ERROR bad URI/)[0]
|
116
|
-
assert_match(DumpPat, s)
|
117
|
-
assert_not_match(CtrlPat, s)
|
118
|
-
}
|
119
|
-
end
|
120
|
-
|
121
|
-
def test_bad_header
|
122
|
-
start_cgi_server{|server, addr, port, log|
|
123
|
-
res = TCPSocket.open(addr, port) {|sock|
|
124
|
-
sock << "GET / HTTP/1.0#{CRLF}#{CtrlSeq}#{CRLF}#{CRLF}"
|
125
|
-
sock.close_write
|
126
|
-
sock.read
|
127
|
-
}
|
128
|
-
assert_match(%r{\AHTTP/\d.\d 400 Bad Request}, res)
|
129
|
-
s = log.call.each_line.grep(/ERROR bad header/)[0]
|
130
|
-
assert_match(DumpPat, s)
|
131
|
-
assert_not_match(CtrlPat, s)
|
132
|
-
}
|
133
|
-
end
|
134
|
-
end
|
data/test/webrick/test_cookie.rb
DELETED
@@ -1,131 +0,0 @@
|
|
1
|
-
require "test/unit"
|
2
|
-
require "webrick/cookie"
|
3
|
-
|
4
|
-
class TestWEBrickCookie < Test::Unit::TestCase
|
5
|
-
def test_new
|
6
|
-
cookie = WEBrick::Cookie.new("foo","bar")
|
7
|
-
assert_equal("foo", cookie.name)
|
8
|
-
assert_equal("bar", cookie.value)
|
9
|
-
assert_equal("foo=bar", cookie.to_s)
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_time
|
13
|
-
cookie = WEBrick::Cookie.new("foo","bar")
|
14
|
-
t = 1000000000
|
15
|
-
cookie.max_age = t
|
16
|
-
assert_match(t.to_s, cookie.to_s)
|
17
|
-
|
18
|
-
cookie = WEBrick::Cookie.new("foo","bar")
|
19
|
-
t = Time.at(1000000000)
|
20
|
-
cookie.expires = t
|
21
|
-
assert_equal(Time, cookie.expires.class)
|
22
|
-
assert_equal(t, cookie.expires)
|
23
|
-
ts = t.httpdate
|
24
|
-
cookie.expires = ts
|
25
|
-
assert_equal(Time, cookie.expires.class)
|
26
|
-
assert_equal(t, cookie.expires)
|
27
|
-
assert_match(ts, cookie.to_s)
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_parse
|
31
|
-
data = ""
|
32
|
-
data << '$Version="1"; '
|
33
|
-
data << 'Customer="WILE_E_COYOTE"; $Path="/acme"; '
|
34
|
-
data << 'Part_Number="Rocket_Launcher_0001"; $Path="/acme"; '
|
35
|
-
data << 'Shipping="FedEx"; $Path="/acme"'
|
36
|
-
cookies = WEBrick::Cookie.parse(data)
|
37
|
-
assert_equal(3, cookies.size)
|
38
|
-
assert_equal(1, cookies[0].version)
|
39
|
-
assert_equal("Customer", cookies[0].name)
|
40
|
-
assert_equal("WILE_E_COYOTE", cookies[0].value)
|
41
|
-
assert_equal("/acme", cookies[0].path)
|
42
|
-
assert_equal(1, cookies[1].version)
|
43
|
-
assert_equal("Part_Number", cookies[1].name)
|
44
|
-
assert_equal("Rocket_Launcher_0001", cookies[1].value)
|
45
|
-
assert_equal(1, cookies[2].version)
|
46
|
-
assert_equal("Shipping", cookies[2].name)
|
47
|
-
assert_equal("FedEx", cookies[2].value)
|
48
|
-
|
49
|
-
data = "hoge=moge; __div__session=9865ecfd514be7f7"
|
50
|
-
cookies = WEBrick::Cookie.parse(data)
|
51
|
-
assert_equal(0, cookies[0].version)
|
52
|
-
assert_equal("hoge", cookies[0].name)
|
53
|
-
assert_equal("moge", cookies[0].value)
|
54
|
-
assert_equal("__div__session", cookies[1].name)
|
55
|
-
assert_equal("9865ecfd514be7f7", cookies[1].value)
|
56
|
-
end
|
57
|
-
|
58
|
-
def test_parse_no_whitespace
|
59
|
-
data = [
|
60
|
-
'$Version="1"; ',
|
61
|
-
'Customer="WILE_E_COYOTE";$Path="/acme";', # no SP between cookie-string
|
62
|
-
'Part_Number="Rocket_Launcher_0001";$Path="/acme";', # no SP between cookie-string
|
63
|
-
'Shipping="FedEx";$Path="/acme"'
|
64
|
-
].join
|
65
|
-
cookies = WEBrick::Cookie.parse(data)
|
66
|
-
assert_equal(1, cookies.size)
|
67
|
-
end
|
68
|
-
|
69
|
-
def test_parse_too_much_whitespaces
|
70
|
-
# According to RFC6265,
|
71
|
-
# cookie-string = cookie-pair *( ";" SP cookie-pair )
|
72
|
-
# So single 0x20 is needed after ';'. We allow multiple spaces here for
|
73
|
-
# compatibility with older WEBrick versions.
|
74
|
-
data = [
|
75
|
-
'$Version="1"; ',
|
76
|
-
'Customer="WILE_E_COYOTE";$Path="/acme"; ', # no SP between cookie-string
|
77
|
-
'Part_Number="Rocket_Launcher_0001";$Path="/acme"; ', # no SP between cookie-string
|
78
|
-
'Shipping="FedEx";$Path="/acme"'
|
79
|
-
].join
|
80
|
-
cookies = WEBrick::Cookie.parse(data)
|
81
|
-
assert_equal(3, cookies.size)
|
82
|
-
end
|
83
|
-
|
84
|
-
def test_parse_set_cookie
|
85
|
-
data = %(Customer="WILE_E_COYOTE"; Version="1"; Path="/acme")
|
86
|
-
cookie = WEBrick::Cookie.parse_set_cookie(data)
|
87
|
-
assert_equal("Customer", cookie.name)
|
88
|
-
assert_equal("WILE_E_COYOTE", cookie.value)
|
89
|
-
assert_equal(1, cookie.version)
|
90
|
-
assert_equal("/acme", cookie.path)
|
91
|
-
|
92
|
-
data = %(Shipping="FedEx"; Version="1"; Path="/acme"; Secure)
|
93
|
-
cookie = WEBrick::Cookie.parse_set_cookie(data)
|
94
|
-
assert_equal("Shipping", cookie.name)
|
95
|
-
assert_equal("FedEx", cookie.value)
|
96
|
-
assert_equal(1, cookie.version)
|
97
|
-
assert_equal("/acme", cookie.path)
|
98
|
-
assert_equal(true, cookie.secure)
|
99
|
-
end
|
100
|
-
|
101
|
-
def test_parse_set_cookies
|
102
|
-
data = %(Shipping="FedEx"; Version="1"; Path="/acme"; Secure)
|
103
|
-
data << %(, CUSTOMER=WILE_E_COYOTE; path=/; expires=Wednesday, 09-Nov-99 23:12:40 GMT; path=/; Secure)
|
104
|
-
data << %(, name="Aaron"; Version="1"; path="/acme")
|
105
|
-
cookies = WEBrick::Cookie.parse_set_cookies(data)
|
106
|
-
assert_equal(3, cookies.length)
|
107
|
-
|
108
|
-
fed_ex = cookies.find { |c| c.name == 'Shipping' }
|
109
|
-
assert_not_nil(fed_ex)
|
110
|
-
assert_equal("Shipping", fed_ex.name)
|
111
|
-
assert_equal("FedEx", fed_ex.value)
|
112
|
-
assert_equal(1, fed_ex.version)
|
113
|
-
assert_equal("/acme", fed_ex.path)
|
114
|
-
assert_equal(true, fed_ex.secure)
|
115
|
-
|
116
|
-
name = cookies.find { |c| c.name == 'name' }
|
117
|
-
assert_not_nil(name)
|
118
|
-
assert_equal("name", name.name)
|
119
|
-
assert_equal("Aaron", name.value)
|
120
|
-
assert_equal(1, name.version)
|
121
|
-
assert_equal("/acme", name.path)
|
122
|
-
|
123
|
-
customer = cookies.find { |c| c.name == 'CUSTOMER' }
|
124
|
-
assert_not_nil(customer)
|
125
|
-
assert_equal("CUSTOMER", customer.name)
|
126
|
-
assert_equal("WILE_E_COYOTE", customer.value)
|
127
|
-
assert_equal(0, customer.version)
|
128
|
-
assert_equal("/", customer.path)
|
129
|
-
assert_equal(Time.utc(1999, 11, 9, 23, 12, 40), customer.expires)
|
130
|
-
end
|
131
|
-
end
|