Skip to content

Commit 6618c09

Browse files
committed
Merges 'bug/obsolete-activerecord-patch'
Not only does this remove the patch, but adds in specs to cover the test cases that the patch resolved. Verified all steps and landed rapid7#1592 before landing rapid7#1611, so this is complete. [Closes rapid7#1611]
2 parents d987693 + 2075a7b commit 6618c09

File tree

6 files changed

+263
-116
lines changed

6 files changed

+263
-116
lines changed

Rakefile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,19 @@ require 'bundler/setup'
22

33
require 'metasploit_data_models'
44

5+
pathname = Pathname.new(__FILE__)
6+
root = pathname.parent
7+
8+
# add metasploit-framework/lib to load paths so rake files can just require
9+
# files normally without having to use __FILE__ and recalculating root and the
10+
# path to lib
11+
lib_pathname = root.join('lib')
12+
$LOAD_PATH.unshift(lib_pathname.to_s)
13+
514
#
615
# load rake files like a rails engine
716
#
817

9-
pathname = Pathname.new(__FILE__)
10-
root = pathname.parent
1118
rakefile_glob = root.join('lib', 'tasks', '**', '*.rake').to_path
1219

1320
Dir.glob(rakefile_glob) do |rakefile|

lib/metasploit/framework.rb

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Top-level namespace that is shared between {Metasploit::Framework
2+
# metasploit-framework} and pro, which uses Metasploit::Pro.
3+
module Metasploit
4+
# Supports Rails and Rails::Engine like access to metasploit-framework so it
5+
# works in compatible manner with activerecord's rake tasks and other
6+
# railties.
7+
module Framework
8+
# Returns the environment for {Metasploit::Framework}. Checks
9+
# `METASPLOIT_FRAMEWORK_ENV` environment variable for value. Defaults to
10+
# `'development'` if `METASPLOIT_FRAMEWORK_ENV` is not set in the
11+
# environment variables.
12+
#
13+
# {env} is a ActiveSupport::StringInquirer like `Rails.env` so it can be
14+
# queried for its value.
15+
#
16+
# @example check if environment is development
17+
# if Metasploit::Framework.env.development?
18+
# # runs only when in development
19+
# end
20+
#
21+
# @return [ActiveSupport::StringInquirer] the environment name
22+
def self.env
23+
unless instance_variable_defined? :@env
24+
name = ENV['METASPLOIT_FRAMEWORK_ENV']
25+
name ||= 'development'
26+
@env = ActiveSupport::StringInquirer.new(name)
27+
end
28+
29+
@env
30+
end
31+
32+
# Returns the root of the metasploit-framework project. Use in place of
33+
# `Rails.root`.
34+
#
35+
# @return [Pathname]
36+
def self.root
37+
unless instance_variable_defined? :@root
38+
pathname = Pathname.new(__FILE__)
39+
@root = pathname.parent.parent.parent
40+
end
41+
42+
@root
43+
end
44+
end
45+
end

lib/msf/core/db_manager.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,6 @@ def initialize_database_support
9292

9393
initialize_metasploit_data_models
9494

95-
# Patches issues with ActiveRecord
96-
require "msf/core/patches/active_record"
97-
9895
@usable = true
9996

10097
rescue ::Exception => e

lib/msf/core/patches/active_record.rb

Lines changed: 0 additions & 88 deletions
This file was deleted.

lib/tasks/database.rake

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,6 @@
11
load 'active_record/railties/databases.rake'
22

3-
module Metasploit
4-
module Framework
5-
def self.env
6-
unless instance_variable_defined? :@env
7-
name = ENV['METASPLOIT_FRAMEWORK_ENV']
8-
name ||= 'development'
9-
@env = ActiveSupport::StringInquirer.new(name)
10-
end
11-
12-
@env
13-
end
14-
15-
def self.root
16-
unless instance_variable_defined? :@root
17-
pathname = Pathname.new(__FILE__)
18-
@root = pathname.parent.parent.parent
19-
end
20-
21-
@root
22-
end
23-
end
24-
end
25-
3+
require 'metasploit/framework'
264

275
# A modification to remove dependency on Rails.env
286
#

0 commit comments

Comments
 (0)