Skip to content

Commit b4322a9

Browse files
authored
Merge pull request #85 from snesbittsea/br_openssh-unit-test
Openssh Unit Tests
2 parents 79e080c + 9ae281a commit b4322a9

File tree

5 files changed

+328
-6
lines changed

5 files changed

+328
-6
lines changed

.gitignore

Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,193 @@ vagrant/environments/*/ubuntu-xenial-16.04-cloudimg-console.log
1818
.vagrant/
1919
.pe_build
2020
tests/
21+
### Ruby template
22+
*.gem
23+
*.rbc
24+
/.config
25+
/coverage/
26+
/InstalledFiles
27+
/pkg/
28+
/spec/reports/
29+
/spec/examples.txt
30+
/test/tmp/
31+
/test/version_tmp/
32+
/tmp/
33+
34+
# Used by dotenv library to load environment variables.
35+
# .env
36+
37+
## Specific to RubyMotion:
38+
.dat*
39+
.repl_history
40+
build/
41+
*.bridgesupport
42+
build-iPhoneOS/
43+
build-iPhoneSimulator/
44+
45+
## Specific to RubyMotion (use of CocoaPods):
46+
#
47+
# We recommend against adding the Pods directory to your .gitignore. However
48+
# you should judge for yourself, the pros and cons are mentioned at:
49+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
50+
#
51+
# vendor/Pods/
52+
53+
## Documentation cache and generated files:
54+
/.yardoc/
55+
/_yardoc/
56+
/doc/
57+
/rdoc/
58+
59+
## Environment normalization:
60+
/.bundle/
61+
/vendor/bundle
62+
/lib/bundler/man/
63+
64+
# for a library or gem, you might want to ignore these files since the code is
65+
# intended to run in multiple environments; otherwise, check them in:
66+
# Gemfile.lock
67+
# .ruby-version
68+
# .ruby-gemset
69+
70+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
71+
.rvmrc
72+
### JetBrains template
73+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
74+
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
75+
76+
# User-specific stuff:
77+
.idea/**/tasks.xml
78+
.idea/dictionaries
79+
80+
# Sensitive or high-churn files:
81+
.idea/**/dataSources/
82+
.idea/**/dataSources.ids
83+
.idea/**/dataSources.xml
84+
.idea/**/dataSources.local.xml
85+
.idea/**/sqlDataSources.xml
86+
.idea/**/dynamic.xml
87+
.idea/**/uiDesigner.xml
88+
89+
# Gradle:
90+
.idea/**/gradle.xml
91+
.idea/**/libraries
92+
93+
# Mongo Explorer plugin:
94+
.idea/**/mongoSettings.xml
95+
96+
## File-based project format:
97+
*.iws
98+
99+
## Plugin-specific files:
100+
101+
# IntelliJ
102+
/out/
103+
104+
# mpeltonen/sbt-idea plugin
105+
.idea_modules/
106+
107+
# JIRA plugin
108+
atlassian-ide-plugin.xml
109+
110+
# Crashlytics plugin (for Android Studio and IntelliJ)
111+
com_crashlytics_export_strings.xml
112+
crashlytics.properties
113+
crashlytics-build.properties
114+
fabric.properties
115+
### Vagrant template
116+
### Python template
117+
# Byte-compiled / optimized / DLL files
118+
__pycache__/
119+
*.py[cod]
120+
*$py.class
121+
122+
# C extensions
123+
*.so
124+
125+
# Distribution / packaging
126+
.Python
127+
develop-eggs/
128+
dist/
129+
downloads/
130+
eggs/
131+
.eggs/
132+
lib/
133+
lib64/
134+
parts/
135+
sdist/
136+
var/
137+
wheels/
138+
*.egg-info/
139+
.installed.cfg
140+
*.egg
141+
142+
# PyInstaller
143+
# Usually these files are written by a python script from a template
144+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
145+
*.manifest
146+
*.spec
147+
148+
# Installer logs
149+
pip-log.txt
150+
pip-delete-this-directory.txt
151+
152+
# Unit test / coverage reports
153+
htmlcov/
154+
.tox/
155+
.coverage
156+
.coverage.*
157+
.cache
158+
nosetests.xml
159+
coverage.xml
160+
*,cover
161+
.hypothesis/
162+
163+
# Translations
164+
*.mo
165+
*.pot
166+
167+
# Django stuff:
168+
*.log
169+
local_settings.py
170+
171+
# Flask stuff:
172+
instance/
173+
.webassets-cache
174+
175+
# Scrapy stuff:
176+
.scrapy
177+
178+
# Sphinx documentation
179+
docs/_build/
180+
181+
# PyBuilder
182+
target/
183+
184+
# Jupyter Notebook
185+
.ipynb_checkpoints
186+
187+
# pyenv
188+
.python-version
189+
190+
# celery beat schedule file
191+
celerybeat-schedule
192+
193+
# SageMath parsed files
194+
*.sage.py
195+
196+
# dotenv
197+
.env
198+
199+
# virtualenv
200+
.venv
201+
venv/
202+
ENV/
203+
204+
# Spyder project settings
205+
.spyderproject
206+
207+
# Rope project settings
208+
.ropeproject
209+
.idea/
210+
control-repo.iml

