1
mirror of https://github.com/rapid7/metasploit-framework synced 2024-11-05 14:57:30 +01:00

unit testage changes

git-svn-id: file:///home/svn/incoming/trunk@2513 4d416f70-5f16-0410-b530-b9f4589650da
This commit is contained in:
Matt Miller 2005-05-24 05:35:12 +00:00
parent 54daa98c67
commit a39521daa0
5 changed files with 116 additions and 110 deletions

View File

@ -9,10 +9,6 @@
#
###
# Unit testing
#require 'test/unit'
require 'Msf/Core/UnitTestSuite'
# framework-core depends on framework-shared
require 'Msf/Shared'

15
lib/msf/core.rb.ts.rb Normal file
View File

@ -0,0 +1,15 @@
#!/usr/bin/ruby
require 'test/unit'
require 'Msf/Core'
require 'Msf/Core/OptionContainer.rb.ut'
class Msf::TestSuite
def self.suite
suite = Test::Unit::TestSuite.new
suite << Msf::OptionContainer::UnitTest.suite
return suite;
end
end

View File

@ -236,108 +236,4 @@ class OptionContainer < Hash
end
module Test
begin
###
#
# OptionContainerTestCase
# -----------------------
#
# This class implements some testing routines for ensuring that the option
# container is operating correctly.
#
###
class OptionContainerTestCase < ::Test::Unit::TestCase
# Tests the initialization of the OptionContainer object
def test_initialize
# Make sure initialization works
options = nil
assert_block("initialize failed") {
options = OptionContainer.new(
'rhost' => [ OptAddress, true, nil, 'host.com' ],
'rport' => [ OptPort, true, nil, 1234 ])
if (options == nil)
false
end
true
}
# Make sure there are 2 options
assert_equal(2, options.length, "invalid number of options #{options.length}")
# Make sure that the constructor raises an argument error when
# an invalid option is supplied
assert_raise(ArgumentError, "initialize invalid failed") {
OptionContainer.new(
'rhost' => 'invalid');
}
end
# Tests getting the value of an option
def test_get
options = OptionContainer.new(
'rport' => [ OptPort, true, nil, 1234 ])
assert_equal(1234, options.get('rport').default,
"option default does not match")
assert_equal(true, options.get('rport').required?,
"option required does not match")
assert_equal('rport', options['rport'].name,
"option name does not match")
end
# Tests validation
def test_validate
# Test validating required options
options = OptionContainer.new(
'rhost' => [ OptAddress, true ],
'rport' => [ OptPort, true ],
'Lib' => [ OptString ])
ds = DataStore.new
assert_raise(OptionValidateError, "required validation failed") {
options.validate(ds)
}
ds['rhost'] = 'www.invalid.host.tldinvalid'
ds['rport'] = 1234
assert_raise(OptionValidateError, "host validation failed") {
options.validate(ds)
}
# Make sure address validation does work
ds['rhost'] = 'www.google.com'
assert_equal(true, options.validate(ds), "overall validation failed")
# Make sure port validation does work
ds['rport'] = 23423423
assert_raise(OptionValidateError, "port validation failed") {
options.validate(ds)
}
end
# Make sure advanced additions work
def test_advanced
options = OptionContainer.new
options.add_advanced_options(
'DONKEY' => [ OptString, false ])
assert_equal(true, options.get('DONKEY').advanced?,
"advanced option failed")
end
end
rescue
end
end
end

View File

@ -0,0 +1,99 @@
#!/usr/bin/ruby
$:.unshift(File.join('..', '..', File.dirname(__FILE__)))
require 'test/unit'
require 'Msf/Core/OptionContainer'
module Msf
class OptionContainer::UnitTest < Test::Unit::TestCase
# Tests the initialization of the OptionContainer object
def test_initialize
# Make sure initialization works
options = nil
assert_block("initialize failed") {
options = OptionContainer.new(
'rhost' => [ OptAddress, true, nil, 'host.com' ],
'rport' => [ OptPort, true, nil, 1234 ])
if (options == nil)
false
end
true
}
# Make sure there are 2 options
assert_equal(2, options.length, "invalid number of options #{options.length}")
# Make sure that the constructor raises an argument error when
# an invalid option is supplied
assert_raise(ArgumentError, "initialize invalid failed") {
OptionContainer.new(
'rhost' => 'invalid');
}
end
# Tests getting the value of an option
def test_get
options = OptionContainer.new(
'rport' => [ OptPort, true, nil, 1234 ])
assert_equal(1234, options.get('rport').default,
"option default does not match")
assert_equal(true, options.get('rport').required?,
"option required does not match")
assert_equal('rport', options['rport'].name,
"option name does not match")
end
# Tests validation
def test_validate
# Test validating required options
options = OptionContainer.new(
'rhost' => [ OptAddress, true ],
'rport' => [ OptPort, true ],
'Lib' => [ OptString ])
ds = DataStore.new
assert_raise(OptionValidateError, "required validation failed") {
options.validate(ds)
}
ds['rhost'] = 'www.invalid.host.tldinvalid'
ds['rport'] = 1234
assert_raise(OptionValidateError, "host validation failed") {
options.validate(ds)
}
# Make sure address validation does work
ds['rhost'] = 'www.google.com'
assert_equal(true, options.validate(ds), "overall validation failed")
# Make sure port validation does work
ds['rport'] = 23423423
assert_raise(OptionValidateError, "port validation failed") {
options.validate(ds)
}
end
# Make sure advanced additions work
def test_advanced
options = OptionContainer.new
options.add_advanced_options(
'DONKEY' => [ OptString, false ])
assert_equal(true, options.get('DONKEY').advanced?,
"advanced option failed")
end
end
end

View File

@ -1,6 +1,6 @@
#!/usr/bin/ruby -I../Lib
require 'test/unit/ui/console/testrunner'
require 'Msf/Core'
require 'Msf/Core.rb.ts'
Test::Unit::UI::Console::TestRunner.run(Msf::Test::FrameworkCoreTestSuite)
Test::Unit::UI::Console::TestRunner.run(Msf::TestSuite)