Detect leaked constants under Msf::Modules
MSP-11130 Detect constants leaked under Msf::Modules after the suite completes.bug/bundler_fix
parent
313c2407ad
commit
605f48e58d
|
@ -32,6 +32,10 @@ module Metasploit
|
|||
# works in compatible manner with activerecord's rake tasks and other
|
||||
# railties.
|
||||
module Framework
|
||||
extend ActiveSupport::Autoload
|
||||
|
||||
autoload :Spec
|
||||
|
||||
# Returns the root of the metasploit-framework project. Use in place of
|
||||
# `Rails.root`.
|
||||
#
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
module Metasploit::Framework::Spec
|
||||
extend ActiveSupport::Autoload
|
||||
|
||||
autoload :Constants
|
||||
end
|
|
@ -0,0 +1,43 @@
|
|||
require 'msf/core/modules'
|
||||
|
||||
# Monitor constants created by module loading to ensure that the loads in one example don't interfere with the
|
||||
# assertions in another example.
|
||||
module Metasploit::Framework::Spec::Constants
|
||||
# The parent namespace constant that can have children added when loading modules.
|
||||
PARENT_CONSTANT = Msf::Modules
|
||||
|
||||
# Configures after(:suite) callback for RSpec to check for leaked constants.
|
||||
def self.configure!
|
||||
unless @configured
|
||||
RSpec.configure do |config|
|
||||
config.after(:suite) do
|
||||
::Metasploit::Framework::Spec::Constants.each { |child_name|
|
||||
$stderr.puts "#{child_name} not removed from #{PARENT_CONSTANT}"
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
@configured = true
|
||||
end
|
||||
end
|
||||
|
||||
# Yields each constant under {PARENT_CONSTANT}.
|
||||
#
|
||||
# @yield [child_name]
|
||||
# @yieldparam child_name [String] name of constant relative to {PARENT_CONSTANT}.
|
||||
# @yieldreturn [void]
|
||||
# @return [Integer] count
|
||||
def self.each
|
||||
inherit = false
|
||||
count = 0
|
||||
|
||||
child_constant_names = PARENT_CONSTANT.constants(inherit)
|
||||
|
||||
child_constant_names.each do |child_constant_name|
|
||||
count += 1
|
||||
yield child_constant_name
|
||||
end
|
||||
|
||||
count
|
||||
end
|
||||
end
|
|
@ -53,3 +53,5 @@ RSpec.configure do |config|
|
|||
# instead of true.
|
||||
config.use_transactional_fixtures = true
|
||||
end
|
||||
|
||||
Metasploit::Framework::Spec::Constants.configure!
|
||||
|
|
Loading…
Reference in New Issue