Skip to content

Instantly share code, notes, and snippets.

@VuokkoVuorinnen
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save VuokkoVuorinnen/5dcd64c5dca39966a98e to your computer and use it in GitHub Desktop.
Save VuokkoVuorinnen/5dcd64c5dca39966a98e to your computer and use it in GitHub Desktop.
Serverspec
require 'spec_helper'
# Install necessary packages: bind and bind-utils (the latter for testing with
# the host command)
describe package('bind') do
it { should be_installed }
end
describe package('bind-utils') do
it { should be_installed }
end
# Check config files
CONF = '/etc/named.conf'
ZONE = 'chem.net'
ZONE_FILE = '/var/named/chem.net'
REVERSE_ZONE = '56.168.192.in-addr.arpa'
REVERSE_ZONE_FILE = '/var/named/56.168.192.in-addr.arpa'
describe file(CONF) do
it { should be_file }
it { should be_mode 644 }
its(:content) { should match 'zone.*chem.net' }
its(:content) { should match 'zone.*56.168.192.in-addr.arpa'}
end
describe command('named-checkconf') do
it { should return_exit_status 0 }
end
describe file (ZONE_FILE) do
it { should be_file }
it { should be_mode 640 }
it { should be_owned_by 'root' }
it { should be_grouped_into 'named' }
end
describe file (REVERSE_ZONE_FILE) do
it { should be_file }
it { should be_mode 640 }
it { should be_owned_by 'root' }
it { should be_grouped_into 'named' }
end
describe command("named-checkzone #{ZONE}. #{ZONE_FILE} | tail -1") do
it { should return_exit_status 0 }
it { should return_stdout 'OK' }
end
describe command("named-checkzone #{REVERSE_ZONE}. #{REVERSE_ZONE_FILE} | tail -1") do
it { should return_exit_status 0 }
it { should return_stdout 'OK' }
end
# Check service
describe port(53) do
it { should be_listening.with('tcp') }
it { should be_listening.with('udp') }
end
describe service('named') do
it { should be_running }
it { should be_enabled }
end
# Interact with the DNS server, ask for all A, CNAME, SRV, PTR records
describe host('hydrogen.chem.net') do
its(:ipaddress) { should eq '192.168.56.1' }
it { should be_resolvable.by('dns') }
end
describe host('helium.chem.net') do
# its(:ipaddress) { should eq '192.168.56.2' }
its(:ipaddress) { should eq '127.0.0.1' }
it { should be_resolvable.by('dns') }
end
describe host('lithium.chem.net') do
its(:ipaddress) { should eq '192.168.56.3' }
it { should be_resolvable.by('dns') }
end
describe host('beryllium.chem.net') do
its(:ipaddress) { should eq '192.168.56.4' }
it { should be_resolvable.by('dns') }
end
describe host('boron.chem.net') do
its(:ipaddress) { should eq '192.168.56.5' }
it { should be_resolvable.by('dns') }
end
describe host('carbon.chem.net') do
its(:ipaddress) { should eq '192.168.56.6' }
it { should be_resolvable.by('dns') }
end
describe host('nitrogen.chem.net') do
its(:ipaddress) { should eq '192.168.56.7' }
it { should be_resolvable.by('dns') }
end
describe host('oxygen.chem.net') do
its(:ipaddress) { should eq '192.168.56.8' }
it { should be_resolvable.by('dns') }
end
describe host('fluorine.chem.net') do
its(:ipaddress) { should eq '192.168.56.9' }
it { should be_resolvable.by('dns') }
end
describe host('neon.chem.net') do
its(:ipaddress) { should eq '192.168.56.10' }
it { should be_resolvable.by('dns') }
end
# @test "Looking up alias ns1 should return the correct host" {
# result="$(host ns1.${ZONE} ${IP} | grep alias)"
# [[ "${result}" =~ "helium.${ZONE}" ]]
# }
# @test "Looking up alias ns2 should return the correct host" {
# result="$(host ns2.${ZONE} ${IP} | grep alias)"
# [ "$?" -eq 0 ] # exit status should be 0
# [[ "${result}" =~ "lithium.${ZONE}" ]]
# }
# @test "Looking up alias www should return the correct host" {
# result="$(host www.${ZONE} ${IP} | grep alias)"
# [ "$?" -eq 0 ] # exit status should be 0
# [[ "${result}" =~ "boron.${ZONE}" ]]
# }
# @test "Looking up alias mail-in should return the correct host" {
# result="$(host mail-in.${ZONE} ${IP} | grep alias)"
# [ "$?" -eq 0 ] # exit status should be 0
# [[ "${result}" =~ "carbon.${ZONE}" ]]
# }
# @test "Looking up alias mail-out should return the correct host" {
# result="$(host mail-out.${ZONE} ${IP} | grep alias)"
# [ "$?" -eq 0 ] # exit status should be 0
# [[ "${result}" =~ "carbon.${ZONE}" ]]
# }
# @test "Looking up domain name should return mail handler and level (10)" {
# result="$(host ${ZONE} ${IP} | grep mail)"
# [ "$?" -eq 0 ] # exit status should be 0
# [ "${result}" = "${ZONE} mail is handled by 10 carbon.${ZONE}." ]
# }
# @test "Looking up service ftp should return the correct host and priority/weight/port (10 0 21)" {
# result="$(host -t SRV _ftp._tcp.${ZONE} ${IP} | grep SRV)"
# [ "$?" -eq 0 ] # exit status should be 0
# [[ "${result}" =~ "10 0 21 nitrogen.${ZONE}" ]]
# }
# NET_IP=192.168.56
# @test "Looking up ${NET_IP}.1 should return the correct host" {
# result="$(host ${NET_IP}.1 ${IP} | grep pointer)"
# [ "$?" -eq 0 ] # exit status should be 0
# [ "${result}" = "1.${REVERSE_ZONE} domain name pointer hydrogen.chem.net." ]
# }
# @test "Looking up ${NET_IP}.2 should return the correct host" {
# result="$(host ${NET_IP}.2 ${IP} | grep pointer)"
# [ "$?" -eq 0 ] # exit status should be 0
# [ "${result}" = "2.${REVERSE_ZONE} domain name pointer helium.chem.net." ]
# }
# @test "Looking up ${NET_IP}.3 should return the correct host" {
# result="$(host ${NET_IP}.3 ${IP} | grep pointer)"
# [ "$?" -eq 0 ] # exit status should be 0
# [ "${result}" = "3.${REVERSE_ZONE} domain name pointer lithium.chem.net." ]
# }
# @test "Looking up ${NET_IP}.4 should return the correct host" {
# result="$(host ${NET_IP}.4 ${IP} | grep pointer)"
# [ "$?" -eq 0 ] # exit status should be 0
# [ "${result}" = "4.${REVERSE_ZONE} domain name pointer beryllium.chem.net." ]
# }
# @test "Looking up ${NET_IP}.5 should return the correct host" {
# result="$(host ${NET_IP}.5 ${IP} | grep pointer)"
# [ "$?" -eq 0 ] # exit status should be 0
# [ "${result}" = "5.${REVERSE_ZONE} domain name pointer boron.chem.net." ]
# }
# @test "Looking up ${NET_IP}.6 should return the correct host" {
# result="$(host ${NET_IP}.6 ${IP} | grep pointer)"
# [ "$?" -eq 0 ] # exit status should be 0
# [ "${result}" = "6.${REVERSE_ZONE} domain name pointer carbon.chem.net." ]
# }
# @test "Looking up ${NET_IP}.7 should return the correct host" {
# result="$(host ${NET_IP}.7 ${IP} | grep pointer)"
# [ "$?" -eq 0 ] # exit status should be 0
# [ "${result}" = "7.${REVERSE_ZONE} domain name pointer nitrogen.chem.net." ]
# }
# @test "Looking up ${NET_IP}.8 should return the correct host" {
# result="$(host ${NET_IP}.8 ${IP} | grep pointer)"
# [ "$?" -eq 0 ] # exit status should be 0
# [ "${result}" = "8.${REVERSE_ZONE} domain name pointer oxygen.chem.net." ]
# }
# @test "Looking up ${NET_IP}.9 should return the correct host" {
# result="$(host ${NET_IP}.9 ${IP} | grep pointer)"
# [ "$?" -eq 0 ] # exit status should be 0
# [ "${result}" = "9.${REVERSE_ZONE} domain name pointer fluorine.chem.net." ]
# }
# @test "Looking up ${NET_IP}.10 should return the correct host" {
# result="$(host ${NET_IP}.10 ${IP} | grep pointer)"
# [ "$?" -eq 0 ] # exit status should be 0
# [ "${result}" = "10.${REVERSE_ZONE} domain name pointer neon.chem.net." ]
# }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment