Skip to content

Commit

Permalink
Add tests for grouped options and remove unnecessary ENV check for da…
Browse files Browse the repository at this point in the history
…tastore fallbacks
  • Loading branch information
dwelch-r7 committed Feb 15, 2024
1 parent 88f9283 commit 9a4b8b9
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 8 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,6 @@ jobs:
exclude:
- { os: ubuntu-latest, ruby: '3.0' }
include:
- os: ubuntu-latest
ruby: '3.1'
test_cmd: 'bundle exec rake rspec-rerun:spec SPEC_OPTS="--tag content" MSF_FEATURE_DATASTORE_FALLBACKS=1'
- os: ubuntu-latest
ruby: '3.1'
test_cmd: 'bundle exec rake rspec-rerun:spec SPEC_OPTS="--tag content" MSF_FEATURE_DEFER_MODULE_LOADS=1'
Expand Down
86 changes: 83 additions & 3 deletions spec/lib/msf/base/serializer/readable_text_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def initialize
allow(Rex::Text::Table).to receive(:wrapped_tables?).and_return(true)
end

describe '.dump_datastore', if: ENV['DATASTORE_FALLBACKS'] do
describe '.dump_datastore' do
context 'when the datastore is empty' do
it 'returns the datastore as a table' do
expect(described_class.dump_datastore('Table name', Msf::DataStore.new, indent_length)).to match_table <<~TABLE
Expand Down Expand Up @@ -144,7 +144,7 @@ def initialize
end
end

describe '.dump_options', if: ENV['DATASTORE_FALLBACKS'] do
describe '.dump_options' do
context 'when missing is false' do
it 'returns the options as a table' do
expect(described_class.dump_options(aux_mod_with_set_options, indent_string, false)).to match_table <<~TABLE
Expand Down Expand Up @@ -173,9 +173,89 @@ def initialize
TABLE
end
end

context 'when some options are grouped' do
let(:group_name) { 'group_name' }
let(:group_description) { 'Used for example reasons' }
let(:group) { Msf::OptionGroup.new(name: group_name, description: group_description) }
let(:aux_mod_with_grouped_options) do
mod = aux_mod_with_set_options.replicant
mod.options['RHOSTS'].group = group
mod.options['SMBUser'].group = group
mod.options['SMBDomain'].group = group
mod
end
it 'should return the grouped options separate to the rest of the options' do
expect(described_class.dump_options(aux_mod_with_grouped_options, indent_string, false)).to match_table <<~TABLE
Name Current Setting Required Description
---- --------------- -------- -----------
FloatValue 5 no A FloatValue
NewOptionName yes An option with a new name. Aliases ensure the old and new names are synchronized
OptionWithModuleDefault false yes option with module default
RPORT 3000 yes The target port
baz baz_from_module yes baz option
fizz new_fizz yes fizz option
foo foo_from_framework yes Foo option
#{group_description}:
Name Current Setting Required Description
---- --------------- -------- -----------
RHOSTS 192.0.2.2 yes The target host(s), see https://docs.metasploit.com/docs/using-metasploit/basics/using-metasploit.html
SMBDomain WORKGROUP yes The SMB username
SMBUser username yes The SMB username
TABLE
end
end

context 'when there are multiple options groups' do
let(:group_name_1) { 'group_name_1' }
let(:group_description_1) { 'Used for example reasons_1' }
let(:group_name_2) { 'group_name_2' }
let(:group_description_2) { 'Used for example reasons_2' }
let(:group_1) { Msf::OptionGroup.new(name: group_name_1, description: group_description_1) }
let(:group_2) { Msf::OptionGroup.new(name: group_name_2, description: group_description_2) }

let(:aux_mod_with_grouped_options) do
mod = aux_mod_with_set_options.replicant
mod.options['RHOSTS'].group = group_1
mod.options['SMBUser'].group = group_2
mod.options['SMBDomain'].group = group_2
mod
end
it 'should return the grouped options separate to the rest of the options' do
expect(described_class.dump_options(aux_mod_with_grouped_options, indent_string, false)).to match_table <<~TABLE
Name Current Setting Required Description
---- --------------- -------- -----------
FloatValue 5 no A FloatValue
NewOptionName yes An option with a new name. Aliases ensure the old and new names are synchronized
OptionWithModuleDefault false yes option with module default
RPORT 3000 yes The target port
baz baz_from_module yes baz option
fizz new_fizz yes fizz option
foo foo_from_framework yes Foo option
#{group_description_1}:
Name Current Setting Required Description
---- --------------- -------- -----------
RHOSTS 192.0.2.2 yes The target host(s), see https://docs.metasploit.com/docs/using-metasploit/basics/using-metasploit.html
#{group_description_2}:
Name Current Setting Required Description
---- --------------- -------- -----------
SMBDomain WORKGROUP yes The SMB username
SMBUser username yes The SMB username
TABLE
end
end
end

describe '.dump_advanced_options', if: ENV['DATASTORE_FALLBACKS'] do
describe '.dump_advanced_options' do
context 'when kerberos options are present' do
let(:advanced_module_options) do
[
Expand Down
4 changes: 2 additions & 2 deletions spec/lib/msf/ui/console/command_dispatcher/core_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def set_and_test_variable(name, framework_value, module_value, framework_re, mod
end
end

describe '#cmd_set', if: ENV['DATASTORE_FALLBACKS'] do
describe '#cmd_set' do
let(:mod) { nil }

before(:each) do
Expand Down Expand Up @@ -198,7 +198,7 @@ def initialize
end
end

describe '#cmd_unset', if: ENV['DATASTORE_FALLBACKS'] do
describe '#cmd_unset', if: ENV['MSF_FEATURE_DATASTORE_FALLBACKS'] do
let(:mod) { nil }

before(:each) do
Expand Down

0 comments on commit 9a4b8b9

Please sign in to comment.