Skip to content

Commit d8cd272

Browse files
committed
Add tests for extra config options
Signed-off-by: Brian Dwyer <[email protected]>
1 parent e65f964 commit d8cd272

File tree

5 files changed

+59
-5
lines changed

5 files changed

+59
-5
lines changed

attributes/default.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
client['send_env'] = ['LANG', 'LC_*', 'LANGUAGE']
6767

6868
# extra client configuration options
69-
client['extras'].tap = {}
69+
client['extras'] = {}
7070
end
7171

7272
# sshd

spec/recipes/client_spec.rb

+27
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,33 @@
191191
end
192192
end
193193

194+
describe 'extra configuration values' do
195+
context 'without custom extra config value' do
196+
cached(:chef_run) do
197+
ChefSpec::ServerRunner.new.converge(described_recipe)
198+
end
199+
200+
it 'does not have any extra config options' do
201+
expect(chef_run).to render_file('/etc/ssh/ssh_config')
202+
expect(chef_run).not_to render_file('/etc/ssh/ssh_config').
203+
with_content(/^# Extra Configuration Options/)
204+
end
205+
end
206+
207+
context 'with custom extra config value' do
208+
cached(:chef_run) do
209+
ChefSpec::ServerRunner.new do |node|
210+
node.normal['ssh-hardening']['ssh']['client']['extras']['#ExtraConfig'] = 'Value'
211+
end.converge(described_recipe)
212+
end
213+
214+
it 'uses the extra config attributes' do
215+
expect(chef_run).to render_file('/etc/ssh/ssh_config').with_content(/^# Extra Configuration Options/)
216+
expect(chef_run).to render_file('/etc/ssh/ssh_config').with_content(/^#ExtraConfig Value/)
217+
end
218+
end
219+
end
220+
194221
context 'chef-solo' do
195222
cached(:chef_run) do
196223
ChefSpec::SoloRunner.new.converge(described_recipe)

spec/recipes/server_spec.rb

+27
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,33 @@
403403
end
404404
end
405405

406+
describe 'extra configuration values' do
407+
context 'without custom extra config value' do
408+
cached(:chef_run) do
409+
ChefSpec::ServerRunner.new.converge(described_recipe)
410+
end
411+
412+
it 'does not have any extra config options' do
413+
expect(chef_run).to render_file('/etc/ssh/sshd_config')
414+
expect(chef_run).not_to render_file('/etc/ssh/sshd_config').
415+
with_content(/^# Extra Configuration Options/)
416+
end
417+
end
418+
419+
context 'with custom extra config value' do
420+
cached(:chef_run) do
421+
ChefSpec::ServerRunner.new do |node|
422+
node.normal['ssh-hardening']['ssh']['server']['extras']['#ExtraConfig'] = 'Value'
423+
end.converge(described_recipe)
424+
end
425+
426+
it 'uses the extra config attributes' do
427+
expect(chef_run).to render_file('/etc/ssh/sshd_config').with_content(/^# Extra Configuration Options/)
428+
expect(chef_run).to render_file('/etc/ssh/sshd_config').with_content(/^#ExtraConfig Value/)
429+
end
430+
end
431+
end
432+
406433
it 'disables the challenge response authentication' do
407434
expect(chef_run).to render_file('/etc/ssh/sshd_config').
408435
with_content(/ChallengeResponseAuthentication no/)

templates/default/openssh.conf.erb

+2-2
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,9 @@ UseRoaming <%= @node['ssh-hardening']['ssh']['client']['roaming'] ? 'yes' : 'no'
118118
SendEnv <%= @node['ssh-hardening']['ssh']['client']['send_env'].join(' ') %>
119119
<% end %>
120120

121-
<%- unless Array(@node['ssh-hardening']['ssh']['client']['extras']).empty? %>
121+
<%- unless @node['ssh-hardening']['ssh']['client']['extras'].empty? %>
122122
# Extra Configuration Options
123-
<%- Array(@node['ssh-hardening']['ssh']['client']['extras']).each do |key, value| %>
123+
<%- @node['ssh-hardening']['ssh']['client']['extras'].each do |key, value| %>
124124
<%= key %> <%= value %>
125125
<% end -%>
126126
<% end -%>

templates/default/opensshd.conf.erb

+2-2
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,9 @@ X11Forwarding no
230230
#X11Forwarding no
231231
<% end %>
232232

233-
<%- unless Array(@node['ssh-hardening']['ssh']['server']['extras']).empty? %>
233+
<%- unless @node['ssh-hardening']['ssh']['server']['extras'].empty? %>
234234
# Extra Configuration Options
235-
<%- Array(@node['ssh-hardening']['ssh']['server']['extras']).each do |key, value| %>
235+
<%- @node['ssh-hardening']['ssh']['server']['extras'].each do |key, value| %>
236236
<%= key %> <%= value %>
237237
<% end -%>
238238
<% end -%>

0 commit comments

Comments
 (0)