Skip to content

Commit cb882a2

Browse files
committed
Add mdm::payload test and run tests under rails 7.1
1 parent f8c6f6e commit cb882a2

File tree

7 files changed

+80
-10
lines changed

7 files changed

+80
-10
lines changed

Gemfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ group :development, :test do
1919
# auto-load factories from spec/factories
2020
gem 'factory_bot_rails'
2121

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

2526
# Used to create fake data

app/models/mdm/payload.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,15 @@ class Mdm::Payload < ApplicationRecord
9494
# Serializations
9595

9696
if ActiveRecord::VERSION::MAJOR >= 7 && ActiveRecord::VERSION::MINOR >= 1
97-
serialize :urls, coder: ::YAML
97+
serialize :urls, coder: YAML
9898
else
99-
serialize :urls, ::YAML
99+
serialize :urls
100100
end
101101

102102
if ActiveRecord::VERSION::MAJOR >= 7 && ActiveRecord::VERSION::MINOR >= 1
103-
serialize :build_opts, coder: ::YAML
103+
serialize :build_opts, coder: YAML
104104
else
105-
serialize :build_opts, ::YAML
105+
serialize :build_opts
106106
end
107107

108108
public

db/migrate/20110317144932_add_session_table.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
class AddSessionTable < ActiveRecord::Migration[4.2]
22

33
class Event < ApplicationRecord
4-
serialize :info
4+
if ActiveRecord::VERSION::MAJOR >= 7 && ActiveRecord::VERSION::MINOR >= 1
5+
serialize :info, coder: YAML
6+
else
7+
serialize :info
8+
end
59
end
610

711
class SessionEvent < ApplicationRecord
@@ -10,7 +14,11 @@ class SessionEvent < ApplicationRecord
1014

1115
class Session < ApplicationRecord
1216
has_many :events, :class_name => 'AddSessionTable::SessionEvent'
13-
serialize :datastore
17+
if ActiveRecord::VERSION::MAJOR >= 7 && ActiveRecord::VERSION::MINOR >= 1
18+
serialize :datastore, coder: YAML
19+
else
20+
serialize :datastore
21+
end
1422
end
1523

1624
def self.up

db/migrate/20110422000000_convert_binary.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,19 @@ class ConvertBinary < ActiveRecord::Migration[4.2]
33

44

55
class WebPage < ApplicationRecord
6-
serialize :headers
6+
if ActiveRecord::VERSION::MAJOR >= 7 && ActiveRecord::VERSION::MINOR >= 1
7+
serialize :headers, coder: YAML
8+
else
9+
serialize :headers
10+
end
711
end
812

913
class WebVuln < ApplicationRecord
10-
serialize :params
14+
if ActiveRecord::VERSION::MAJOR >= 7 && ActiveRecord::VERSION::MINOR >= 1
15+
serialize :params, coder: YAML
16+
else
17+
serialize :params
18+
end
1119
end
1220

1321
def bfilter(str)
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
RSpec.describe Mdm::Payload, type: :model do
2+
it_should_behave_like 'Metasploit::Concern.run'
3+
4+
context 'factory' do
5+
it 'should be valid' do
6+
mdm_payload = FactoryBot.build(:mdm_payload)
7+
expect(mdm_payload).to be_valid
8+
end
9+
end
10+
11+
context 'database' do
12+
13+
context 'timestamps'do
14+
it { is_expected.to have_db_column(:created_at).of_type(:datetime) }
15+
it { is_expected.to have_db_column(:updated_at).of_type(:datetime) }
16+
end
17+
18+
context 'columns' do
19+
it { is_expected.to have_db_column(:name).of_type(:string) }
20+
it { is_expected.to have_db_column(:uuid).of_type(:string) }
21+
it { is_expected.to have_db_column(:uuid_mask).of_type(:integer) }
22+
it { is_expected.to have_db_column(:timestamp).of_type(:integer) }
23+
it { is_expected.to have_db_column(:arch).of_type(:string) }
24+
it { is_expected.to have_db_column(:platform).of_type(:string) }
25+
it { is_expected.to have_db_column(:urls).of_type(:string) }
26+
it { is_expected.to have_db_column(:description).of_type(:string) }
27+
it { is_expected.to have_db_column(:raw_payload).of_type(:string) }
28+
it { is_expected.to have_db_column(:raw_payload_hash).of_type(:string) }
29+
it { is_expected.to have_db_column(:build_status).of_type(:string) }
30+
it { is_expected.to have_db_column(:build_opts).of_type(:string) }
31+
end
32+
end
33+
34+
context '#destroy' do
35+
it 'should successfully destroy the object' do
36+
payload = FactoryBot.create(:mdm_payload)
37+
expect {
38+
payload.destroy
39+
}.to_not raise_error
40+
expect {
41+
payload.reload
42+
}.to raise_error(ActiveRecord::RecordNotFound)
43+
end
44+
end
45+
end

spec/dummy/config/application.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
require File.expand_path('../boot', __FILE__)
2-
2+
require "logger"
3+
require "active_support"
34
require 'rails/all'
45

56
Bundler.require(*Rails.groups)

spec/factories/mdm/payloads.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FactoryBot.define do
2+
factory :mdm_payload, :aliases => [:payload], :class => Mdm::Payload do
3+
#
4+
# Associations
5+
#
6+
end
7+
end

0 commit comments

Comments
 (0)