Skip to content

Commit

Permalink
add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
zgoldman-r7 committed Sep 11, 2023
1 parent 615aa8d commit a13d45e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/msf/core/opt_address_local.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class OptAddressLocal < OptAddress
def interfaces
begin
NetworkInterface.interfaces || []
rescue
rescue NetworkInterface::Error => e
elog(e)
[]
end
Expand Down
13 changes: 13 additions & 0 deletions spec/lib/msf/core/opt_address_local_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,17 @@
end
end
end
describe '#interfaces' do
context 'getting errors' do
before(:each) do
allow(NetworkInterface).to receive(:interfaces).and_raise(NetworkInterface::Error)
end

it 'rescues and returns an empty array' do
expect(required_opt).to receive(:elog).with(an_instance_of(NetworkInterface::Error))
result = required_opt.interfaces()
expect(result).to eq([])
end
end
end
end

0 comments on commit a13d45e

Please sign in to comment.