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/static_hostnames_spec.rb
Views: 11789
# -*- coding:binary -*-1require 'dnsruby'2require 'spec_helper'34RSpec.describe Rex::Proto::DNS::StaticHostnames do5describe '#parse_hosts_file' do6context 'when parsing a file' do7let(:subject) { described_class.new }8let(:hosts_file) {9<<~CONTENT10# this is a comment1112127.0.0.1 localhost localhost413::1 localhost localhost614127.1.1.1 localhost15thisIsInvalid16CONTENT17}1819before(:each) do20expect(File).to receive(:file?).and_return(true)21expect(File).to receive(:readable?).and_return(true)22expect(::IO).to receive(:foreach) do |_, &block|23hosts_file.split("\n").each do |line|24block.call(line)25end26end27subject.parse_hosts_file28end2930it 'is not empty' do31expect(subject.empty?).to be_falsey32end3334context 'when no type is specified' do35it 'returns an IPv4 address' do36expect(subject.get('localhost')).to eq ['127.0.0.1', '127.1.1.1']37end38end3940it 'defines an IPv4 address for localhost' do41expect(subject.get('localhost', Dnsruby::Types::A)).to eq ['127.0.0.1', '127.1.1.1']42end4344it 'defines an IPv6 address for localhost' do45expect(subject.get('localhost', Dnsruby::Types::AAAA)).to eq ['::1']46end47end48end4950context 'when no hosts are defined' do51let(:subject) { described_class.new }5253describe '#empty?' do54it 'is true' do55expect(subject.empty?).to be_truthy56end57end5859describe '#get' do60it 'returns an empty array' do61expect(subject.get('localhost')).to eq []62end63end6465describe '#get1' do66it 'returns nil' do67expect(subject.get1('localhost')).to be_nil68end69end7071describe '#length' do72it 'is zero' do73expect(subject.length).to eq 074end75end76end77end787980