2005-06-04 19:45:47 +00:00
|
|
|
#!/usr/bin/ruby
|
|
|
|
|
2005-06-09 06:18:27 +00:00
|
|
|
$:.unshift(File.join(File.dirname(__FILE__), '..'))
|
2005-06-04 19:45:47 +00:00
|
|
|
|
|
|
|
require 'test/unit'
|
2005-07-09 21:18:49 +00:00
|
|
|
require 'rex/exceptions'
|
2005-06-04 19:45:47 +00:00
|
|
|
|
|
|
|
module Rex
|
|
|
|
module Exceptions
|
|
|
|
|
|
|
|
class UnitTest < Test::Unit::TestCase
|
|
|
|
|
|
|
|
def test_exceptions
|
|
|
|
Rex.constants.each { |const|
|
|
|
|
mod = Rex.const_get(const)
|
|
|
|
|
|
|
|
if ((mod.kind_of?(Class) == false) ||
|
|
|
|
(mod.ancestors.include?(Rex::Exception) == false))
|
|
|
|
next
|
|
|
|
end
|
|
|
|
|
|
|
|
begin
|
|
|
|
raise mod.new
|
2005-09-29 20:18:24 +00:00
|
|
|
rescue ::ArgumentError
|
2005-06-04 19:45:47 +00:00
|
|
|
rescue mod => detail
|
|
|
|
assert_respond_to(detail, 'to_s', "#{mod} does not implement to_s")
|
|
|
|
assert_not_nil(detail.to_s, "invalid to_s")
|
|
|
|
end
|
|
|
|
}
|
2005-06-04 19:56:54 +00:00
|
|
|
|
|
|
|
# Test communication error detail strings
|
|
|
|
begin
|
|
|
|
raise ConnectionRefused.new('127.0.0.1', 4444)
|
|
|
|
rescue HostCommunicationError => detail
|
|
|
|
assert_match(/^The connection(.*)\(127.0.0.1:4444\)/, detail.to_s)
|
|
|
|
assert_equal('127.0.0.1', detail.host)
|
|
|
|
assert_equal(4444, detail.port)
|
|
|
|
end
|
2005-06-04 19:45:47 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|