From 17a2aab4c00c19fcb5c3aa62a01b4dbb758e5f2a Mon Sep 17 00:00:00 2001 From: Dean Welch Date: Tue, 13 Feb 2024 18:26:04 +0000 Subject: [PATCH] Add tests for grouped options and remove unnecessary ENV check for datastore fallbacks --- .github/workflows/verify.yml | 3 - .../msf/base/serializer/readable_text_spec.rb | 80 +++++++++++++++++++ 2 files changed, 80 insertions(+), 3 deletions(-) diff --git a/.github/workflows/verify.yml b/.github/workflows/verify.yml index d05f3130215ab..7109422a1c6ab 100644 --- a/.github/workflows/verify.yml +++ b/.github/workflows/verify.yml @@ -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' diff --git a/spec/lib/msf/base/serializer/readable_text_spec.rb b/spec/lib/msf/base/serializer/readable_text_spec.rb index ad6a165a42298..b24a6a9830c15 100644 --- a/spec/lib/msf/base/serializer/readable_text_spec.rb +++ b/spec/lib/msf/base/serializer/readable_text_spec.rb @@ -182,6 +182,86 @@ 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' do