From 2b75a53c9382f33d39555cdde454da8fbed749ae Mon Sep 17 00:00:00 2001 From: Lutz Wolf Date: Sat, 24 May 2014 23:46:26 +0200 Subject: [PATCH] Add basic rspec for portspec_to_portlist --- spec/lib/rex/socket_spec.rb | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/spec/lib/rex/socket_spec.rb b/spec/lib/rex/socket_spec.rb index 41c1abde79..3bc99de1bc 100644 --- a/spec/lib/rex/socket_spec.rb +++ b/spec/lib/rex/socket_spec.rb @@ -163,4 +163,35 @@ describe Rex::Socket do end end + + describe '.portspec_to_portlist' do + + portspec = '-1,0-10,!2-5,!7,65530-,65536' + context "'#{portspec}'" do + + subject { described_class.portspec_to_portlist portspec } + + it { should be_a(Array) } + + not_included = [] + not_included << -1 + not_included << 65536 + not_included.concat (2..5).to_a + not_included << 7 + not_included.each do |item| + it { should_not include item } + end + + included = [] + included << -1 + included.concat (0..10).to_a + included.concat (65530..65535).to_a + included << 65536 + included = included - not_included + included.each do |item| + it { should include item } + end + end + end + end