-
Notifications
You must be signed in to change notification settings - Fork 14.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
165 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# -*- coding:binary -*- | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
RSpec.describe Msf::Module::Options do | ||
subject(:mod) do | ||
mod = ::Msf::Module.new | ||
mod.extend described_class | ||
mod | ||
end | ||
|
||
describe '#register_option_group' do | ||
let(:name) { 'name' } | ||
let(:description) { 'description' } | ||
let(:option_names) { %w[option1 option2] } | ||
|
||
context 'there are no registered option groups' do | ||
it 'registers a new option group' do | ||
subject.send(:register_option_group, name: name, description: description, option_names: option_names) | ||
expect(subject.options.groups.length).to eq(1) | ||
expect(subject.options.groups.keys).to include(name) | ||
end | ||
end | ||
|
||
context 'there is a registered option group' do | ||
let(:existing_name) { 'existing_name' } | ||
let(:existing_options) { ['existing_option_names'] } | ||
let(:existing_description) { 'existing_description' } | ||
before(:each) do | ||
subject.send(:register_option_group, name: existing_name, description: existing_description, option_names: existing_options) | ||
end | ||
|
||
it 'registers a an additional option group' do | ||
subject.send(:register_option_group, name: name, description: description, option_names: option_names) | ||
expect(subject.options.groups.length).to eq(2) | ||
expect(subject.options.groups.keys).to include(name, existing_name) | ||
end | ||
|
||
context 'when adding a group with the same name' do | ||
it 'merges the option groups together' do | ||
subject.send(:register_option_group, name: existing_name, description: description, option_names: option_names) | ||
expect(subject.options.groups.length).to eq(1) | ||
expect(subject.options.groups.keys).to include(existing_name) | ||
expect(subject.options.groups[existing_name].option_names).to include(*existing_options, *option_names) | ||
expect(subject.options.groups[existing_name].description).to eq(description) | ||
end | ||
|
||
it 'overwrites the existing option group' do | ||
subject.send(:register_option_group, name: existing_name, description: description, option_names: option_names, merge: false) | ||
expect(subject.options.groups.length).to eq(1) | ||
expect(subject.options.groups.keys).to include(existing_name) | ||
expect(subject.options.groups[existing_name].option_names).to include(*option_names) | ||
expect(subject.options.groups[existing_name].description).to eq(description) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# -*- coding:binary -*- | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
RSpec.describe Msf::OptionGroup do | ||
subject { described_class.new(name: 'name', description: 'description') } | ||
|
||
describe '#add_option' do | ||
let(:option_name) { 'option_name' } | ||
context 'when the option group is empty' do | ||
it 'adds the option' do | ||
subject.add_option(option_name) | ||
expect(subject.option_names.length).to eql(1) | ||
expect(subject.option_names).to include(option_name) | ||
end | ||
end | ||
|
||
context 'when the option group contains options' do | ||
subject { described_class.new(name: 'name', description: 'description', option_names: ['existing_option']) } | ||
|
||
it 'adds the option' do | ||
subject.add_option(option_name) | ||
expect(subject.option_names.length).to eql(2) | ||
expect(subject.option_names).to include(option_name) | ||
end | ||
end | ||
end | ||
|
||
describe '#add_options' do | ||
let(:option_names) { %w[option_name1 option_name2] } | ||
context 'when the option group is empty' do | ||
it 'adds the option' do | ||
subject.add_options(option_names) | ||
expect(subject.option_names.length).to eql(2) | ||
expect(subject.option_names).to include(*option_names) | ||
end | ||
end | ||
|
||
context 'when the option group contains options' do | ||
subject { described_class.new(name: 'name', description: 'description', option_names: ['existing_option']) } | ||
|
||
it 'adds the option' do | ||
subject.add_options(option_names) | ||
expect(subject.option_names.length).to eql(3) | ||
expect(subject.option_names).to include(*option_names) | ||
end | ||
end | ||
end | ||
end |