Spec Msf::Simple::Framework#init_module_paths

[#47720609]
unstable
Luke Imhoff 2013-05-24 12:33:42 -05:00
parent c22178752e
commit 4ba571346e
4 changed files with 139 additions and 27 deletions

View File

@ -1,5 +1,6 @@
# -*- coding: binary -*-
require 'msf/base/simple'
require 'msf/base/simple/framework/module_paths'
module Msf
module Simple
@ -12,6 +13,7 @@ module Simple
#
###
module Framework
include Msf::Simple::Framework::ModulePaths
###
#
@ -155,33 +157,6 @@ module Framework
self.datastore.to_file(Msf::Config.config_file, 'framework/core')
end
#
# Initialize the module paths
#
def init_module_paths
# Ensure the module cache is accurate
self.modules.refresh_cache_from_database
# Initialize the default module search paths
if (Msf::Config.module_directory)
self.modules.add_module_path(Msf::Config.module_directory)
end
# Initialize the user module search path
if (Msf::Config.user_module_directory)
self.modules.add_module_path(Msf::Config.user_module_directory)
end
# If additional module paths have been defined globally, then load them.
# They should be separated by semi-colons.
if self.datastore['MsfModulePaths']
self.datastore['MsfModulePaths'].split(";").each { |path|
self.modules.add_module_path(path)
}
end
end
#
# Statistics.
#

View File

@ -0,0 +1,33 @@
module Msf
module Simple
module Framework
module ModulePaths
# Initialize the module paths
#
# @return [void]
def init_module_paths
# Ensure the module cache is accurate
self.modules.refresh_cache_from_database
# Initialize the default module search paths
if (Msf::Config.module_directory)
self.modules.add_module_path(Msf::Config.module_directory)
end
# Initialize the user module search path
if (Msf::Config.user_module_directory)
self.modules.add_module_path(Msf::Config.user_module_directory)
end
# If additional module paths have been defined globally, then load them.
# They should be separated by semi-colons.
if self.datastore['MsfModulePaths']
self.datastore['MsfModulePaths'].split(";").each { |path|
self.modules.add_module_path(path)
}
end
end
end
end
end
end

View File

@ -0,0 +1,11 @@
require 'spec_helper'
describe Msf::Simple::Framework do
include_context 'Msf::Simple::Framework'
subject do
framework
end
it_should_behave_like 'Msf::Simple::Framework::ModulePaths'
end

View File

@ -0,0 +1,93 @@
shared_examples_for 'Msf::Simple::Framework::ModulePaths' do
it { should be_a Msf::Simple::Framework::ModulePaths }
context '#init_module_paths' do
def init_module_paths
framework.init_module_paths
end
let(:module_directory) do
nil
end
let(:user_module_directory) do
nil
end
before(:each) do
# create the framework first so that it's initialization's call
# to init_module_paths doesn't get captured.
framework
Msf::Config.stub(:module_directory => module_directory)
Msf::Config.stub(:user_module_directory => user_module_directory)
end
it 'should refresh module cache from database' do
framework.modules.should_receive(:refresh_cache_from_database)
init_module_paths
end
context 'Msf::Config' do
context 'module_directory' do
context 'without nil' do
let(:module_directory) do
'modules'
end
it 'should add Msf::Config.module_directory to module paths' do
framework.modules.should_receive(:add_module_path).with(
module_directory
)
init_module_paths
end
end
end
context 'user_module_directory' do
context 'without nil' do
let(:user_module_directory) do
'user/modules'
end
it 'should add Msf::Config.user_module_directory to module paths' do
framework.modules.should_receive(:add_module_path).with(
user_module_directory
)
init_module_paths
end
end
end
end
context 'datastore' do
context 'MsfModulePaths' do
let(:module_paths) do
module_paths = []
1.upto(2) do |i|
module_paths << "msf/#{i}/modules"
end
module_paths
end
before(:each) do
msf_module_paths = module_paths.join(';')
framework.datastore['MsfModulePaths'] = msf_module_paths
end
it 'should add each module path' do
module_paths.each do |module_path|
framework.modules.should_receive(:add_module_path).with(module_path)
end
init_module_paths
end
end
end
end
end