File tree Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -161,7 +161,16 @@ def initialize_metasploit_data_models
161
161
'db' ,
162
162
'migrate'
163
163
)
164
- ActiveRecord ::Migrator . migrations_paths << metasploit_data_model_migrations_pathname . to_s
164
+ metasploit_data_model_migrations_path = metasploit_data_model_migrations_pathname . to_s
165
+
166
+ # Since ActiveRecord::Migrator.migrations_paths can persist between
167
+ # instances of Msf::DBManager, such as in specs,
168
+ # metasploit_data_models_migrations_path may already be part of
169
+ # migrations_paths, in which case it should not be added or multiple
170
+ # migrations with the same version number errors will occur.
171
+ unless ActiveRecord ::Migrator . migrations_paths . include? metasploit_data_model_migrations_path
172
+ ActiveRecord ::Migrator . migrations_paths << metasploit_data_model_migrations_path
173
+ end
165
174
end
166
175
167
176
#
Original file line number Diff line number Diff line change 21
21
it_should_behave_like 'Msf::DBManager::Migration'
22
22
it_should_behave_like 'Msf::DBManager::ImportMsfXml'
23
23
24
+ context '#initialize_metasploit_data_models' do
25
+ def initialize_metasploit_data_models
26
+ db_manager . initialize_metasploit_data_models
27
+ end
28
+
29
+ it 'should not add duplicate paths to ActiveRecord::Migrator.migrations_paths' do
30
+ initialize_metasploit_data_models
31
+
32
+ expect {
33
+ initialize_metasploit_data_models
34
+ } . to_not change {
35
+ ActiveRecord ::Migrator . migrations_paths . length
36
+ }
37
+
38
+ ActiveRecord ::Migrator . migrations_paths . uniq . should == ActiveRecord ::Migrator . migrations_paths
39
+ end
40
+ end
41
+
24
42
context '#purge_all_module_details' do
25
43
def purge_all_module_details
26
44
db_manager . purge_all_module_details
You can’t perform that action at this time.
0 commit comments