From 752717301e6f342ff9f835c52496d22ae3fdb3b6 Mon Sep 17 00:00:00 2001 From: zinduolis Date: Mon, 4 Nov 2024 15:56:25 +1000 Subject: [PATCH] Upgrade activerecord to 7.2 and refactor code for new version --- Gemfile | 2 +- Gemfile.lock | 37 ++++++++++--------- beef | 5 ++- .../autorun_engine/autorun_engine_spec.rb | 4 +- .../handlers/browser_details_handler_spec.rb | 6 ++- spec/beef/extensions/requester_spec.rb | 4 +- .../websocket_hooked_browser_spec.rb | 6 ++- .../modules/debug/test_beef_debugs_spec.rb | 5 ++- spec/spec_helper.rb | 9 +++-- 9 files changed, 44 insertions(+), 34 deletions(-) diff --git a/Gemfile b/Gemfile index 2de308bd8b..36dd65f506 100644 --- a/Gemfile +++ b/Gemfile @@ -21,7 +21,7 @@ gem 'term-ansicolor', :require => 'term/ansicolor' gem 'rubyzip', '~> 2.3' gem 'espeak-ruby', '~> 1.1.0' # Text-to-Voice gem 'rake', '~> 13.2' -gem 'activerecord', '~> 7.0' +gem 'activerecord', '~> 7.2' gem 'otr-activerecord', '~> 2.4.0' gem 'sqlite3', '~> 1.4' gem 'rubocop', '~> 1.68.0', require: false diff --git a/Gemfile.lock b/Gemfile.lock index 6b6b4f3cf6..8de3140674 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,22 +1,24 @@ GEM remote: https://rubygems.org/ specs: - activemodel (7.1.4.2) - activesupport (= 7.1.4.2) - activerecord (7.1.4.2) - activemodel (= 7.1.4.2) - activesupport (= 7.1.4.2) + activemodel (7.2.2) + activesupport (= 7.2.2) + activerecord (7.2.2) + activemodel (= 7.2.2) + activesupport (= 7.2.2) timeout (>= 0.4.0) - activesupport (7.1.4.2) + activesupport (7.2.2) base64 + benchmark (>= 0.3) bigdecimal - concurrent-ruby (~> 1.0, >= 1.0.2) + concurrent-ruby (~> 1.0, >= 1.3.1) connection_pool (>= 2.2.5) drb i18n (>= 1.6, < 2) + logger (>= 1.4.2) minitest (>= 5.1) - mutex_m - tzinfo (~> 2.0) + securerandom (>= 0.3) + tzinfo (~> 2.0, >= 2.0.5) addressable (2.8.7) public_suffix (>= 2.0.2, < 7.0) ansi (1.5.0) @@ -32,6 +34,7 @@ GEM async-io (1.43.2) async base64 (0.2.0) + benchmark (0.3.0) bigdecimal (3.1.8) browserstack-local (1.4.3) byebug (11.1.3) @@ -102,13 +105,12 @@ GEM msgpack (1.7.3) mustermann (3.0.3) ruby2_keywords (~> 0.0.1) - mutex_m (0.2.0) net-protocol (0.2.2) timeout net-smtp (0.5.0) net-protocol netrc (0.11.0) - nio4r (2.7.3) + nio4r (2.7.4) nokogiri (1.16.7-aarch64-linux) racc (~> 1.4) nokogiri (1.16.7-arm-linux) @@ -126,7 +128,7 @@ GEM hashie-forbidden_attributes (~> 0.1) parallel (1.26.3) parseconfig (1.1.2) - parser (3.3.5.0) + parser (3.3.5.1) ast (~> 2.4.1) racc power_assert (2.0.4) @@ -168,7 +170,7 @@ GEM rspec-core (~> 3.13.0) rspec-expectations (~> 3.13.0) rspec-mocks (~> 3.13.0) - rspec-core (3.13.1) + rspec-core (3.13.2) rspec-support (~> 3.13.0) rspec-expectations (3.13.3) diff-lcs (>= 1.2.0, < 2.0) @@ -187,7 +189,7 @@ GEM rubocop-ast (>= 1.32.2, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 2.4.0, < 3.0) - rubocop-ast (1.33.0) + rubocop-ast (1.33.1) parser (>= 3.3.1.0) ruby-progressbar (1.13.0) ruby2_keywords (0.0.5) @@ -195,6 +197,7 @@ GEM rushover (0.3.0) json rest-client + securerandom (0.3.1) selenium-webdriver (4.26.0) base64 (~> 0.2) logger (~> 1.4) @@ -241,7 +244,7 @@ GEM tilt (2.4.0) timeout (0.4.1) timers (4.3.5) - tins (1.35.0) + tins (1.37.0) bigdecimal sync tzinfo (2.0.6) @@ -249,7 +252,7 @@ GEM uglifier (4.2.1) execjs (>= 0.3.0, < 3) unicode-display_width (2.6.0) - webrick (1.8.2) + webrick (1.9.0) websocket (1.2.11) websocket-client-simple (0.6.1) event_emitter @@ -268,7 +271,7 @@ PLATFORMS x86_64-linux DEPENDENCIES - activerecord (~> 7.0) + activerecord (~> 7.2) ansi (~> 1.5) async (~> 1.32) async-dns (~> 1.3) diff --git a/beef b/beef index 7d8dd55b94..1341279270 100755 --- a/beef +++ b/beef @@ -194,7 +194,6 @@ end # Connect to DB ActiveRecord::Base.logger = nil -OTR::ActiveRecord.migrations_paths = [File.join('core', 'main', 'ar-migrations')] OTR::ActiveRecord.configure_from_hash!(adapter:'sqlite3', database:db_file) # otr-activerecord require you to manually establish the connection with the following line #Also a check to confirm that the correct Gem version is installed to require it, likely easier for old systems. @@ -204,10 +203,12 @@ end # Migrate (if required) ActiveRecord::Migration.verbose = false # silence activerecord migration stdout messages -context = ActiveRecord::Migration.new.migration_context +ActiveRecord::Migrator.migrations_paths = [File.join('core', 'main', 'ar-migrations')] +context = ActiveRecord::MigrationContext.new(ActiveRecord::Migrator.migrations_paths) if context.needs_migration? ActiveRecord::Migrator.new(:up, context.migrations, context.schema_migration, context.internal_metadata).migrate end + # # @note Extensions may take a moment to load, thus we print out a please wait message # diff --git a/spec/beef/core/main/autorun_engine/autorun_engine_spec.rb b/spec/beef/core/main/autorun_engine/autorun_engine_spec.rb index f5b621c8c0..38ba96a625 100644 --- a/spec/beef/core/main/autorun_engine/autorun_engine_spec.rb +++ b/spec/beef/core/main/autorun_engine/autorun_engine_spec.rb @@ -42,14 +42,14 @@ # Load up DB and migrate if necessary ActiveRecord::Base.logger = nil - OTR::ActiveRecord.migrations_paths = [File.join('core', 'main', 'ar-migrations')] OTR::ActiveRecord.configure_from_hash!(adapter: 'sqlite3', database: db_file) # otr-activerecord require you to manually establish the connection with the following line #Also a check to confirm that the correct Gem version is installed to require it, likely easier for old systems. if Gem.loaded_specs['otr-activerecord'].version > Gem::Version.create('1.4.2') OTR::ActiveRecord.establish_connection! end - context = ActiveRecord::Migration.new.migration_context + ActiveRecord::Migrator.migrations_paths = [File.join('core', 'main', 'ar-migrations')] + context = ActiveRecord::MigrationContext.new(ActiveRecord::Migrator.migrations_paths) ActiveRecord::Migrator.new(:up, context.migrations, context.schema_migration, context.internal_metadata).migrate if context.needs_migration? BeEF::Core::Migration.instance.update_db! diff --git a/spec/beef/core/main/handlers/browser_details_handler_spec.rb b/spec/beef/core/main/handlers/browser_details_handler_spec.rb index f47deec091..943f53f06f 100644 --- a/spec/beef/core/main/handlers/browser_details_handler_spec.rb +++ b/spec/beef/core/main/handlers/browser_details_handler_spec.rb @@ -41,7 +41,6 @@ # Load up DB and migrate if necessary ActiveRecord::Base.logger = nil - OTR::ActiveRecord.migrations_paths = [File.join('core', 'main', 'ar-migrations')] OTR::ActiveRecord.configure_from_hash!(adapter: 'sqlite3', database: db_file) # otr-activerecord require you to manually establish the connection with the following line #Also a check to confirm that the correct Gem version is installed to require it, likely easier for old systems. @@ -49,8 +48,11 @@ OTR::ActiveRecord.establish_connection! end - context = ActiveRecord::Migration.new.migration_context + # Migrate (if required) + ActiveRecord::Migrator.migrations_paths = [File.join('core', 'main', 'ar-migrations')] + context = ActiveRecord::MigrationContext.new(ActiveRecord::Migrator.migrations_paths) ActiveRecord::Migrator.new(:up, context.migrations, context.schema_migration, context.internal_metadata).migrate if context.needs_migration? + BeEF::Core::Migration.instance.update_db! # Spawn HTTP Server diff --git a/spec/beef/extensions/requester_spec.rb b/spec/beef/extensions/requester_spec.rb index 4f4d7e929f..6522247745 100644 --- a/spec/beef/extensions/requester_spec.rb +++ b/spec/beef/extensions/requester_spec.rb @@ -34,12 +34,12 @@ # Connect to DB ActiveRecord::Base.logger = nil - OTR::ActiveRecord.migrations_paths = [File.join('core', 'main', 'ar-migrations')] OTR::ActiveRecord.configure_from_hash!(adapter: 'sqlite3', database: 'beef.db') OTR::ActiveRecord.establish_connection! if Gem.loaded_specs['otr-activerecord'].version > Gem::Version.create('1.4.2') # Migrate if required - context = ActiveRecord::Migration.new.migration_context + ActiveRecord::Migrator.migrations_paths = [File.join('core', 'main', 'ar-migrations')] + context = ActiveRecord::MigrationContext.new(ActiveRecord::Migrator.migrations_paths) ActiveRecord::Migrator.new(:up, context.migrations, context.schema_migration, context.internal_metadata).migrate if context.needs_migration? # Start HTTP hook server diff --git a/spec/beef/extensions/websocket_hooked_browser_spec.rb b/spec/beef/extensions/websocket_hooked_browser_spec.rb index 7abd8d97c7..59354befc6 100644 --- a/spec/beef/extensions/websocket_hooked_browser_spec.rb +++ b/spec/beef/extensions/websocket_hooked_browser_spec.rb @@ -41,15 +41,17 @@ end # Load up DB and migrate if necessary ActiveRecord::Base.logger = nil - OTR::ActiveRecord.migrations_paths = [File.join('core', 'main', 'ar-migrations')] OTR::ActiveRecord.configure_from_hash!(adapter: 'sqlite3', database: db_file) # otr-activerecord require you to manually establish the connection with the following line #Also a check to confirm that the correct Gem version is installed to require it, likely easier for old systems. if Gem.loaded_specs['otr-activerecord'].version > Gem::Version.create('1.4.2') OTR::ActiveRecord.establish_connection! end - context = ActiveRecord::Migration.new.migration_context + + ActiveRecord::Migrator.migrations_paths = [File.join('core', 'main', 'ar-migrations')] + context = ActiveRecord::MigrationContext.new(ActiveRecord::Migrator.migrations_paths) ActiveRecord::Migrator.new(:up, context.migrations, context.schema_migration, context.internal_metadata).migrate if context.needs_migration? + BeEF::Core::Migration.instance.update_db! # Spawn HTTP Server print_info 'Starting HTTP Hook Server' diff --git a/spec/beef/modules/debug/test_beef_debugs_spec.rb b/spec/beef/modules/debug/test_beef_debugs_spec.rb index 1912d331c0..c67ffc5839 100644 --- a/spec/beef/modules/debug/test_beef_debugs_spec.rb +++ b/spec/beef/modules/debug/test_beef_debugs_spec.rb @@ -39,14 +39,15 @@ # Load up DB and migrate if necessary ActiveRecord::Base.logger = nil - OTR::ActiveRecord.migrations_paths = [File.join('core', 'main', 'ar-migrations')] OTR::ActiveRecord.configure_from_hash!(adapter: 'sqlite3', database: db_file) # otr-activerecord require you to manually establish the connection with the following line #Also a check to confirm that the correct Gem version is installed to require it, likely easier for old systems. if Gem.loaded_specs['otr-activerecord'].version > Gem::Version.create('1.4.2') OTR::ActiveRecord.establish_connection! end - context = ActiveRecord::Migration.new.migration_context + + ActiveRecord::Migrator.migrations_paths = [File.join('core', 'main', 'ar-migrations')] + context = ActiveRecord::MigrationContext.new(ActiveRecord::Migrator.migrations_paths) ActiveRecord::Migrator.new(:up, context.migrations, context.schema_migration, context.internal_metadata).migrate if context.needs_migration? BeEF::Core::Migration.instance.update_db! diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 750a638672..56e3edf462 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -50,7 +50,6 @@ def reset! ## DB config ActiveRecord::Base.logger = nil -OTR::ActiveRecord.migrations_paths = [File.join('core', 'main', 'ar-migrations')] OTR::ActiveRecord.configure_from_hash!(adapter: 'sqlite3', database: ':memory:') # otr-activerecord requires manually establishing the connection with the following line @@ -62,7 +61,8 @@ def reset! # Migrate (if required) ActiveRecord::Migration.verbose = false # silence activerecord migration stdout messages -context = ActiveRecord::Migration.new.migration_context +ActiveRecord::Migrator.migrations_paths = [File.join('core', 'main', 'ar-migrations')] +context = ActiveRecord::MigrationContext.new(ActiveRecord::Migrator.migrations_paths) if context.needs_migration? ActiveRecord::Migrator.new(:up, context.migrations, context.schema_migration, context.internal_metadata).migrate end @@ -160,7 +160,6 @@ def start_beef_server # Load up DB and migrate if necessary ActiveRecord::Base.logger = nil - OTR::ActiveRecord.migrations_paths = [File.join('core', 'main', 'ar-migrations')] OTR::ActiveRecord.configure_from_hash!(adapter:'sqlite3', database: db_file) # otr-activerecord require you to manually establish the connection with the following line #Also a check to confirm that the correct Gem version is installed to require it, likely easier for old systems. @@ -170,10 +169,12 @@ def start_beef_server # Migrate (if required) ActiveRecord::Migration.verbose = false # silence activerecord migration stdout messages - context = ActiveRecord::Migration.new.migration_context + ActiveRecord::Migrator.migrations_paths = [File.join('core', 'main', 'ar-migrations')] + context = ActiveRecord::MigrationContext.new(ActiveRecord::Migrator.migrations_paths) if context.needs_migration? ActiveRecord::Migrator.new(:up, context.migrations, context.schema_migration, context.internal_metadata).migrate end + BeEF::Core::Migration.instance.update_db! # Spawn HTTP Server