From f055cbf4f08f46eb0338891b33aeb48edc37dbed Mon Sep 17 00:00:00 2001 From: Brian Dwyer Date: Thu, 6 Apr 2017 15:35:28 -0400 Subject: [PATCH] Add tests for extra config options Signed-off-by: Brian Dwyer --- attributes/default.rb | 2 +- spec/recipes/client_spec.rb | 27 +++++++++++++++++++++++++++ spec/recipes/server_spec.rb | 27 +++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 1 deletion(-) diff --git a/attributes/default.rb b/attributes/default.rb index 87a2493..128ae2c 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -66,7 +66,7 @@ client['send_env'] = ['LANG', 'LC_*', 'LANGUAGE'] # extra client configuration options - client['extras'].tap = {} + client['extras'] = {} end # sshd diff --git a/spec/recipes/client_spec.rb b/spec/recipes/client_spec.rb index 42905af..fbbfcf2 100644 --- a/spec/recipes/client_spec.rb +++ b/spec/recipes/client_spec.rb @@ -191,6 +191,33 @@ end end + describe 'extra configuration values' do + context 'without custom extra config value' do + cached(:chef_run) do + ChefSpec::ServerRunner.new.converge(described_recipe) + end + + it 'does not have any extra config options' do + expect(chef_run).to render_file('/etc/ssh/ssh_config') + expect(chef_run).not_to render_file('/etc/ssh/ssh_config'). + with_content(/^# Extra Configuration Options/) + end + end + + context 'with custom extra config value' do + cached(:chef_run) do + ChefSpec::ServerRunner.new do |node| + node.normal['ssh-hardening']['ssh']['client']['extras']['#ExtraConfig'] = 'Value' + end.converge(described_recipe) + end + + it 'uses the extra config attributes' do + expect(chef_run).to render_file('/etc/ssh/ssh_config').with_content(/^# Extra Configuration Options/) + expect(chef_run).to render_file('/etc/ssh/ssh_config').with_content(/^#ExtraConfig Value/) + end + end + end + context 'chef-solo' do cached(:chef_run) do ChefSpec::SoloRunner.new.converge(described_recipe) diff --git a/spec/recipes/server_spec.rb b/spec/recipes/server_spec.rb index 151dff4..8376e58 100644 --- a/spec/recipes/server_spec.rb +++ b/spec/recipes/server_spec.rb @@ -403,6 +403,33 @@ end end + describe 'extra configuration values' do + context 'without custom extra config value' do + cached(:chef_run) do + ChefSpec::ServerRunner.new.converge(described_recipe) + end + + it 'does not have any extra config options' do + expect(chef_run).to render_file('/etc/ssh/sshd_config') + expect(chef_run).not_to render_file('/etc/ssh/sshd_config'). + with_content(/^# Extra Configuration Options/) + end + end + + context 'with custom extra config value' do + cached(:chef_run) do + ChefSpec::ServerRunner.new do |node| + node.normal['ssh-hardening']['ssh']['server']['extras']['#ExtraConfig'] = 'Value' + end.converge(described_recipe) + end + + it 'uses the extra config attributes' do + expect(chef_run).to render_file('/etc/ssh/sshd_config').with_content(/^# Extra Configuration Options/) + expect(chef_run).to render_file('/etc/ssh/sshd_config').with_content(/^#ExtraConfig Value/) + end + end + end + it 'disables the challenge response authentication' do expect(chef_run).to render_file('/etc/ssh/sshd_config'). with_content(/ChallengeResponseAuthentication no/)