2011-01-18 19:08:49 -05:00
|
|
|
######################################################################
|
|
|
|
# This file is imported from the rubygems project.
|
|
|
|
# DO NOT make modifications in this repo. They _will_ be reverted!
|
|
|
|
# File a patch instead and assign it to Ryan Davis or Eric Hodel.
|
|
|
|
######################################################################
|
|
|
|
|
|
|
|
require "test/rubygems/gemutilities"
|
|
|
|
require "test/rubygems/simple_gem"
|
2007-11-10 02:48:56 -05:00
|
|
|
require 'rubygems/validator'
|
|
|
|
|
|
|
|
class TestGemValidator < RubyGemTestCase
|
|
|
|
|
|
|
|
def setup
|
|
|
|
super
|
|
|
|
|
|
|
|
@simple_gem = SIMPLE_GEM
|
|
|
|
@validator = Gem::Validator.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_verify_gem_file
|
|
|
|
gem_file = File.join @tempdir, 'simple_gem.gem'
|
|
|
|
File.open gem_file, 'wb' do |fp| fp.write @simple_gem end
|
|
|
|
|
|
|
|
assert_equal nil, @validator.verify_gem_file(gem_file)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_verify_gem_file_empty
|
2008-10-25 18:58:43 -04:00
|
|
|
e = assert_raises Gem::VerificationError do
|
2007-11-10 02:48:56 -05:00
|
|
|
@validator.verify_gem_file ''
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal 'missing gem file ', e.message
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_verify_gem_file_nonexistent
|
|
|
|
file = '/nonexistent/nonexistent.gem'
|
2008-10-25 18:58:43 -04:00
|
|
|
e = assert_raises Gem::VerificationError do
|
2007-11-10 02:48:56 -05:00
|
|
|
@validator.verify_gem_file file
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal "missing gem file #{file}", e.message
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_verify_gem
|
|
|
|
assert_equal nil, @validator.verify_gem(@simple_gem)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_verify_gem_empty
|
2008-10-25 18:58:43 -04:00
|
|
|
e = assert_raises Gem::VerificationError do
|
2007-11-10 02:48:56 -05:00
|
|
|
@validator.verify_gem ''
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal 'empty gem file', e.message
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_verify_gem_invalid_checksum
|
2008-10-25 18:58:43 -04:00
|
|
|
e = assert_raises Gem::VerificationError do
|
2007-11-10 02:48:56 -05:00
|
|
|
@validator.verify_gem @simple_gem.upcase
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal 'invalid checksum for gem file', e.message
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_verify_gem_no_sum
|
|
|
|
assert_equal nil, @validator.verify_gem('words')
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|