2012-03-01 23:30:37 +00:00
|
|
|
|
|
|
|
|
2012-03-03 00:55:11 +00:00
|
|
|
module Msf
|
2012-03-01 23:30:37 +00:00
|
|
|
|
2012-03-03 00:55:11 +00:00
|
|
|
module ModuleTest
|
|
|
|
attr_accessor :tests
|
|
|
|
attr_accessor :failures
|
|
|
|
|
|
|
|
def initialize(info={})
|
|
|
|
@tests = 0
|
|
|
|
@failures = 0
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
|
|
|
def run_all_tests
|
|
|
|
tests = self.methods.select { |m| m.to_s =~ /^test_/ }
|
|
|
|
tests.each { |test_method|
|
|
|
|
self.send(test_method)
|
|
|
|
}
|
|
|
|
|
|
|
|
end
|
2012-03-01 23:30:37 +00:00
|
|
|
|
|
|
|
def it(msg="", &block)
|
2012-03-03 00:55:11 +00:00
|
|
|
@tests += 1
|
2012-03-01 23:30:37 +00:00
|
|
|
begin
|
|
|
|
result = block.call
|
|
|
|
unless result
|
|
|
|
print_error("FAILED: #{msg}")
|
|
|
|
print_error("FAILED: #{error}") if error
|
2012-03-03 00:55:11 +00:00
|
|
|
@failures += 1
|
2012-03-01 23:30:37 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
rescue ::Exception => e
|
|
|
|
print_error("FAILED: #{msg}")
|
|
|
|
print_error("Exception: #{e.class} : #{e}")
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
print_good("#{msg}")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-03-03 00:55:11 +00:00
|
|
|
module ModuleTest::PostTest
|
|
|
|
include ModuleTest
|
|
|
|
def run
|
|
|
|
print_status("Running against session #{datastore["SESSION"]}")
|
|
|
|
print_status("Session type is #{session.type}")
|
|
|
|
print_status("Session platform is #{session.platform}")
|
2012-03-01 23:30:37 +00:00
|
|
|
|
2012-03-03 00:55:11 +00:00
|
|
|
@tests = 0; @failures = 0
|
|
|
|
run_all_tests
|
2012-03-01 23:30:37 +00:00
|
|
|
|
2012-03-03 00:55:11 +00:00
|
|
|
vprint_status("Testing complete.")
|
|
|
|
print_status("Passed: #{@tests - @failures}; Failed: #{@failures}")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|