2009-10-03 11:59:29 -04:00
|
|
|
require_relative 'gemutilities'
|
2007-11-10 02:48:56 -05:00
|
|
|
require 'rubygems/server'
|
|
|
|
require 'stringio'
|
|
|
|
|
|
|
|
class Gem::Server
|
2007-12-20 03:39:12 -05:00
|
|
|
attr_accessor :source_index
|
2007-11-10 02:48:56 -05:00
|
|
|
attr_reader :server
|
|
|
|
end
|
|
|
|
|
|
|
|
class TestGemServer < RubyGemTestCase
|
|
|
|
|
|
|
|
def setup
|
|
|
|
super
|
|
|
|
|
|
|
|
@a1 = quick_gem 'a', '1'
|
2008-06-17 18:04:18 -04:00
|
|
|
@a2 = quick_gem 'a', '2'
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-04-11 16:57:02 -04:00
|
|
|
@server = Gem::Server.new Gem.dir, process_based_port, false
|
2007-11-10 02:48:56 -05:00
|
|
|
@req = WEBrick::HTTPRequest.new :Logger => nil
|
|
|
|
@res = WEBrick::HTTPResponse.new :HTTPVersion => '1.0'
|
|
|
|
end
|
|
|
|
|
2010-04-22 04:24:42 -04:00
|
|
|
def test_spec_dirs
|
|
|
|
s = Gem::Server.new Gem.dir, process_based_port, false
|
|
|
|
|
|
|
|
assert_equal [File.join(Gem.dir, 'specifications')], s.spec_dirs
|
|
|
|
|
|
|
|
s = Gem::Server.new [Gem.dir, Gem.dir], process_based_port, false
|
|
|
|
|
|
|
|
assert_equal [File.join(Gem.dir, 'specifications'),
|
|
|
|
File.join(Gem.dir, 'specifications')], s.spec_dirs
|
|
|
|
end
|
|
|
|
|
2008-06-17 18:04:18 -04:00
|
|
|
def test_Marshal
|
|
|
|
data = StringIO.new "GET /Marshal.#{Gem.marshal_version} HTTP/1.0\r\n\r\n"
|
2007-11-10 02:48:56 -05:00
|
|
|
@req.parse data
|
|
|
|
|
2008-06-17 18:04:18 -04:00
|
|
|
@server.Marshal @req, @res
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2007-12-20 03:39:12 -05:00
|
|
|
assert_equal 200, @res.status, @res.body
|
2007-11-10 02:48:56 -05:00
|
|
|
assert_match %r| \d\d:\d\d:\d\d |, @res['date']
|
2008-06-17 18:04:18 -04:00
|
|
|
assert_equal 'application/octet-stream', @res['content-type']
|
|
|
|
|
|
|
|
si = Gem::SourceIndex.new
|
|
|
|
si.add_specs @a1, @a2
|
|
|
|
|
|
|
|
assert_equal si, Marshal.load(@res.body)
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
2008-06-17 18:04:18 -04:00
|
|
|
def test_Marshal_Z
|
|
|
|
data = StringIO.new "GET /Marshal.#{Gem.marshal_version}.Z HTTP/1.0\r\n\r\n"
|
2007-11-10 02:48:56 -05:00
|
|
|
@req.parse data
|
|
|
|
|
2008-06-17 18:04:18 -04:00
|
|
|
@server.Marshal @req, @res
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2007-12-20 03:39:12 -05:00
|
|
|
assert_equal 200, @res.status, @res.body
|
2007-11-10 02:48:56 -05:00
|
|
|
assert_match %r| \d\d:\d\d:\d\d |, @res['date']
|
2008-06-17 18:04:18 -04:00
|
|
|
assert_equal 'application/x-deflate', @res['content-type']
|
|
|
|
|
|
|
|
si = Gem::SourceIndex.new
|
|
|
|
si.add_specs @a1, @a2
|
|
|
|
|
|
|
|
assert_equal si, Marshal.load(Gem.inflate(@res.body))
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_latest_specs
|
|
|
|
data = StringIO.new "GET /latest_specs.#{Gem.marshal_version} HTTP/1.0\r\n\r\n"
|
|
|
|
@req.parse data
|
|
|
|
|
|
|
|
@server.latest_specs @req, @res
|
|
|
|
|
|
|
|
assert_equal 200, @res.status, @res.body
|
|
|
|
assert_match %r| \d\d:\d\d:\d\d |, @res['date']
|
|
|
|
assert_equal 'application/octet-stream', @res['content-type']
|
|
|
|
assert_equal [['a', Gem::Version.new(2), Gem::Platform::RUBY]],
|
|
|
|
Marshal.load(@res.body)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_latest_specs_gz
|
|
|
|
data = StringIO.new "GET /latest_specs.#{Gem.marshal_version}.gz HTTP/1.0\r\n\r\n"
|
|
|
|
@req.parse data
|
|
|
|
|
|
|
|
@server.latest_specs @req, @res
|
|
|
|
|
|
|
|
assert_equal 200, @res.status, @res.body
|
|
|
|
assert_match %r| \d\d:\d\d:\d\d |, @res['date']
|
|
|
|
assert_equal 'application/x-gzip', @res['content-type']
|
|
|
|
assert_equal [['a', Gem::Version.new(2), Gem::Platform::RUBY]],
|
|
|
|
Marshal.load(Gem.gunzip(@res.body))
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
2010-02-21 21:52:35 -05:00
|
|
|
def test_listen
|
|
|
|
util_listen
|
|
|
|
|
|
|
|
out, err = capture_io do
|
|
|
|
@server.listen
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal 1, @server.server.listeners.length
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_listen_addresses
|
|
|
|
util_listen
|
|
|
|
|
|
|
|
out, err = capture_io do
|
|
|
|
@server.listen %w[a b]
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal 2, @server.server.listeners.length
|
|
|
|
end
|
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
def test_quick_a_1_gemspec_rz
|
|
|
|
data = StringIO.new "GET /quick/a-1.gemspec.rz HTTP/1.0\r\n\r\n"
|
|
|
|
@req.parse data
|
|
|
|
|
|
|
|
@server.quick @req, @res
|
|
|
|
|
2007-12-20 03:39:12 -05:00
|
|
|
assert_equal 200, @res.status, @res.body
|
2007-11-10 02:48:56 -05:00
|
|
|
assert @res['date']
|
2008-06-17 18:04:18 -04:00
|
|
|
assert_equal 'application/x-deflate', @res['content-type']
|
2008-02-10 03:00:19 -05:00
|
|
|
|
2008-06-17 18:04:18 -04:00
|
|
|
spec = YAML.load Gem.inflate(@res.body)
|
2008-02-10 03:00:19 -05:00
|
|
|
assert_equal 'a', spec.name
|
|
|
|
assert_equal Gem::Version.new(1), spec.version
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
2007-12-20 03:39:12 -05:00
|
|
|
def test_quick_a_1_mswin32_gemspec_rz
|
|
|
|
a1_p = quick_gem 'a', '1' do |s| s.platform = Gem::Platform.local end
|
|
|
|
|
|
|
|
data = StringIO.new "GET /quick/a-1-#{Gem::Platform.local}.gemspec.rz HTTP/1.0\r\n\r\n"
|
|
|
|
@req.parse data
|
|
|
|
|
|
|
|
@server.quick @req, @res
|
|
|
|
|
|
|
|
assert_equal 200, @res.status, @res.body
|
|
|
|
assert @res['date']
|
2008-06-17 18:04:18 -04:00
|
|
|
assert_equal 'application/x-deflate', @res['content-type']
|
2008-02-10 03:00:19 -05:00
|
|
|
|
2008-06-17 18:04:18 -04:00
|
|
|
spec = YAML.load Gem.inflate(@res.body)
|
2008-02-10 03:00:19 -05:00
|
|
|
assert_equal 'a', spec.name
|
|
|
|
assert_equal Gem::Version.new(1), spec.version
|
|
|
|
assert_equal Gem::Platform.local, spec.platform
|
2007-12-20 03:39:12 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_quick_common_substrings
|
|
|
|
ab1 = quick_gem 'ab', '1'
|
|
|
|
|
|
|
|
data = StringIO.new "GET /quick/a-1.gemspec.rz HTTP/1.0\r\n\r\n"
|
|
|
|
@req.parse data
|
|
|
|
|
|
|
|
@server.quick @req, @res
|
|
|
|
|
|
|
|
assert_equal 200, @res.status, @res.body
|
|
|
|
assert @res['date']
|
2008-06-17 18:04:18 -04:00
|
|
|
assert_equal 'application/x-deflate', @res['content-type']
|
2008-02-10 03:00:19 -05:00
|
|
|
|
2008-06-17 18:04:18 -04:00
|
|
|
spec = YAML.load Gem.inflate(@res.body)
|
2008-02-10 03:00:19 -05:00
|
|
|
assert_equal 'a', spec.name
|
|
|
|
assert_equal Gem::Version.new(1), spec.version
|
2007-12-20 03:39:12 -05:00
|
|
|
end
|
|
|
|
|
2008-06-17 18:04:18 -04:00
|
|
|
def test_quick_index
|
|
|
|
data = StringIO.new "GET /quick/index HTTP/1.0\r\n\r\n"
|
|
|
|
@req.parse data
|
|
|
|
|
|
|
|
@server.quick @req, @res
|
|
|
|
|
|
|
|
assert_equal 200, @res.status, @res.body
|
|
|
|
assert_match %r| \d\d:\d\d:\d\d |, @res['date']
|
|
|
|
assert_equal 'text/plain', @res['content-type']
|
|
|
|
assert_equal "a-1\na-2", @res.body
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_quick_index_rz
|
|
|
|
data = StringIO.new "GET /quick/index.rz HTTP/1.0\r\n\r\n"
|
|
|
|
@req.parse data
|
|
|
|
|
|
|
|
@server.quick @req, @res
|
|
|
|
|
|
|
|
assert_equal 200, @res.status, @res.body
|
|
|
|
assert_match %r| \d\d:\d\d:\d\d |, @res['date']
|
|
|
|
assert_equal 'application/x-deflate', @res['content-type']
|
|
|
|
assert_equal "a-1\na-2", Gem.inflate(@res.body)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_quick_latest_index
|
|
|
|
data = StringIO.new "GET /quick/latest_index HTTP/1.0\r\n\r\n"
|
|
|
|
@req.parse data
|
|
|
|
|
|
|
|
@server.quick @req, @res
|
|
|
|
|
|
|
|
assert_equal 200, @res.status, @res.body
|
|
|
|
assert_match %r| \d\d:\d\d:\d\d |, @res['date']
|
|
|
|
assert_equal 'text/plain', @res['content-type']
|
|
|
|
assert_equal 'a-2', @res.body
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_quick_latest_index_rz
|
|
|
|
data = StringIO.new "GET /quick/latest_index.rz HTTP/1.0\r\n\r\n"
|
|
|
|
@req.parse data
|
|
|
|
|
|
|
|
@server.quick @req, @res
|
|
|
|
|
|
|
|
assert_equal 200, @res.status, @res.body
|
|
|
|
assert_match %r| \d\d:\d\d:\d\d |, @res['date']
|
|
|
|
assert_equal 'application/x-deflate', @res['content-type']
|
|
|
|
assert_equal 'a-2', Gem.inflate(@res.body)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_quick_missing
|
2007-11-10 02:48:56 -05:00
|
|
|
data = StringIO.new "GET /quick/z-9.gemspec.rz HTTP/1.0\r\n\r\n"
|
|
|
|
@req.parse data
|
|
|
|
|
|
|
|
@server.quick @req, @res
|
|
|
|
|
2007-12-20 03:39:12 -05:00
|
|
|
assert_equal 404, @res.status, @res.body
|
2007-11-10 02:48:56 -05:00
|
|
|
assert_match %r| \d\d:\d\d:\d\d |, @res['date']
|
|
|
|
assert_equal 'text/plain', @res['content-type']
|
2007-12-20 03:39:12 -05:00
|
|
|
assert_equal 'No gems found matching "z" "9" nil', @res.body
|
2007-11-10 02:48:56 -05:00
|
|
|
assert_equal 404, @res.status
|
|
|
|
end
|
|
|
|
|
2008-06-17 18:04:18 -04:00
|
|
|
def test_quick_marshal_a_1_gemspec_rz
|
|
|
|
data = StringIO.new "GET /quick/Marshal.#{Gem.marshal_version}/a-1.gemspec.rz HTTP/1.0\r\n\r\n"
|
|
|
|
@req.parse data
|
|
|
|
|
|
|
|
@server.quick @req, @res
|
|
|
|
|
|
|
|
assert_equal 200, @res.status, @res.body
|
|
|
|
assert @res['date']
|
|
|
|
assert_equal 'application/x-deflate', @res['content-type']
|
|
|
|
|
|
|
|
spec = Marshal.load Gem.inflate(@res.body)
|
|
|
|
assert_equal 'a', spec.name
|
|
|
|
assert_equal Gem::Version.new(1), spec.version
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_quick_marshal_a_1_mswin32_gemspec_rz
|
|
|
|
a1_p = quick_gem 'a', '1' do |s| s.platform = Gem::Platform.local end
|
|
|
|
|
|
|
|
data = StringIO.new "GET /quick/Marshal.#{Gem.marshal_version}/a-1-#{Gem::Platform.local}.gemspec.rz HTTP/1.0\r\n\r\n"
|
|
|
|
@req.parse data
|
|
|
|
|
|
|
|
@server.quick @req, @res
|
|
|
|
|
|
|
|
assert_equal 200, @res.status, @res.body
|
|
|
|
assert @res['date']
|
|
|
|
assert_equal 'application/x-deflate', @res['content-type']
|
|
|
|
|
|
|
|
spec = Marshal.load Gem.inflate(@res.body)
|
|
|
|
assert_equal 'a', spec.name
|
|
|
|
assert_equal Gem::Version.new(1), spec.version
|
|
|
|
assert_equal Gem::Platform.local, spec.platform
|
|
|
|
end
|
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
def test_rdoc
|
|
|
|
data = StringIO.new "GET /rdoc?q=a HTTP/1.0\r\n\r\n"
|
|
|
|
@req.parse data
|
|
|
|
|
|
|
|
@server.rdoc @req, @res
|
|
|
|
|
|
|
|
assert_equal 200, @res.status, @res.body
|
|
|
|
assert_match %r|No documentation found|, @res.body
|
|
|
|
assert_equal 'text/html', @res['content-type']
|
|
|
|
end
|
2008-06-17 18:04:18 -04:00
|
|
|
|
|
|
|
def test_root
|
|
|
|
data = StringIO.new "GET / HTTP/1.0\r\n\r\n"
|
|
|
|
@req.parse data
|
|
|
|
|
|
|
|
@server.root @req, @res
|
|
|
|
|
|
|
|
assert_equal 200, @res.status, @res.body
|
|
|
|
assert_match %r| \d\d:\d\d:\d\d |, @res['date']
|
|
|
|
assert_equal 'text/html', @res['content-type']
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_specs
|
|
|
|
data = StringIO.new "GET /specs.#{Gem.marshal_version} HTTP/1.0\r\n\r\n"
|
|
|
|
@req.parse data
|
|
|
|
|
|
|
|
@server.specs @req, @res
|
|
|
|
|
|
|
|
assert_equal 200, @res.status, @res.body
|
|
|
|
assert_match %r| \d\d:\d\d:\d\d |, @res['date']
|
|
|
|
assert_equal 'application/octet-stream', @res['content-type']
|
|
|
|
|
|
|
|
assert_equal [['a', Gem::Version.new(1), Gem::Platform::RUBY],
|
|
|
|
['a', Gem::Version.new(2), Gem::Platform::RUBY]],
|
|
|
|
Marshal.load(@res.body)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_specs_gz
|
|
|
|
data = StringIO.new "GET /specs.#{Gem.marshal_version}.gz HTTP/1.0\r\n\r\n"
|
|
|
|
@req.parse data
|
|
|
|
|
|
|
|
@server.specs @req, @res
|
|
|
|
|
|
|
|
assert_equal 200, @res.status, @res.body
|
|
|
|
assert_match %r| \d\d:\d\d:\d\d |, @res['date']
|
|
|
|
assert_equal 'application/x-gzip', @res['content-type']
|
|
|
|
|
|
|
|
assert_equal [['a', Gem::Version.new(1), Gem::Platform::RUBY],
|
|
|
|
['a', Gem::Version.new(2), Gem::Platform::RUBY]],
|
|
|
|
Marshal.load(Gem.gunzip(@res.body))
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_yaml
|
|
|
|
data = StringIO.new "GET /yaml.#{Gem.marshal_version} HTTP/1.0\r\n\r\n"
|
|
|
|
@req.parse data
|
|
|
|
|
|
|
|
@server.yaml @req, @res
|
|
|
|
|
|
|
|
assert_equal 200, @res.status, @res.body
|
|
|
|
assert_match %r| \d\d:\d\d:\d\d |, @res['date']
|
|
|
|
assert_equal 'text/plain', @res['content-type']
|
|
|
|
|
|
|
|
si = Gem::SourceIndex.new
|
|
|
|
si.add_specs @a1, @a2
|
|
|
|
|
|
|
|
assert_equal si, YAML.load(@res.body)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_yaml_Z
|
|
|
|
data = StringIO.new "GET /yaml.#{Gem.marshal_version}.Z HTTP/1.0\r\n\r\n"
|
|
|
|
@req.parse data
|
|
|
|
|
|
|
|
@server.yaml @req, @res
|
|
|
|
|
|
|
|
assert_equal 200, @res.status, @res.body
|
|
|
|
assert_match %r| \d\d:\d\d:\d\d |, @res['date']
|
|
|
|
assert_equal 'application/x-deflate', @res['content-type']
|
|
|
|
|
|
|
|
si = Gem::SourceIndex.new
|
|
|
|
si.add_specs @a1, @a2
|
|
|
|
|
|
|
|
assert_equal si, YAML.load(Gem.inflate(@res.body))
|
|
|
|
end
|
|
|
|
|
2010-02-21 21:52:35 -05:00
|
|
|
def util_listen
|
|
|
|
webrick = Object.new
|
|
|
|
webrick.instance_variable_set :@listeners, []
|
|
|
|
def webrick.listeners() @listeners end
|
|
|
|
def webrick.listen(host, port)
|
|
|
|
socket = Object.new
|
|
|
|
socket.instance_variable_set :@host, host
|
|
|
|
socket.instance_variable_set :@port, port
|
|
|
|
def socket.addr() [nil, @port, @host] end
|
|
|
|
@listeners << socket
|
|
|
|
end
|
|
|
|
|
|
|
|
@server.instance_variable_set :@server, webrick
|
|
|
|
end
|
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|