|
277 | 277 | end |
278 | 278 | end |
279 | 279 |
|
| 280 | + context 'with an IP CIDR' do |
| 281 | + let(:try) { '192.168.1.1/30' } |
| 282 | + it 'should return true' do |
| 283 | + expect(addr).to eq true |
| 284 | + end |
| 285 | + end |
| 286 | + |
280 | 287 | context 'with multiple IPv4 addresses' do |
281 | 288 | context 'separated by newlines' do |
282 | 289 | let(:try) { "127.0.0.1\n127.0.0.1" } |
|
377 | 384 | end |
378 | 385 | end |
379 | 386 |
|
| 387 | + context 'with an ip address range' do |
| 388 | + let(:try) { '192.168.1.1-4' } |
| 389 | + it 'should return false' do |
| 390 | + expect(name).to eq false |
| 391 | + end |
| 392 | + end |
| 393 | + |
| 394 | + context 'with an ip CIDR' do |
| 395 | + let(:try) { '192.168.1.1/24' } |
| 396 | + it 'should return false' do |
| 397 | + expect(name).to eq false |
| 398 | + end |
| 399 | + end |
| 400 | + |
380 | 401 | context 'with a hostname' do |
381 | 402 | let(:try) { "localhost" } |
382 | 403 | it "should return true" do |
|
529 | 550 | end |
530 | 551 | end |
531 | 552 | end |
| 553 | + |
| 554 | + describe '.is_ip_range?' do |
| 555 | + [ |
| 556 | + { input: '1.1.1.1 - 1.1.1.255', expected: true }, |
| 557 | + { input: '1.1.1.1- 1.1.1.255', expected: true }, |
| 558 | + { input: '1.1.1.1 -1.1.1.255', expected: true }, |
| 559 | + { input: '1.1.1.1-1.1.1.255', expected: true }, |
| 560 | + { input: ' 1.1.1.1 - 1.1.1.255 ', expected: true }, |
| 561 | + { input: '1.1.1.1 - 255', expected: true }, |
| 562 | + { input: '::1 - ::ffff', expected: true }, |
| 563 | + { input: '127.0.0.1-.5', expected: true }, |
| 564 | + { input: '127.0.0.1-5', expected: true }, |
| 565 | + { input: '127.0.0.1-1.5', expected: true }, |
| 566 | + { input: '127.0.0.1-.1.5', expected: true }, |
| 567 | + { input: '::1 - ::1', expected: true }, |
| 568 | + { input: '::ffff - ::ffff', expected: true }, |
| 569 | + { input: '1.1.1.1 - ::1', expected: false }, |
| 570 | + { input: '::1 - 1.1.1.1', expected: false }, |
| 571 | + { input: 'example-domain.com', expected: false }, |
| 572 | + { input: 'example-domain-name.com', expected: false }, |
| 573 | + { input: '127.0.0.1', expected: false }, |
| 574 | + { input: '::1', expected: false }, |
| 575 | + { input: '::ffff::ffff', expected: false }, |
| 576 | + { input: '::1-::ffffffff', expected: false }, |
| 577 | + { input: '::1-ffff', expected: false }, |
| 578 | + { input: '1-ffff', expected: false }, |
| 579 | + { input: '1-::ffff', expected: false }, |
| 580 | + { input: 'example-domain.com-example-subdomain.com', expected: false }, |
| 581 | + { input: 'example-domain.com-docs.rapid7.com', expected: false }, |
| 582 | + { input: 'example-domain.com-127.0.0.1', expected: false }, |
| 583 | + { input: '127.0.0.1-rapid7.com', expected: false }, |
| 584 | + { input: '1-rapid7.com', expected: false }, |
| 585 | + { input: '::1-rapid7.com::ffff', expected: false }, |
| 586 | + { input: '00:1A:2B:3C:4D:5E-00:A1:B2:C3:D4:E5', expected: false }, |
| 587 | + { input: '00:1A:2B:3C:4D:5E-00:A1:B2:C3:D4:E5', expected: false }, |
| 588 | + ].each do |test_case| |
| 589 | + it "should return #{test_case[:expected]} when given #{test_case[:input]}" do |
| 590 | + input = test_case[:input] |
| 591 | + expected = test_case[:expected] |
| 592 | + |
| 593 | + expect(described_class.is_ip_range?(input)).to eq(expected) |
| 594 | + end |
| 595 | + end |
| 596 | + end |
532 | 597 | end |
0 commit comments