2005-12-17 06:46:23 +00:00
|
|
|
#!/usr/bin/env ruby
|
2012-06-29 05:18:28 +00:00
|
|
|
# -*- coding: binary -*-
|
2005-05-26 06:35:37 +00:00
|
|
|
|
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
|
2010-03-11 13:54:10 +00:00
|
|
|
def on_session_close(session,reason='')
|
2005-05-26 06:35:37 +00:00
|
|
|
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")
|
2010-03-11 13:54:10 +00:00
|
|
|
assert_equal(1, session.sid,
|
2005-05-26 06:35:37 +00:00
|
|
|
"Session sid was not initialized properly")
|
2010-03-11 13:54:10 +00:00
|
|
|
assert_equal(framework, session.framework,
|
2005-05-26 06:35:37 +00:00
|
|
|
"Session framework was not initialized properly")
|
2010-03-11 13:54:10 +00:00
|
|
|
assert_equal(1, manager.entries.length,
|
2005-05-26 06:35:37 +00:00
|
|
|
"Number of session manager entries is not one")
|
2010-03-11 13:54:10 +00:00
|
|
|
assert_equal(session, manager[session.sid],
|
2005-05-26 06:35:37 +00:00
|
|
|
"Index of sid did not return session")
|
|
|
|
|
|
|
|
manager.deregister(session)
|
2010-03-11 13:54:10 +00:00
|
|
|
|
|
|
|
assert_equal(0, manager.entries.length,
|
2005-05-26 06:35:37 +00:00
|
|
|
"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)
|
2010-03-11 13:54:10 +00:00
|
|
|
assert_equal(handler.open_session, session,
|
2005-05-26 06:35:37 +00:00
|
|
|
"Open session handler not called")
|
|
|
|
|
|
|
|
manager.deregister(session)
|
2010-03-11 13:54:10 +00:00
|
|
|
assert_equal(handler.close_session, session,
|
2005-05-26 06:35:37 +00:00
|
|
|
"Close session handler not called")
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2010-03-11 13:54:10 +00:00
|
|
|
end
|
|
|
|
|