rack 2.0.9.3 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of rack might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +808 -0
- data/CONTRIBUTING.md +142 -0
- data/{COPYING → MIT-LICENSE} +4 -2
- data/README.md +293 -0
- data/SPEC.rdoc +340 -0
- data/lib/rack/auth/abstract/handler.rb +6 -2
- data/lib/rack/auth/abstract/request.rb +4 -2
- data/lib/rack/auth/basic.rb +7 -4
- data/lib/rack/auth/digest/md5.rb +1 -129
- data/lib/rack/auth/digest/nonce.rb +1 -51
- data/lib/rack/auth/digest/params.rb +1 -52
- data/lib/rack/auth/digest/request.rb +1 -41
- data/lib/rack/auth/digest.rb +256 -0
- data/lib/rack/body_proxy.rb +18 -15
- data/lib/rack/builder.rb +151 -40
- data/lib/rack/cascade.rb +30 -12
- data/lib/rack/chunked.rb +74 -23
- data/lib/rack/common_logger.rb +49 -36
- data/lib/rack/conditional_get.rb +33 -26
- data/lib/rack/config.rb +2 -0
- data/lib/rack/constants.rb +63 -0
- data/lib/rack/content_length.rb +13 -16
- data/lib/rack/content_type.rb +12 -8
- data/lib/rack/deflater.rb +84 -45
- data/lib/rack/directory.rb +90 -64
- data/lib/rack/etag.rb +17 -23
- data/lib/rack/events.rb +23 -20
- data/lib/rack/file.rb +5 -172
- data/lib/rack/files.rb +216 -0
- data/lib/rack/head.rb +10 -9
- data/lib/rack/headers.rb +154 -0
- data/lib/rack/lint.rb +786 -645
- data/lib/rack/lock.rb +4 -6
- data/lib/rack/logger.rb +4 -0
- data/lib/rack/media_type.rb +10 -5
- data/lib/rack/method_override.rb +8 -2
- data/lib/rack/mime.rb +17 -1
- data/lib/rack/mock.rb +2 -195
- data/lib/rack/mock_request.rb +166 -0
- data/lib/rack/mock_response.rb +126 -0
- data/lib/rack/multipart/generator.rb +21 -15
- data/lib/rack/multipart/parser.rb +161 -118
- data/lib/rack/multipart/uploaded_file.rb +19 -7
- data/lib/rack/multipart.rb +23 -41
- data/lib/rack/null_logger.rb +11 -0
- data/lib/rack/query_parser.rb +126 -65
- data/lib/rack/recursive.rb +9 -5
- data/lib/rack/reloader.rb +6 -4
- data/lib/rack/request.rb +331 -74
- data/lib/rack/response.rb +223 -70
- data/lib/rack/rewindable_input.rb +28 -8
- data/lib/rack/runtime.rb +11 -8
- data/lib/rack/sendfile.rb +42 -33
- data/lib/rack/show_exceptions.rb +35 -18
- data/lib/rack/show_status.rb +25 -15
- data/lib/rack/static.rb +30 -18
- data/lib/rack/tempfile_reaper.rb +16 -5
- data/lib/rack/urlmap.rb +14 -6
- data/lib/rack/utils.rb +268 -260
- data/lib/rack/version.rb +34 -0
- data/lib/rack.rb +15 -92
- metadata +44 -207
- data/HISTORY.md +0 -520
- data/README.rdoc +0 -316
- data/Rakefile +0 -116
- data/SPEC +0 -263
- data/bin/rackup +0 -4
- data/contrib/rack.png +0 -0
- data/contrib/rack.svg +0 -150
- data/contrib/rack_logo.svg +0 -164
- data/contrib/rdoc.css +0 -412
- data/example/lobster.ru +0 -4
- data/example/protectedlobster.rb +0 -14
- data/example/protectedlobster.ru +0 -8
- data/lib/rack/handler/cgi.rb +0 -60
- data/lib/rack/handler/fastcgi.rb +0 -100
- data/lib/rack/handler/lsws.rb +0 -61
- data/lib/rack/handler/scgi.rb +0 -70
- data/lib/rack/handler/thin.rb +0 -36
- data/lib/rack/handler/webrick.rb +0 -120
- data/lib/rack/handler.rb +0 -99
- data/lib/rack/lobster.rb +0 -70
- data/lib/rack/server.rb +0 -395
- data/lib/rack/session/abstract/id.rb +0 -510
- data/lib/rack/session/cookie.rb +0 -204
- data/lib/rack/session/memcache.rb +0 -99
- data/lib/rack/session/pool.rb +0 -83
- data/rack.gemspec +0 -34
- data/test/builder/an_underscore_app.rb +0 -5
- data/test/builder/anything.rb +0 -5
- data/test/builder/comment.ru +0 -4
- data/test/builder/end.ru +0 -5
- data/test/builder/line.ru +0 -1
- data/test/builder/options.ru +0 -2
- data/test/cgi/assets/folder/test.js +0 -1
- data/test/cgi/assets/fonts/font.eot +0 -1
- data/test/cgi/assets/images/image.png +0 -1
- data/test/cgi/assets/index.html +0 -1
- data/test/cgi/assets/javascripts/app.js +0 -1
- data/test/cgi/assets/stylesheets/app.css +0 -1
- data/test/cgi/lighttpd.conf +0 -26
- data/test/cgi/rackup_stub.rb +0 -6
- data/test/cgi/sample_rackup.ru +0 -5
- data/test/cgi/test +0 -9
- data/test/cgi/test+directory/test+file +0 -1
- data/test/cgi/test.fcgi +0 -9
- data/test/cgi/test.gz +0 -0
- data/test/cgi/test.ru +0 -5
- data/test/gemloader.rb +0 -10
- data/test/helper.rb +0 -34
- data/test/multipart/bad_robots +0 -259
- data/test/multipart/binary +0 -0
- data/test/multipart/content_type_and_no_filename +0 -6
- data/test/multipart/empty +0 -10
- data/test/multipart/fail_16384_nofile +0 -814
- data/test/multipart/file1.txt +0 -1
- data/test/multipart/filename_and_modification_param +0 -7
- data/test/multipart/filename_and_no_name +0 -6
- data/test/multipart/filename_with_encoded_words +0 -7
- data/test/multipart/filename_with_escaped_quotes +0 -6
- data/test/multipart/filename_with_escaped_quotes_and_modification_param +0 -7
- data/test/multipart/filename_with_null_byte +0 -7
- data/test/multipart/filename_with_percent_escaped_quotes +0 -6
- data/test/multipart/filename_with_single_quote +0 -7
- data/test/multipart/filename_with_unescaped_percentages +0 -6
- data/test/multipart/filename_with_unescaped_percentages2 +0 -6
- data/test/multipart/filename_with_unescaped_percentages3 +0 -6
- data/test/multipart/filename_with_unescaped_quotes +0 -6
- data/test/multipart/ie +0 -6
- data/test/multipart/invalid_character +0 -6
- data/test/multipart/mixed_files +0 -21
- data/test/multipart/nested +0 -10
- data/test/multipart/none +0 -9
- data/test/multipart/quoted +0 -15
- data/test/multipart/rack-logo.png +0 -0
- data/test/multipart/semicolon +0 -6
- data/test/multipart/text +0 -15
- data/test/multipart/three_files_three_fields +0 -31
- data/test/multipart/unity3d_wwwform +0 -11
- data/test/multipart/webkit +0 -32
- data/test/rackup/config.ru +0 -31
- data/test/registering_handler/rack/handler/registering_myself.rb +0 -8
- data/test/spec_auth_basic.rb +0 -89
- data/test/spec_auth_digest.rb +0 -260
- data/test/spec_body_proxy.rb +0 -85
- data/test/spec_builder.rb +0 -233
- data/test/spec_cascade.rb +0 -63
- data/test/spec_cgi.rb +0 -84
- data/test/spec_chunked.rb +0 -103
- data/test/spec_common_logger.rb +0 -107
- data/test/spec_conditional_get.rb +0 -103
- data/test/spec_config.rb +0 -23
- data/test/spec_content_length.rb +0 -86
- data/test/spec_content_type.rb +0 -46
- data/test/spec_deflater.rb +0 -375
- data/test/spec_directory.rb +0 -148
- data/test/spec_etag.rb +0 -108
- data/test/spec_events.rb +0 -133
- data/test/spec_fastcgi.rb +0 -85
- data/test/spec_file.rb +0 -264
- data/test/spec_handler.rb +0 -57
- data/test/spec_head.rb +0 -46
- data/test/spec_lint.rb +0 -520
- data/test/spec_lobster.rb +0 -59
- data/test/spec_lock.rb +0 -204
- data/test/spec_logger.rb +0 -24
- data/test/spec_media_type.rb +0 -42
- data/test/spec_method_override.rb +0 -110
- data/test/spec_mime.rb +0 -51
- data/test/spec_mock.rb +0 -359
- data/test/spec_multipart.rb +0 -721
- data/test/spec_null_logger.rb +0 -21
- data/test/spec_recursive.rb +0 -75
- data/test/spec_request.rb +0 -1423
- data/test/spec_response.rb +0 -528
- data/test/spec_rewindable_input.rb +0 -128
- data/test/spec_runtime.rb +0 -50
- data/test/spec_sendfile.rb +0 -125
- data/test/spec_server.rb +0 -193
- data/test/spec_session_abstract_id.rb +0 -31
- data/test/spec_session_abstract_session_hash.rb +0 -45
- data/test/spec_session_cookie.rb +0 -442
- data/test/spec_session_memcache.rb +0 -357
- data/test/spec_session_persisted_secure_secure_session_hash.rb +0 -73
- data/test/spec_session_pool.rb +0 -247
- data/test/spec_show_exceptions.rb +0 -93
- data/test/spec_show_status.rb +0 -104
- data/test/spec_static.rb +0 -184
- data/test/spec_tempfile_reaper.rb +0 -64
- data/test/spec_thin.rb +0 -96
- data/test/spec_urlmap.rb +0 -237
- data/test/spec_utils.rb +0 -742
- data/test/spec_version.rb +0 -11
- data/test/spec_webrick.rb +0 -206
- data/test/static/another/index.html +0 -1
- data/test/static/foo.html +0 -1
- data/test/static/index.html +0 -1
- data/test/testrequest.rb +0 -78
- data/test/unregistered_handler/rack/handler/unregistered.rb +0 -7
- data/test/unregistered_handler/rack/handler/unregistered_long_one.rb +0 -7
data/test/spec_sendfile.rb
DELETED
@@ -1,125 +0,0 @@
|
|
1
|
-
require 'minitest/autorun'
|
2
|
-
require 'fileutils'
|
3
|
-
require 'rack/lint'
|
4
|
-
require 'rack/sendfile'
|
5
|
-
require 'rack/mock'
|
6
|
-
require 'tmpdir'
|
7
|
-
|
8
|
-
describe Rack::Sendfile do
|
9
|
-
def sendfile_body
|
10
|
-
FileUtils.touch File.join(Dir.tmpdir, "rack_sendfile")
|
11
|
-
res = ['Hello World']
|
12
|
-
def res.to_path ; File.join(Dir.tmpdir, "rack_sendfile") ; end
|
13
|
-
res
|
14
|
-
end
|
15
|
-
|
16
|
-
def simple_app(body=sendfile_body)
|
17
|
-
lambda { |env| [200, {'Content-Type' => 'text/plain'}, body] }
|
18
|
-
end
|
19
|
-
|
20
|
-
def sendfile_app(body, mappings = [])
|
21
|
-
Rack::Lint.new Rack::Sendfile.new(simple_app(body), nil, mappings)
|
22
|
-
end
|
23
|
-
|
24
|
-
def request(headers={}, body=sendfile_body, mappings=[])
|
25
|
-
yield Rack::MockRequest.new(sendfile_app(body, mappings)).get('/', headers)
|
26
|
-
end
|
27
|
-
|
28
|
-
def open_file(path)
|
29
|
-
Class.new(File) do
|
30
|
-
unless method_defined?(:to_path)
|
31
|
-
alias :to_path :path
|
32
|
-
end
|
33
|
-
end.open(path, 'wb+')
|
34
|
-
end
|
35
|
-
|
36
|
-
it "does nothing when no X-Sendfile-Type header present" do
|
37
|
-
request do |response|
|
38
|
-
response.must_be :ok?
|
39
|
-
response.body.must_equal 'Hello World'
|
40
|
-
response.headers.wont_include 'X-Sendfile'
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
it "sets X-Sendfile response header and discards body" do
|
45
|
-
request 'HTTP_X_SENDFILE_TYPE' => 'X-Sendfile' do |response|
|
46
|
-
response.must_be :ok?
|
47
|
-
response.body.must_be :empty?
|
48
|
-
response.headers['Content-Length'].must_equal '0'
|
49
|
-
response.headers['X-Sendfile'].must_equal File.join(Dir.tmpdir, "rack_sendfile")
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
it "sets X-Lighttpd-Send-File response header and discards body" do
|
54
|
-
request 'HTTP_X_SENDFILE_TYPE' => 'X-Lighttpd-Send-File' do |response|
|
55
|
-
response.must_be :ok?
|
56
|
-
response.body.must_be :empty?
|
57
|
-
response.headers['Content-Length'].must_equal '0'
|
58
|
-
response.headers['X-Lighttpd-Send-File'].must_equal File.join(Dir.tmpdir, "rack_sendfile")
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
it "sets X-Accel-Redirect response header and discards body" do
|
63
|
-
headers = {
|
64
|
-
'HTTP_X_SENDFILE_TYPE' => 'X-Accel-Redirect',
|
65
|
-
'HTTP_X_ACCEL_MAPPING' => "#{Dir.tmpdir}/=/foo/bar/"
|
66
|
-
}
|
67
|
-
request headers do |response|
|
68
|
-
response.must_be :ok?
|
69
|
-
response.body.must_be :empty?
|
70
|
-
response.headers['Content-Length'].must_equal '0'
|
71
|
-
response.headers['X-Accel-Redirect'].must_equal '/foo/bar/rack_sendfile'
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
it 'writes to rack.error when no X-Accel-Mapping is specified' do
|
76
|
-
request 'HTTP_X_SENDFILE_TYPE' => 'X-Accel-Redirect' do |response|
|
77
|
-
response.must_be :ok?
|
78
|
-
response.body.must_equal 'Hello World'
|
79
|
-
response.headers.wont_include 'X-Accel-Redirect'
|
80
|
-
response.errors.must_include 'X-Accel-Mapping'
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
it 'does nothing when body does not respond to #to_path' do
|
85
|
-
request({'HTTP_X_SENDFILE_TYPE' => 'X-Sendfile'}, ['Not a file...']) do |response|
|
86
|
-
response.body.must_equal 'Not a file...'
|
87
|
-
response.headers.wont_include 'X-Sendfile'
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
it "sets X-Accel-Redirect response header and discards body when initialized with multiple mappings" do
|
92
|
-
begin
|
93
|
-
dir1 = Dir.mktmpdir
|
94
|
-
dir2 = Dir.mktmpdir
|
95
|
-
|
96
|
-
first_body = open_file(File.join(dir1, 'rack_sendfile'))
|
97
|
-
first_body.puts 'hello world'
|
98
|
-
|
99
|
-
second_body = open_file(File.join(dir2, 'rack_sendfile'))
|
100
|
-
second_body.puts 'goodbye world'
|
101
|
-
|
102
|
-
mappings = [
|
103
|
-
["#{dir1}/", '/foo/bar/'],
|
104
|
-
["#{dir2}/", '/wibble/']
|
105
|
-
]
|
106
|
-
|
107
|
-
request({'HTTP_X_SENDFILE_TYPE' => 'X-Accel-Redirect'}, first_body, mappings) do |response|
|
108
|
-
response.must_be :ok?
|
109
|
-
response.body.must_be :empty?
|
110
|
-
response.headers['Content-Length'].must_equal '0'
|
111
|
-
response.headers['X-Accel-Redirect'].must_equal '/foo/bar/rack_sendfile'
|
112
|
-
end
|
113
|
-
|
114
|
-
request({'HTTP_X_SENDFILE_TYPE' => 'X-Accel-Redirect'}, second_body, mappings) do |response|
|
115
|
-
response.must_be :ok?
|
116
|
-
response.body.must_be :empty?
|
117
|
-
response.headers['Content-Length'].must_equal '0'
|
118
|
-
response.headers['X-Accel-Redirect'].must_equal '/wibble/rack_sendfile'
|
119
|
-
end
|
120
|
-
ensure
|
121
|
-
FileUtils.remove_entry_secure dir1
|
122
|
-
FileUtils.remove_entry_secure dir2
|
123
|
-
end
|
124
|
-
end
|
125
|
-
end
|
data/test/spec_server.rb
DELETED
@@ -1,193 +0,0 @@
|
|
1
|
-
require 'minitest/autorun'
|
2
|
-
require 'rack'
|
3
|
-
require 'rack/server'
|
4
|
-
require 'tempfile'
|
5
|
-
require 'socket'
|
6
|
-
require 'open-uri'
|
7
|
-
|
8
|
-
module Minitest::Spec::DSL
|
9
|
-
alias :should :it
|
10
|
-
end
|
11
|
-
|
12
|
-
describe Rack::Server do
|
13
|
-
SPEC_ARGV = []
|
14
|
-
|
15
|
-
before { SPEC_ARGV[0..-1] = [] }
|
16
|
-
|
17
|
-
def app
|
18
|
-
lambda { |env| [200, {'Content-Type' => 'text/plain'}, ['success']] }
|
19
|
-
end
|
20
|
-
|
21
|
-
def with_stderr
|
22
|
-
old, $stderr = $stderr, StringIO.new
|
23
|
-
yield $stderr
|
24
|
-
ensure
|
25
|
-
$stderr = old
|
26
|
-
end
|
27
|
-
|
28
|
-
it "overrides :config if :app is passed in" do
|
29
|
-
server = Rack::Server.new(:app => "FOO")
|
30
|
-
server.app.must_equal "FOO"
|
31
|
-
end
|
32
|
-
|
33
|
-
it "prefer to use :builder when it is passed in" do
|
34
|
-
server = Rack::Server.new(:builder => "run lambda { |env| [200, {'Content-Type' => 'text/plain'}, ['success']] }")
|
35
|
-
server.app.class.must_equal Proc
|
36
|
-
Rack::MockRequest.new(server.app).get("/").body.to_s.must_equal 'success'
|
37
|
-
end
|
38
|
-
|
39
|
-
it "allow subclasses to override middleware" do
|
40
|
-
server = Class.new(Rack::Server).class_eval { def middleware; Hash.new [] end; self }
|
41
|
-
server.middleware['deployment'].wont_equal []
|
42
|
-
server.new(:app => 'foo').middleware['deployment'].must_equal []
|
43
|
-
end
|
44
|
-
|
45
|
-
it "allow subclasses to override default middleware" do
|
46
|
-
server = Class.new(Rack::Server).instance_eval { def default_middleware_by_environment; Hash.new [] end; self }
|
47
|
-
server.middleware['deployment'].must_equal []
|
48
|
-
server.new(:app => 'foo').middleware['deployment'].must_equal []
|
49
|
-
end
|
50
|
-
|
51
|
-
it "only provide default middleware for development and deployment environments" do
|
52
|
-
Rack::Server.default_middleware_by_environment.keys.sort.must_equal %w(deployment development)
|
53
|
-
end
|
54
|
-
|
55
|
-
it "always return an empty array for unknown environments" do
|
56
|
-
server = Rack::Server.new(:app => 'foo')
|
57
|
-
server.middleware['production'].must_equal []
|
58
|
-
end
|
59
|
-
|
60
|
-
it "not include Rack::Lint in deployment environment" do
|
61
|
-
server = Rack::Server.new(:app => 'foo')
|
62
|
-
server.middleware['deployment'].flatten.wont_include Rack::Lint
|
63
|
-
end
|
64
|
-
|
65
|
-
it "not include Rack::ShowExceptions in deployment environment" do
|
66
|
-
server = Rack::Server.new(:app => 'foo')
|
67
|
-
server.middleware['deployment'].flatten.wont_include Rack::ShowExceptions
|
68
|
-
end
|
69
|
-
|
70
|
-
it "include Rack::TempfileReaper in deployment environment" do
|
71
|
-
server = Rack::Server.new(:app => 'foo')
|
72
|
-
server.middleware['deployment'].flatten.must_include Rack::TempfileReaper
|
73
|
-
end
|
74
|
-
|
75
|
-
it "support CGI" do
|
76
|
-
begin
|
77
|
-
o, ENV["REQUEST_METHOD"] = ENV["REQUEST_METHOD"], 'foo'
|
78
|
-
server = Rack::Server.new(:app => 'foo')
|
79
|
-
server.server.name =~ /CGI/
|
80
|
-
Rack::Server.logging_middleware.call(server).must_be_nil
|
81
|
-
ensure
|
82
|
-
ENV['REQUEST_METHOD'] = o
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
it "be quiet if said so" do
|
87
|
-
server = Rack::Server.new(:app => "FOO", :quiet => true)
|
88
|
-
Rack::Server.logging_middleware.call(server).must_be_nil
|
89
|
-
end
|
90
|
-
|
91
|
-
it "use a full path to the pidfile" do
|
92
|
-
# avoids issues with daemonize chdir
|
93
|
-
opts = Rack::Server.new.send(:parse_options, %w[--pid testing.pid])
|
94
|
-
opts[:pid].must_equal ::File.expand_path('testing.pid')
|
95
|
-
end
|
96
|
-
|
97
|
-
it "get options from ARGV" do
|
98
|
-
SPEC_ARGV[0..-1] = ['--debug', '-sthin', '--env', 'production']
|
99
|
-
server = Rack::Server.new
|
100
|
-
server.options[:debug].must_equal true
|
101
|
-
server.options[:server].must_equal 'thin'
|
102
|
-
server.options[:environment].must_equal 'production'
|
103
|
-
end
|
104
|
-
|
105
|
-
it "only override non-passed options from parsed .ru file" do
|
106
|
-
builder_file = File.join(File.dirname(__FILE__), 'builder', 'options.ru')
|
107
|
-
SPEC_ARGV[0..-1] = ['--debug', '-sthin', '--env', 'production', builder_file]
|
108
|
-
server = Rack::Server.new
|
109
|
-
server.app # force .ru file to be parsed
|
110
|
-
|
111
|
-
server.options[:debug].must_equal true
|
112
|
-
server.options[:server].must_equal 'thin'
|
113
|
-
server.options[:environment].must_equal 'production'
|
114
|
-
server.options[:Port].must_equal '2929'
|
115
|
-
end
|
116
|
-
|
117
|
-
it "run a server" do
|
118
|
-
pidfile = Tempfile.open('pidfile') { |f| break f }
|
119
|
-
FileUtils.rm pidfile.path
|
120
|
-
server = Rack::Server.new(
|
121
|
-
:app => app,
|
122
|
-
:environment => 'none',
|
123
|
-
:pid => pidfile.path,
|
124
|
-
:Port => TCPServer.open('127.0.0.1', 0){|s| s.addr[1] },
|
125
|
-
:Host => '127.0.0.1',
|
126
|
-
:Logger => WEBrick::Log.new(nil, WEBrick::BasicLog::WARN),
|
127
|
-
:AccessLog => [],
|
128
|
-
:daemonize => false,
|
129
|
-
:server => 'webrick'
|
130
|
-
)
|
131
|
-
t = Thread.new { server.start { |s| Thread.current[:server] = s } }
|
132
|
-
t.join(0.01) until t[:server] && t[:server].status != :Stop
|
133
|
-
body = open("http://127.0.0.1:#{server.options[:Port]}/") { |f| f.read }
|
134
|
-
body.must_equal 'success'
|
135
|
-
|
136
|
-
Process.kill(:INT, $$)
|
137
|
-
t.join
|
138
|
-
open(pidfile.path) { |f| f.read.must_equal $$.to_s }
|
139
|
-
end
|
140
|
-
|
141
|
-
it "check pid file presence and running process" do
|
142
|
-
pidfile = Tempfile.open('pidfile') { |f| f.write($$); break f }.path
|
143
|
-
server = Rack::Server.new(:pid => pidfile)
|
144
|
-
server.send(:pidfile_process_status).must_equal :running
|
145
|
-
end
|
146
|
-
|
147
|
-
it "check pid file presence and dead process" do
|
148
|
-
dead_pid = `echo $$`.to_i
|
149
|
-
pidfile = Tempfile.open('pidfile') { |f| f.write(dead_pid); break f }.path
|
150
|
-
server = Rack::Server.new(:pid => pidfile)
|
151
|
-
server.send(:pidfile_process_status).must_equal :dead
|
152
|
-
end
|
153
|
-
|
154
|
-
it "check pid file presence and exited process" do
|
155
|
-
pidfile = Tempfile.open('pidfile') { |f| break f }.path
|
156
|
-
::File.delete(pidfile)
|
157
|
-
server = Rack::Server.new(:pid => pidfile)
|
158
|
-
server.send(:pidfile_process_status).must_equal :exited
|
159
|
-
end
|
160
|
-
|
161
|
-
it "check pid file presence and not owned process" do
|
162
|
-
pidfile = Tempfile.open('pidfile') { |f| f.write(1); break f }.path
|
163
|
-
server = Rack::Server.new(:pid => pidfile)
|
164
|
-
server.send(:pidfile_process_status).must_equal :not_owned
|
165
|
-
end
|
166
|
-
|
167
|
-
it "not write pid file when it is created after check" do
|
168
|
-
pidfile = Tempfile.open('pidfile') { |f| break f }.path
|
169
|
-
::File.delete(pidfile)
|
170
|
-
server = Rack::Server.new(:pid => pidfile)
|
171
|
-
::File.open(pidfile, 'w') { |f| f.write(1) }
|
172
|
-
with_stderr do |err|
|
173
|
-
lambda { server.send(:write_pid) }.must_raise SystemExit
|
174
|
-
err.rewind
|
175
|
-
output = err.read
|
176
|
-
output.must_match(/already running/)
|
177
|
-
output.must_include pidfile
|
178
|
-
end
|
179
|
-
end
|
180
|
-
|
181
|
-
it "inform the user about existing pidfiles with running processes" do
|
182
|
-
pidfile = Tempfile.open('pidfile') { |f| f.write(1); break f }.path
|
183
|
-
server = Rack::Server.new(:pid => pidfile)
|
184
|
-
with_stderr do |err|
|
185
|
-
lambda { server.start }.must_raise SystemExit
|
186
|
-
err.rewind
|
187
|
-
output = err.read
|
188
|
-
output.must_match(/already running/)
|
189
|
-
output.must_include pidfile
|
190
|
-
end
|
191
|
-
end
|
192
|
-
|
193
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
require 'minitest/autorun'
|
2
|
-
### WARNING: there be hax in this file.
|
3
|
-
|
4
|
-
require 'rack/session/abstract/id'
|
5
|
-
|
6
|
-
describe Rack::Session::Abstract::ID do
|
7
|
-
attr_reader :id
|
8
|
-
|
9
|
-
def setup
|
10
|
-
super
|
11
|
-
@id = Rack::Session::Abstract::ID
|
12
|
-
end
|
13
|
-
|
14
|
-
it "use securerandom" do
|
15
|
-
assert_equal ::SecureRandom, id::DEFAULT_OPTIONS[:secure_random]
|
16
|
-
|
17
|
-
id = @id.new nil
|
18
|
-
assert_equal ::SecureRandom, id.sid_secure
|
19
|
-
end
|
20
|
-
|
21
|
-
it "allow to use another securerandom provider" do
|
22
|
-
secure_random = Class.new do
|
23
|
-
def hex(*args)
|
24
|
-
'fake_hex'
|
25
|
-
end
|
26
|
-
end
|
27
|
-
id = Rack::Session::Abstract::ID.new nil, :secure_random => secure_random.new
|
28
|
-
id.send(:generate_sid).must_equal 'fake_hex'
|
29
|
-
end
|
30
|
-
|
31
|
-
end
|
@@ -1,45 +0,0 @@
|
|
1
|
-
require 'minitest/autorun'
|
2
|
-
require 'rack/session/abstract/id'
|
3
|
-
|
4
|
-
describe Rack::Session::Abstract::SessionHash do
|
5
|
-
attr_reader :hash
|
6
|
-
|
7
|
-
def setup
|
8
|
-
super
|
9
|
-
store = Class.new do
|
10
|
-
def load_session(req)
|
11
|
-
["id", {foo: :bar, baz: :qux}]
|
12
|
-
end
|
13
|
-
def session_exists?(req)
|
14
|
-
true
|
15
|
-
end
|
16
|
-
end
|
17
|
-
@hash = Rack::Session::Abstract::SessionHash.new(store.new, nil)
|
18
|
-
end
|
19
|
-
|
20
|
-
it "returns keys" do
|
21
|
-
assert_equal ["foo", "baz"], hash.keys
|
22
|
-
end
|
23
|
-
|
24
|
-
it "returns values" do
|
25
|
-
assert_equal [:bar, :qux], hash.values
|
26
|
-
end
|
27
|
-
|
28
|
-
describe "#fetch" do
|
29
|
-
it "returns value for a matching key" do
|
30
|
-
assert_equal :bar, hash.fetch(:foo)
|
31
|
-
end
|
32
|
-
|
33
|
-
it "works with a default value" do
|
34
|
-
assert_equal :default, hash.fetch(:unknown, :default)
|
35
|
-
end
|
36
|
-
|
37
|
-
it "works with a block" do
|
38
|
-
assert_equal :default, hash.fetch(:unkown) { :default }
|
39
|
-
end
|
40
|
-
|
41
|
-
it "it raises when fetching unknown keys without defaults" do
|
42
|
-
lambda { hash.fetch(:unknown) }.must_raise KeyError
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|