1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308
|
require 'spec_helper'
describe 'dns' do
describe 'on RedHat with no custom parameters' do
let(:facts) do
{
:clientcert => 'puppetmaster.example.com',
:concat_basedir => '/doesnotexist',
:fqdn => 'puppetmaster.example.com',
:osfamily => 'RedHat',
:ipaddress => '192.0.2.1',
}
end
describe 'with no custom parameters' do
it { should contain_class('dns::install') }
it { should contain_class('dns::config') }
it { should contain_class('dns::service') }
it { should contain_package('bind').with_ensure('present') }
it { should contain_concat('/etc/named/options.conf') }
it { verify_concat_fragment_contents(catalogue, 'options.conf+10-main.dns', [
'directory "/var/named";',
'recursion yes;',
'allow-query { any; };',
'dnssec-enable yes;',
'dnssec-validation yes;',
'empty-zones-enable yes;',
'listen-on-v6 { any; };',
'allow-recursion { localnets; localhost; };'
])}
it { should contain_concat('/etc/named.conf') }
it { verify_concat_fragment_exact_contents(catalogue, 'named.conf+10-main.dns', [
'// named.conf',
'include "/etc/rndc.key";',
'controls {',
' inet 127.0.0.1 port 953 allow { 127.0.0.1; } keys { "rndc-key"; };',
'};',
'options {',
' include "/etc/named/options.conf";',
'};',
'include "/etc/named.rfc1912.zones";',
'// Public view read by Server Admin',
'include "/etc/named/zones.conf";'
])}
it { should contain_file('/var/named/dynamic').with_ensure('directory') }
it { should contain_exec('create-rndc.key').
with_command("/usr/sbin/rndc-confgen -r /dev/urandom -a -c /etc/rndc.key") }
it { should contain_service('named').with_ensure('running').with_enable(true) }
end
describe 'with unmanaged localzonepath' do
let(:params) do {
:localzonepath => 'unmanaged',
} end
it { verify_concat_fragment_exact_contents(catalogue, 'named.conf+10-main.dns', [
'// named.conf',
'include "/etc/rndc.key";',
'controls {',
' inet 127.0.0.1 port 953 allow { 127.0.0.1; } keys { "rndc-key"; };',
'};',
'options {',
' include "/etc/named/options.conf";',
'};',
'// Public view read by Server Admin',
'include "/etc/named/zones.conf";'
])}
end
describe 'with additional_directives' do
let(:params) { {:additional_directives => [
[
'logging {',
' channel string {',
' print-severity boolean;',
' print-category boolean;',
' };',
'};',
].join("\n"),
[
'lwres {',
' listen-on [ port integer ] {',
' ( ipv4_address | ipv6_address ) [ port integer ];',
' };',
' view string optional_class;',
' search { string; ... };',
' ndots integer;',
'};',
].join("\n"),
]} }
it { verify_concat_fragment_exact_contents(catalogue, 'named.conf+10-main.dns', [
'// named.conf',
'include "/etc/rndc.key";',
'controls {',
' inet 127.0.0.1 port 953 allow { 127.0.0.1; } keys { "rndc-key"; };',
'};',
'options {',
' include "/etc/named/options.conf";',
'};',
'include "/etc/named.rfc1912.zones";',
'// additional directives',
'logging {',
' channel string {',
' print-severity boolean;',
' print-category boolean;',
' };',
'};',
'lwres {',
' listen-on [ port integer ] {',
' ( ipv4_address | ipv6_address ) [ port integer ];',
' };',
' view string optional_class;',
' search { string; ... };',
' ndots integer;',
'};',
'// Public view read by Server Admin',
'include "/etc/named/zones.conf";'
])}
end
describe 'with ipv6 disabled' do
let(:params) { {:listen_on_v6 => 'none'} }
it { should contain_concat('/etc/named/options.conf') }
it { verify_concat_fragment_contents(catalogue, 'options.conf+10-main.dns', [
'listen-on-v6 { none; };',
])}
end
describe 'with empty zones disabled' do
let(:params) { {:empty_zones_enable => 'no'} }
it { should contain_concat('/etc/named/options.conf') }
it { verify_concat_fragment_contents(catalogue, 'options.conf+10-main.dns', [
'empty-zones-enable no;',
])}
end
describe 'with dns_notify disabled' do
let(:params) { {:dns_notify => 'no' } }
it { should contain_concat('/etc/named/options.conf') }
it { verify_concat_fragment_contents(catalogue, 'options.conf+10-main.dns', [
'notify no;',
])}
end
describe 'with forward only' do
let(:params) { {:forward => 'only'} }
it { should contain_concat('/etc/named/options.conf') }
it { verify_concat_fragment_contents(catalogue, 'options.conf+10-main.dns', [
'forward only;',
])}
end
describe 'with undef forward' do
let(:params) { {:forward => :undef} }
it { should contain_concat('/etc/named/options.conf') }
it { should contain_concat_fragment('options.conf+10-main.dns').without_content('/forward ;/') }
end
describe 'with false listen_on_v6' do
let(:params) { {:listen_on_v6 => false} }
it { should contain_concat('/etc/named/options.conf') }
it { should contain_concat_fragment('options.conf+10-main.dns').without_content('/listen_on_v6/') }
end
describe 'with service_ensure stopped' do
let(:params) { {:service_ensure => 'stopped'} }
it { should contain_service('named').with_ensure('stopped').with_enable(true) }
end
describe 'with service_enable false' do
let(:params) { {:service_enable => false} }
it { should contain_service('named').with_ensure('running').with_enable(false) }
end
describe 'with acls set' do
let(:params) { {:acls => { 'trusted_nets' => [ '127.0.0.1/24', '127.0.1.0/24' ] } } }
it { verify_concat_fragment_exact_contents(catalogue, 'named.conf+10-main.dns', [
'// named.conf',
'include "/etc/rndc.key";',
'controls {',
' inet 127.0.0.1 port 953 allow { 127.0.0.1; } keys { "rndc-key"; };',
'};',
'options {',
' include "/etc/named/options.conf";',
'};',
'include "/etc/named.rfc1912.zones";',
'acl "trusted_nets" {',
' 127.0.0.1/24;',
' 127.0.1.0/24;',
'};',
'// Public view read by Server Admin',
'include "/etc/named/zones.conf";'
])}
end
describe 'with additional options' do
let(:params) { { :additional_options => { 'max-cache-ttl' => 3600, 'max-ncache-ttl' => 3600 } } }
it { verify_concat_fragment_contents(catalogue, 'options.conf+10-main.dns', [
'directory "/var/named";',
'recursion yes;',
'allow-query { any; };',
'dnssec-enable yes;',
'dnssec-validation yes;',
'empty-zones-enable yes;',
'listen-on-v6 { any; };',
'allow-recursion { localnets; localhost; };',
'max-cache-ttl 3600;',
'max-ncache-ttl 3600;'
])}
end
describe 'with zones' do
let :params do
{
:zones => {
'example.com' => {},
},
}
end
it { should compile.with_all_deps }
it { should contain_dns__zone('example.com') }
end
describe 'with keys' do
let :params do
{
:keys => {
'dns-key' => {},
},
}
end
it { should compile.with_all_deps }
it { should contain_dns__key('dns-key') }
end
end
describe 'on FreeBSD with no custom parameters' do
let(:facts) do
{
:clientcert => 'puppetmaster.example.com',
:concat_basedir => '/doesnotexist',
:fqdn => 'puppetmaster.example.com',
:osfamily => 'FreeBSD',
}
end
describe 'with no custom parameters' do
it { should contain_class('dns::install') }
it { should contain_class('dns::config') }
it { should contain_class('dns::service') }
it { should contain_package('bind910').with_ensure('present') }
it { should contain_concat('/usr/local/etc/namedb/options.conf') }
it { verify_concat_fragment_contents(catalogue, 'options.conf+10-main.dns', [
'recursion yes;',
'allow-query { any; };',
'dnssec-enable yes;',
'dnssec-validation yes;',
'empty-zones-enable yes;',
'listen-on-v6 { any; };',
'allow-recursion { localnets; localhost; };'
])}
it { should contain_concat('/usr/local/etc/namedb/named.conf') }
it { verify_concat_fragment_exact_contents(catalogue, 'named.conf+10-main.dns', [
'// named.conf',
'include "/usr/local/etc/namedb/rndc.key";',
'controls {',
' inet 127.0.0.1 port 953 allow { 127.0.0.1; } keys { "rndc-key"; };',
'};',
'options {',
' include "/usr/local/etc/namedb/options.conf";',
'};',
'// Public view read by Server Admin',
'include "/usr/local/etc/namedb/zones.conf";'
])}
it { should contain_file('/usr/local/etc/namedb/dynamic').with_ensure('directory') }
it { should contain_exec('create-rndc.key').
with_command("/usr/local/sbin/rndc-confgen -r /dev/urandom -a -c /usr/local/etc/namedb/rndc.key") }
it { should contain_service('named').with_ensure('running').with_enable(true) }
end
describe 'with service_ensure stopped' do
let(:params) { {:service_ensure => 'stopped'} }
it { should contain_service('named').with_ensure('stopped').with_enable(true) }
end
describe 'with service_enable false' do
let(:params) { {:service_enable => false} }
it { should contain_service('named').with_ensure('running').with_enable(false) }
end
end
end
|