Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ group :development, :test do
# auto-load factories from spec/factories
gem 'factory_bot_rails'

gem 'rails', '~> 7.0'
# Enforce tests to run on 7.0.X
gem 'rails', '~> 7.0.0'
gem 'net-smtp', require: false

# Used to create fake data
Expand Down
14 changes: 11 additions & 3 deletions app/models/mdm/payload.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,18 @@ class Mdm::Payload < ApplicationRecord

#
# Serializations
#

serialize :urls
serialize :build_opts
if ActiveRecord::VERSION::MAJOR >= 7 && ActiveRecord::VERSION::MINOR >= 1
serialize :urls, coder: YAML
else
serialize :urls
end
Comment on lines +96 to +100
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since specifying coder: is a noop, and the old code didn't specify any coder, this if/else statementi s kind of redundant, I did add in an explicit serialize :urls, YAML but that broke the tests and it makes more sense to keep the old functionality the same as it was before
I don't mind keeping it here, since it makes it obvious what the intention is


if ActiveRecord::VERSION::MAJOR >= 7 && ActiveRecord::VERSION::MINOR >= 1
serialize :build_opts, coder: YAML
else
serialize :build_opts
end

public

Expand Down
12 changes: 10 additions & 2 deletions db/migrate/20110317144932_add_session_table.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
class AddSessionTable < ActiveRecord::Migration[4.2]

class Event < ApplicationRecord
serialize :info
if ActiveRecord::VERSION::MAJOR >= 7 && ActiveRecord::VERSION::MINOR >= 1
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we're tab indented here for some reason, ignore the formatting it looks normal in the IDE, file was orinigally tabs so not going to change that

serialize :info, coder: YAML
else
serialize :info
end
end

class SessionEvent < ApplicationRecord
Expand All @@ -10,7 +14,11 @@ class SessionEvent < ApplicationRecord

class Session < ApplicationRecord
has_many :events, :class_name => 'AddSessionTable::SessionEvent'
serialize :datastore
if ActiveRecord::VERSION::MAJOR >= 7 && ActiveRecord::VERSION::MINOR >= 1
serialize :datastore, coder: YAML
else
serialize :datastore
end
end

def self.up
Expand Down
12 changes: 10 additions & 2 deletions db/migrate/20110422000000_convert_binary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,19 @@ class ConvertBinary < ActiveRecord::Migration[4.2]


class WebPage < ApplicationRecord
serialize :headers
if ActiveRecord::VERSION::MAJOR >= 7 && ActiveRecord::VERSION::MINOR >= 1
serialize :headers, coder: YAML
else
serialize :headers
end
end

class WebVuln < ApplicationRecord
serialize :params
if ActiveRecord::VERSION::MAJOR >= 7 && ActiveRecord::VERSION::MINOR >= 1
serialize :params, coder: YAML
else
serialize :params
end
end

def bfilter(str)
Expand Down
45 changes: 45 additions & 0 deletions spec/app/models/mdm/payload_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
RSpec.describe Mdm::Payload, type: :model do
it_should_behave_like 'Metasploit::Concern.run'

context 'factory' do
it 'should be valid' do
mdm_payload = FactoryBot.build(:mdm_payload)
expect(mdm_payload).to be_valid
end
end

context 'database' do

context 'timestamps'do
it { is_expected.to have_db_column(:created_at).of_type(:datetime) }
it { is_expected.to have_db_column(:updated_at).of_type(:datetime) }
end

context 'columns' do
it { is_expected.to have_db_column(:name).of_type(:string) }
it { is_expected.to have_db_column(:uuid).of_type(:string) }
it { is_expected.to have_db_column(:uuid_mask).of_type(:integer) }
it { is_expected.to have_db_column(:timestamp).of_type(:integer) }
it { is_expected.to have_db_column(:arch).of_type(:string) }
it { is_expected.to have_db_column(:platform).of_type(:string) }
it { is_expected.to have_db_column(:urls).of_type(:string) }
it { is_expected.to have_db_column(:description).of_type(:string) }
it { is_expected.to have_db_column(:raw_payload).of_type(:string) }
it { is_expected.to have_db_column(:raw_payload_hash).of_type(:string) }
it { is_expected.to have_db_column(:build_status).of_type(:string) }
it { is_expected.to have_db_column(:build_opts).of_type(:string) }
end
end

context '#destroy' do
it 'should successfully destroy the object' do
payload = FactoryBot.create(:mdm_payload)
expect {
payload.destroy
}.to_not raise_error
expect {
payload.reload
}.to raise_error(ActiveRecord::RecordNotFound)
end
end
end
3 changes: 2 additions & 1 deletion spec/dummy/config/application.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require File.expand_path('../boot', __FILE__)

require "logger"
require "active_support"
require 'rails/all'

Bundler.require(*Rails.groups)
Expand Down
7 changes: 7 additions & 0 deletions spec/factories/mdm/payloads.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FactoryBot.define do
factory :mdm_payload, :aliases => [:payload], :class => Mdm::Payload do
#
# Associations
#
end
end
Loading