site/profile/.fixtures.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ fixtures:
1818
"archive": "https://github.com/voxpupuli/puppet-archive"
1919
"vagrant": "https://github.com/unibet/puppet-vagrant"
2020
symlinks:
21-
"profile": "#{source_dir}/site/profile"
22-
"tools": "#{source_dir}/site/tools"
21+
"profile": "#{source_dir}"
22+
"tools": "#{source_dir}/../tools"
2323
"my_data": "#{source_dir}/hieradata"

site/profile/manifests/ssh/openssh.pp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# This class installs and configures openssh
22
#
3+
# @param ensure Default: present
4+
# If openssh should be present or absent: present (default value) or absent
5+
#
6+
# @param configure_dir_source Default: undef
7+
# The source content.
8+
#
9+
# @param config_file_template Default ''
10+
# The path to an erb template to use to populate the openssh configuration file:
11+
# If the value is set to the empty string no openssh configuration file will be created.
12+
#
13+
314
class profile::ssh::openssh (
415
Enum['present','absent'] $ensure = 'present',
516

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
require 'spec_helper'
2+
require 'yaml'
3+
facts_yaml = File.dirname(__FILE__) + '/../fixtures/facts/spec.yaml'
4+
facts = YAML.load_file(facts_yaml)
5+
6+
describe 'profile::ssh::openssh', :type => :class do
7+
let(:facts) { facts }
8+
9+
on_supported_os.each do |os, facts|
10+
context "on #{os}" do
11+
let (:facts) do
12+
facts.merge(super())
13+
end
14+
15+
# it { pp catalogue.resources } # Uncomment to dump the catalogue
16+
17+
it { is_expected.to compile.with_all_deps }
18+
it { is_expected.to contain_class('profile::ssh::openssh') }
19+
20+
context 'with defaults values' do
21+
it { is_expected.not_to contain_tp__conf('openssh') }
22+
23+
it { is_expected.to contain_tp__dir('openssh').with(
24+
'ensure' => 'present',
25+
'source' => nil
26+
) }
27+
28+
it { is_expected.to contain_tp__install('openssh').with(
29+
'ensure' => 'present'
30+
) }
31+
end
32+
33+
context 'with :ensure parameter specified' do
34+
let :default_params do
35+
{
36+
:config_dir_source => 'test_config_dir_source',
37+
:config_file_template => '/dev/null',
38+
}
39+
end
40+
41+
describe 'with parameter: ensure set to absent' do
42+
let :params do
43+
default_params.merge({:ensure => 'absent'})
44+
end
45+
46+
it { is_expected.to contain_tp__install('openssh').with(
47+
'ensure' => 'absent'
48+
) }
49+
50+
it { is_expected.to contain_tp__dir('openssh').with(
51+
'ensure' => 'absent',
52+
'source' => 'test_config_dir_source'
53+
) }
54+
55+
it { is_expected.to contain_tp__conf('openssh').with(
56+
'ensure' => 'absent',
57+
'template' => '/dev/null',
58+
'options_hash' => {'option1' => 'option1_value',
59+
'option2' => 'option2_value'}
60+
) }
61+
end
62+
63+
describe 'with parameter :ensure set to present' do
64+
let :params do
65+
default_params.merge({:ensure => 'present'})
66+
end
67+
68+
it { is_expected.to contain_tp__install('openssh').with(
69+
'ensure' => 'present'
70+
) }
71+
72+
it { is_expected.to contain_tp__conf('openssh').with(
73+
'ensure' => 'present',
74+
'template' => '/dev/null',
75+
'options_hash' => {'option1' => 'option1_value',
76+
'option2' => 'option2_value'}
77+
) }
78+
79+
it { is_expected.to contain_tp__dir('openssh').with(
80+
'ensure' => 'present',
81+
'source' => 'test_config_dir_source'
82+
) }
83+
end
84+
85+
end
86+
87+
context 'with invalid parameter values' do
88+
describe 'with :ensure not equal to "present" or "absent"' do
89+
let :params do
90+
{
91+
:ensure => 'invalid'
92+
}
93+
end
94+
it { is_expected.to raise_error(Puppet::PreformattedError, /^Evaluation Error.* got \'invalid\'.*/) }
95+
end
96+
97+
describe 'with :config_dir_source set to empty string' do
98+
let :params do
99+
{
100+
:ensure => 'present',
101+
:config_dir_source => ''
102+
}
103+
end
104+
it { is_expected.to raise_error(Puppet::PreformattedError, /^Evaluation Error:.*/) }
105+
end
106+
107+
describe 'with :config_dir_source not a string' do
108+
let :params do
109+
{
110+
:ensure => 'present',
111+
:config_dir_source => 1
112+
}
113+
end
114+
it { is_expected.to raise_error(Puppet::PreformattedError, /^Evaluation Error:.*/) }
115+
end
116+
117+
end
118+
end
119+
end
120+
end
121+
122+

site/profile/spec/fixtures/hieradata/default.yaml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,9 @@
4949
profile::hardening::services::remove_default_services: true
5050

5151
# Configure OpenSSH:
52-
profile::ssh::openssh::banner_template: 'profile/ssh/openssh/banner.erb'
53-
profile::ssh::openssh::config_file_template: 'profile/ssh/openssh/sshd_config.erb'
54-
profile::ssh::openssh::hardened_configs: true
55-
52+
profile::ssh::openssh::options:
53+
option1: 'option1_value'
54+
option2: 'option2_value'
5655
# Monitor classes
5756
# profile::monitor::ganglia_class: ''
5857
profile::monitor::check_mk_class: ''

0 commit comments

Comments
 (0)