X7ROOT File Manager
Current Path:
/opt/alt/ruby23/lib64/ruby/gems/2.3.0/gems/rack-1.6.4/test
opt
/
alt
/
ruby23
/
lib64
/
ruby
/
gems
/
2.3.0
/
gems
/
rack-1.6.4
/
test
/
ðŸ“
..
ðŸ“
builder
ðŸ“
cgi
📄
gemloader.rb
(298 B)
ðŸ“
multipart
ðŸ“
rackup
ðŸ“
registering_handler
📄
spec_auth_basic.rb
(2.26 KB)
📄
spec_auth_digest.rb
(8.08 KB)
📄
spec_body_proxy.rb
(2.2 KB)
📄
spec_builder.rb
(6.2 KB)
📄
spec_cascade.rb
(2.11 KB)
📄
spec_cgi.rb
(2.92 KB)
📄
spec_chunked.rb
(3.87 KB)
📄
spec_commonlogger.rb
(2.37 KB)
📄
spec_conditionalget.rb
(3.28 KB)
📄
spec_config.rb
(544 B)
📄
spec_content_length.rb
(2.8 KB)
📄
spec_content_type.rb
(1.47 KB)
📄
spec_deflater.rb
(10.04 KB)
📄
spec_directory.rb
(2.19 KB)
📄
spec_etag.rb
(3.84 KB)
📄
spec_fastcgi.rb
(3.08 KB)
📄
spec_file.rb
(6.32 KB)
📄
spec_handler.rb
(1.87 KB)
📄
spec_head.rb
(1.36 KB)
📄
spec_lint.rb
(19.23 KB)
📄
spec_lobster.rb
(1.23 KB)
📄
spec_lock.rb
(4.33 KB)
📄
spec_logger.rb
(622 B)
📄
spec_methodoverride.rb
(2.38 KB)
📄
spec_mime.rb
(1.81 KB)
📄
spec_mock.rb
(9.34 KB)
📄
spec_mongrel.rb
(5.73 KB)
📄
spec_multipart.rb
(23.62 KB)
📄
spec_nulllogger.rb
(514 B)
📄
spec_recursive.rb
(1.83 KB)
📄
spec_request.rb
(42.52 KB)
📄
spec_response.rb
(10.08 KB)
📄
spec_rewindable_input.rb
(2.78 KB)
📄
spec_runtime.rb
(1.53 KB)
📄
spec_sendfile.rb
(4.12 KB)
📄
spec_server.rb
(5.57 KB)
📄
spec_session_abstract_id.rb
(1.29 KB)
📄
spec_session_cookie.rb
(12.94 KB)
📄
spec_session_memcache.rb
(11.12 KB)
📄
spec_session_pool.rb
(6.53 KB)
📄
spec_showexceptions.rb
(2.01 KB)
📄
spec_showstatus.rb
(2.74 KB)
📄
spec_static.rb
(4.6 KB)
📄
spec_tempfile_reaper.rb
(1.57 KB)
📄
spec_thin.rb
(2.55 KB)
📄
spec_urlmap.rb
(8.82 KB)
📄
spec_utils.rb
(24.89 KB)
📄
spec_version.rb
(504 B)
📄
spec_webrick.rb
(5.5 KB)
ðŸ“
static
📄
testrequest.rb
(1.96 KB)
ðŸ“
unregistered_handler
Editing: spec_session_pool.rb
require 'thread' require 'rack/lint' require 'rack/mock' require 'rack/session/pool' describe Rack::Session::Pool do session_key = Rack::Session::Pool::DEFAULT_OPTIONS[:key] session_match = /#{session_key}=[0-9a-fA-F]+;/ incrementor = lambda do |env| env["rack.session"]["counter"] ||= 0 env["rack.session"]["counter"] += 1 Rack::Response.new(env["rack.session"].inspect).to_a end session_id = Rack::Lint.new(lambda do |env| Rack::Response.new(env["rack.session"].inspect).to_a end) nothing = Rack::Lint.new(lambda do |env| Rack::Response.new("Nothing").to_a end) drop_session = Rack::Lint.new(lambda do |env| env['rack.session.options'][:drop] = true incrementor.call(env) end) renew_session = Rack::Lint.new(lambda do |env| env['rack.session.options'][:renew] = true incrementor.call(env) end) defer_session = Rack::Lint.new(lambda do |env| env['rack.session.options'][:defer] = true incrementor.call(env) end) incrementor = Rack::Lint.new(incrementor) it "creates a new cookie" do pool = Rack::Session::Pool.new(incrementor) res = Rack::MockRequest.new(pool).get("/") res["Set-Cookie"].should.match session_match res.body.should.equal '{"counter"=>1}' end it "determines session from a cookie" do pool = Rack::Session::Pool.new(incrementor) req = Rack::MockRequest.new(pool) cookie = req.get("/")["Set-Cookie"] req.get("/", "HTTP_COOKIE" => cookie). body.should.equal '{"counter"=>2}' req.get("/", "HTTP_COOKIE" => cookie). body.should.equal '{"counter"=>3}' end it "survives nonexistant cookies" do pool = Rack::Session::Pool.new(incrementor) res = Rack::MockRequest.new(pool). get("/", "HTTP_COOKIE" => "#{session_key}=blarghfasel") res.body.should.equal '{"counter"=>1}' end it "does not send the same session id if it did not change" do pool = Rack::Session::Pool.new(incrementor) req = Rack::MockRequest.new(pool) res0 = req.get("/") cookie = res0["Set-Cookie"][session_match] res0.body.should.equal '{"counter"=>1}' pool.pool.size.should.equal 1 res1 = req.get("/", "HTTP_COOKIE" => cookie) res1["Set-Cookie"].should.be.nil res1.body.should.equal '{"counter"=>2}' pool.pool.size.should.equal 1 res2 = req.get("/", "HTTP_COOKIE" => cookie) res2["Set-Cookie"].should.be.nil res2.body.should.equal '{"counter"=>3}' pool.pool.size.should.equal 1 end it "deletes cookies with :drop option" do pool = Rack::Session::Pool.new(incrementor) req = Rack::MockRequest.new(pool) drop = Rack::Utils::Context.new(pool, drop_session) dreq = Rack::MockRequest.new(drop) res1 = req.get("/") session = (cookie = res1["Set-Cookie"])[session_match] res1.body.should.equal '{"counter"=>1}' pool.pool.size.should.equal 1 res2 = dreq.get("/", "HTTP_COOKIE" => cookie) res2["Set-Cookie"].should.be.nil res2.body.should.equal '{"counter"=>2}' pool.pool.size.should.equal 0 res3 = req.get("/", "HTTP_COOKIE" => cookie) res3["Set-Cookie"][session_match].should.not.equal session res3.body.should.equal '{"counter"=>1}' pool.pool.size.should.equal 1 end it "provides new session id with :renew option" do pool = Rack::Session::Pool.new(incrementor) req = Rack::MockRequest.new(pool) renew = Rack::Utils::Context.new(pool, renew_session) rreq = Rack::MockRequest.new(renew) res1 = req.get("/") session = (cookie = res1["Set-Cookie"])[session_match] res1.body.should.equal '{"counter"=>1}' pool.pool.size.should.equal 1 res2 = rreq.get("/", "HTTP_COOKIE" => cookie) new_cookie = res2["Set-Cookie"] new_session = new_cookie[session_match] new_session.should.not.equal session res2.body.should.equal '{"counter"=>2}' pool.pool.size.should.equal 1 res3 = req.get("/", "HTTP_COOKIE" => new_cookie) res3.body.should.equal '{"counter"=>3}' pool.pool.size.should.equal 1 res4 = req.get("/", "HTTP_COOKIE" => cookie) res4.body.should.equal '{"counter"=>1}' pool.pool.size.should.equal 2 end it "omits cookie with :defer option" do pool = Rack::Session::Pool.new(incrementor) defer = Rack::Utils::Context.new(pool, defer_session) dreq = Rack::MockRequest.new(defer) res1 = dreq.get("/") res1["Set-Cookie"].should.equal nil res1.body.should.equal '{"counter"=>1}' pool.pool.size.should.equal 1 end # anyone know how to do this better? it "should merge sessions when multithreaded" do unless $DEBUG 1.should.equal 1 next end warn 'Running multithread tests for Session::Pool' pool = Rack::Session::Pool.new(incrementor) req = Rack::MockRequest.new(pool) res = req.get('/') res.body.should.equal '{"counter"=>1}' cookie = res["Set-Cookie"] sess_id = cookie[/#{pool.key}=([^,;]+)/,1] delta_incrementor = lambda do |env| # emulate disconjoinment of threading env['rack.session'] = env['rack.session'].dup Thread.stop env['rack.session'][(Time.now.usec*rand).to_i] = true incrementor.call(env) end tses = Rack::Utils::Context.new pool, delta_incrementor treq = Rack::MockRequest.new(tses) tnum = rand(7).to_i+5 r = Array.new(tnum) do Thread.new(treq) do |run| run.get('/', "HTTP_COOKIE" => cookie, 'rack.multithread' => true) end end.reverse.map{|t| t.run.join.value } r.each do |resp| resp['Set-Cookie'].should.equal cookie resp.body.should.include '"counter"=>2' end session = pool.pool[sess_id] session.size.should.equal tnum+1 # counter session['counter'].should.equal 2 # meeeh end it "does not return a cookie if cookie was not read/written" do app = Rack::Session::Pool.new(nothing) res = Rack::MockRequest.new(app).get("/") res["Set-Cookie"].should.be.nil end it "does not return a cookie if cookie was not written (only read)" do app = Rack::Session::Pool.new(session_id) res = Rack::MockRequest.new(app).get("/") res["Set-Cookie"].should.be.nil end it "returns even if not read/written if :expire_after is set" do app = Rack::Session::Pool.new(nothing, :expire_after => 3600) res = Rack::MockRequest.new(app).get("/", 'rack.session' => {'not' => 'empty'}) res["Set-Cookie"].should.not.be.nil end it "returns no cookie if no data was written and no session was created previously, even if :expire_after is set" do app = Rack::Session::Pool.new(nothing, :expire_after => 3600) res = Rack::MockRequest.new(app).get("/") res["Set-Cookie"].should.be.nil end end
Upload File
Create Folder