Skip to content

Commit

Permalink
* Add dns_alt_names parameter
Browse files Browse the repository at this point in the history
* Add spec helper functions to verify contents of concat_fragment resources
* Replace spec.opts with .rspec
  • Loading branch information
treydock committed Jul 8, 2014
1 parent 15d7976 commit 1057f21
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
--format documentation
--color
--tty
--backtrace
1 change: 1 addition & 0 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
$allow_any_crl_auth = $::puppet::allow_any_crl_auth,
$auth_template = $::puppet::auth_template,
$ca_server = $::puppet::ca_server,
$dns_alt_names = $::puppet::dns_alt_names,
$main_template = $::puppet::main_template,
$nsauth_template = $::puppet::nsauth_template,
$puppet_dir = $::puppet::dir,
Expand Down
7 changes: 7 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@
# a string with the location of the ca_server
# or 'false'.
#
# $dns_alt_names:: Use additional DNS names when generating a
# certificate. Defaults to an empty Array.
# type:array
#
# $classfile:: The file in which puppet agent stores a list
# of the classes associated with the retrieved
# configuration.
Expand Down Expand Up @@ -255,6 +259,7 @@
$show_diff = $puppet::params::show_diff,
$configtimeout = $puppet::params::configtimeout,
$ca_server = $puppet::params::ca_server,
$dns_alt_names = $puppet::params::dns_alt_names,
$classfile = $puppet::params::classfile,
$main_template = $puppet::params::main_template,
$agent_template = $puppet::params::agent_template,
Expand Down Expand Up @@ -328,6 +333,8 @@
validate_string($server_external_nodes)
validate_string($server_ca_proxy)

validate_array($dns_alt_names)

include ::puppet::config
Class['puppet::config'] -> Class['puppet']

Expand Down
1 change: 1 addition & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
$show_diff = false
$configtimeout = 120
$ca_server = ''
$dns_alt_names = []
$classfile = '$vardir/classes.txt'

# Need your own config templates? Specify here:
Expand Down
26 changes: 26 additions & 0 deletions spec/classes/puppet_config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,19 @@
it 'should contain auth.conf' do
should contain_file('/etc/puppet/auth.conf').with_content(%r{^path /certificate_revocation_list/ca\nmethod find$})
end

it 'should contain puppet.conf [main]' do
verify_concat_fragment_exact_contents(subject, 'puppet.conf+10-main', [
'[main]',
' logdir = /var/log/puppet',
' rundir = /var/run/puppet',
' ssldir = $vardir/ssl',
' privatekeydir = $ssldir/private_keys { group = service }',
' hostprivkey = $privatekeydir/$certname.pem { mode = 640 }',
' autosign = $confdir/autosign.conf { mode = 664 }',
' show_diff = false',
])
end
end

describe 'with allow_any_crl_auth' do
Expand All @@ -24,4 +37,17 @@
should contain_file('/etc/puppet/auth.conf').with_content(%r{^path /certificate_revocation_list/ca\nauth any$})
end
end

context "when dns_alt_names => ['foo','bar']" do
let :pre_condition do
"class { 'puppet': dns_alt_names => ['foo','bar'] }"
end

it 'should contain puppet.conf [main] with dns_alt_names' do
verify_concat_fragment_contents(subject, 'puppet.conf+10-main', [
'[main]',
' dns_alt_names = foo,bar',
])
end
end
end
10 changes: 10 additions & 0 deletions spec/classes/puppet_init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,14 @@
it { should contain_concat_fragment('puppet.conf+10-main').with_content(/^\s+ca_server\s+= ca.example.org$/) }
end

# Test validate_array parameters
[
:dns_alt_names,
].each do |p|
context "when #{p} => 'foo'" do
let(:params) {{ p => 'foo' }}
it { expect { should create_class('puppet') }.to raise_error(Puppet::Error, /is not an Array/) }
end
end

end
9 changes: 9 additions & 0 deletions spec/lib/module_spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
def verify_concat_fragment_contents(subject, title, expected_lines)
content = subject.resource('concat_fragment', title).send(:parameters)[:content]
(content.split("\n") & expected_lines).should == expected_lines
end

def verify_concat_fragment_exact_contents(subject, title, expected_lines)
content = subject.resource('concat_fragment', title).send(:parameters)[:content]
content.split(/\n/).reject { |line| line =~ /(^#|^$|^\s+#)/ }.should == expected_lines
end
1 change: 0 additions & 1 deletion spec/spec.opts

This file was deleted.

1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'puppetlabs_spec_helper/module_spec_helper'
require 'lib/module_spec_helper'

fixture_path = File.expand_path(File.join(__FILE__, '..', 'fixtures'))

Expand Down
4 changes: 4 additions & 0 deletions templates/puppet.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,7 @@
ca_server = <%= @ca_server %>
<% end -%>

<% if @dns_alt_names and !@dns_alt_names.empty? -%>
dns_alt_names = <%= @dns_alt_names.join(",") %>
<% end -%>

0 comments on commit 1057f21

Please sign in to comment.