2005-05-26 06:35:37 +00:00
|
|
|
#!/usr/bin/ruby
|
|
|
|
|
2005-06-09 06:18:27 +00:00
|
|
|
$:.unshift(File.join(File.dirname(__FILE__), '..', '..'))
|
2005-05-26 06:35:37 +00:00
|
|
|
|
|
|
|
require 'test/unit'
|
2005-07-09 21:18:49 +00:00
|
|
|
require 'msf/core/session_manager'
|
2005-05-26 06:35:37 +00:00
|
|
|
|
|
|
|
module Msf
|
|
|
|
|
|
|
|
class SessionManager::UnitTest < Test::Unit::TestCase
|
|
|
|
|
2005-10-30 22:20:29 +00:00
|
|
|
class UtSessionEvent
|
|
|
|
include SessionEvent
|
2005-05-26 06:35:37 +00:00
|
|
|
|
|
|
|
def on_session_open(session)
|
|
|
|
self.open_session = session
|
|
|
|
end
|
|
|
|
def on_session_close(session)
|
|
|
|
self.close_session = session
|
|
|
|
end
|
|
|
|
|
|
|
|
attr_accessor :open_session, :close_session
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Tests to make sure session registration functions properly
|
|
|
|
#
|
|
|
|
def test_registration
|
|
|
|
framework = Framework.new
|
|
|
|
manager = SessionManager.new(framework)
|
|
|
|
|
2005-09-24 18:42:29 +00:00
|
|
|
session = Class.new
|
|
|
|
session.extend(Session)
|
2005-05-26 06:35:37 +00:00
|
|
|
|
|
|
|
assert_equal(1, manager.register(session), "Did not get expected sid")
|
|
|
|
assert_equal(1, session.sid,
|
|
|
|
"Session sid was not initialized properly")
|
|
|
|
assert_equal(framework, session.framework,
|
|
|
|
"Session framework was not initialized properly")
|
|
|
|
assert_equal(1, manager.entries.length,
|
|
|
|
"Number of session manager entries is not one")
|
|
|
|
assert_equal(session, manager[session.sid],
|
|
|
|
"Index of sid did not return session")
|
|
|
|
|
|
|
|
manager.deregister(session)
|
|
|
|
|
|
|
|
assert_equal(0, manager.entries.length,
|
|
|
|
"Number of session manager entries is not zero")
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Test session notification events
|
|
|
|
#
|
|
|
|
def test_notify
|
|
|
|
framework = Framework.new
|
|
|
|
manager = SessionManager.new(framework)
|
2005-10-30 22:20:29 +00:00
|
|
|
handler = UtSessionEvent.new
|
2005-09-24 18:42:29 +00:00
|
|
|
session = Class.new
|
|
|
|
session.extend(Session)
|
2005-05-26 06:35:37 +00:00
|
|
|
|
|
|
|
framework.events.add_session_subscriber(handler)
|
|
|
|
|
|
|
|
manager.register(session)
|
|
|
|
assert_equal(handler.open_session, session,
|
|
|
|
"Open session handler not called")
|
|
|
|
|
|
|
|
manager.deregister(session)
|
|
|
|
assert_equal(handler.close_session, session,
|
|
|
|
"Close session handler not called")
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|