|
1 | 1 | # -*- coding:binary -*-
|
2 | 2 | require 'rex/socket/range_walker'
|
| 3 | +require 'spec_helper' |
3 | 4 |
|
4 | 5 | describe Rex::Socket do
|
5 | 6 |
|
|
166 | 167 |
|
167 | 168 | describe '.portspec_to_portlist' do
|
168 | 169 |
|
169 |
| - portspec = '-1,0-10,!2-5,!7,65530-,65536' |
170 |
| - context "'#{portspec}'" do |
| 170 | + subject(:portlist) { described_class.portspec_to_portlist portspec_string} |
| 171 | + let(:portspec_string) { '-1,0-10,!2-5,!7,65530-,65536' } |
171 | 172 |
|
172 |
| - subject { described_class.portspec_to_portlist portspec } |
| 173 | + it 'does not include negative numbers' do |
| 174 | + expect(portlist).to_not include '-1' |
| 175 | + end |
173 | 176 |
|
174 |
| - it { should be_a(Array) } |
| 177 | + it 'does not include 0' do |
| 178 | + expect(portlist).to_not include '0' |
| 179 | + end |
175 | 180 |
|
176 |
| - not_included = [] |
177 |
| - not_included << -1 |
178 |
| - not_included << 65536 |
179 |
| - not_included.concat (2..5).to_a |
180 |
| - not_included << 7 |
181 |
| - not_included.each do |item| |
182 |
| - it { should_not include item } |
| 181 | + it 'does not include negated numbers' do |
| 182 | + ['2', '3', '4', '5', '7'].each do |port| |
| 183 | + expect(portlist).to_not include port |
183 | 184 | end
|
| 185 | + end |
| 186 | + |
| 187 | + it 'does not include any numbers above 65535' do |
| 188 | + expect(portlist).to_not include '65536' |
| 189 | + end |
184 | 190 |
|
185 |
| - included = [] |
186 |
| - included << -1 |
187 |
| - included.concat (0..10).to_a |
188 |
| - included.concat (65530..65535).to_a |
189 |
| - included << 65536 |
190 |
| - included = included - not_included |
191 |
| - included.each do |item| |
192 |
| - it { should include item } |
| 191 | + it 'expands open ended ranges' do |
| 192 | + (65530..65535).each do |port| |
| 193 | + expect(portlist).to include port |
193 | 194 | end
|
194 | 195 | end
|
195 | 196 | end
|
|
0 commit comments