Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/spec/lib/rex/proto/dns/upstream_rule_spec.rb
Views: 11789
# -*- coding:binary -*-1require 'spec_helper'2require 'rex/text'34RSpec.describe Rex::Proto::DNS::UpstreamRule do5describe '.spell_check_resolver' do6it 'returns nil for IPv4 addresses' do7address = Rex::Socket.addr_ntoa(Random.new.bytes(4))8expect(described_class.spell_check_resolver(address)).to be_nil9end1011it 'returns nil for IPv6 addresses' do12address = Rex::Socket.addr_ntoa(Random.new.bytes(16))13expect(described_class.spell_check_resolver(address)).to be_nil14end1516it 'returns nil for "black-hole"' do17expect(described_class.spell_check_resolver('black-hole')).to be_nil18end1920it 'returns a populated array for "blackhole"' do21suggestions = described_class.spell_check_resolver('blackhole')22expect(suggestions).to be_a Array23expect(suggestions.first).to eq 'black-hole'24end25end2627describe '.valid_resolver?' do28it 'returns true for "black-hole"' do29expect(described_class.valid_resolver?('black-hole')).to be_truthy30expect(described_class.valid_resolver?('Black-Hole')).to be_truthy31expect(described_class.valid_resolver?(%s[black-hole])).to be_truthy32end3334it 'returns true for IPv4 addresses' do35address = Rex::Socket.addr_ntoa(Random.new.bytes(4))36expect(described_class.valid_resolver?(address)).to be_truthy37end3839it 'returns true for IPv6 addresses' do40address = Rex::Socket.addr_ntoa(Random.new.bytes(16))41expect(described_class.valid_resolver?(address)).to be_truthy42end4344it 'returns true for "static"' do45expect(described_class.valid_resolver?('static')).to be_truthy46expect(described_class.valid_resolver?('Static')).to be_truthy47expect(described_class.valid_resolver?(:static)).to be_truthy48end4950it 'returns true for "system"' do51expect(described_class.valid_resolver?('system')).to be_truthy52expect(described_class.valid_resolver?('System')).to be_truthy53expect(described_class.valid_resolver?(:system)).to be_truthy54end5556it 'raises returns false for invalid resolvers' do57expect(described_class.valid_resolver?('fake')).to be_falsey58end59end6061context 'when using a wildcard condition' do62let(:subject) { described_class.new(wildcard: '*.metasploit.com') }6364describe '#matches_all?' do65it 'does not return true for everything' do66expect(subject.matches_all?).to be_falsey67end68end6970describe '#matches_name?' do71it 'returns true for subdomains' do72expect(subject.matches_name?('www.metasploit.com')).to be_truthy73end7475it 'returns true for subsubdomains' do76expect(subject.matches_name?('one.two.metasploit.com')).to be_truthy77end7879it 'returns false for the domain' do80expect(subject.matches_name?('metasploit.com')).to be_falsey81end828384it 'returns false for other domains' do85expect(subject.matches_name?('notmetasploit.com')).to be_falsey86end87end88end8990context 'when not using a wildcard condition' do91let(:subject) { described_class.new }9293describe '#wildcard' do94it 'defaults to *' do95expect(subject.wildcard).to eq '*'96end97end9899describe '#matches_all?' do100it 'returns true for everything' do101expect(subject.matches_all?).to be_truthy102end103end104105describe '#matches_name?' do106it 'returns true for everything' do107expect(subject.matches_name?("#{Rex::Text.rand_text_alphanumeric(10)}.#{Rex::Text.rand_text_alphanumeric(3)}")).to be_truthy108end109end110end111end112113114