Skip to content

Commit c4f17e3

Browse files
committed
add more tests
1 parent ad23df8 commit c4f17e3

8 files changed

Lines changed: 750 additions & 14 deletions

File tree

REFERENCE.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
* `ssh::client::install`: Install ssh client package
2020
* `ssh::server::config`: Managed ssh server configuration
2121
* `ssh::server::install`: Install ssh server package
22-
* `ssh::server::service`: This class managed ssh server service
22+
* `ssh::server::service`: This class manages the ssh server service
2323

2424
### Defined types
2525

@@ -613,6 +613,8 @@ The following parameters are available in the `ssh::server` class:
613613
* [`config_group`](#-ssh--server--config_group)
614614
* [`default_options`](#-ssh--server--default_options)
615615
* [`ensure`](#-ssh--server--ensure)
616+
* [`service_ensure`](#-ssh--server--service_ensure)
617+
* [`service_enable`](#-ssh--server--service_enable)
616618
* [`include_dir`](#-ssh--server--include_dir)
617619
* [`include_dir_mode`](#-ssh--server--include_dir_mode)
618620
* [`include_dir_purge`](#-ssh--server--include_dir_purge)
@@ -731,6 +733,22 @@ Ensurable param to ssh server
731733

732734
Default value: `present`
733735

736+
##### <a name="-ssh--server--service_ensure"></a>`service_ensure`
737+
738+
Data type: `Stdlib::Ensure::Service`
739+
740+
Whether the service should be running or stopped, defaults to true when ensure is set to present, otherwise false
741+
742+
Default value: `$ensure ? { 'present' => 'running', 'absent' => 'stopped'`
743+
744+
##### <a name="-ssh--server--service_enable"></a>`service_enable`
745+
746+
Data type: `Boolean`
747+
748+
Whether the service should be started at boot. Will be added automatically if ensure is running/removed if ensure is stopped
749+
750+
Default value: `($service_ensure == 'running'`
751+
734752
##### <a name="-ssh--server--include_dir"></a>`include_dir`
735753

736754
Data type: `Optional[Stdlib::Absolutepath]`

manifests/server.pp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@
4444
# @param ensure
4545
# Ensurable param to ssh server
4646
#
47+
# @param service_ensure
48+
# Whether the service should be running or stopped, defaults to true when ensure is set to present, otherwise false
49+
#
50+
# @param service_enable
51+
# Whether the service should be started at boot. Will be added automatically if ensure is running/removed if ensure is stopped
52+
#
4753
# @param include_dir
4854
# Path to sshd include directory.
4955
#
@@ -127,6 +133,8 @@
127133
Variant[Integer, String[1]] $config_group,
128134
Hash $default_options,
129135
String $ensure = present,
136+
Stdlib::Ensure::Service $service_ensure = $ensure ? { 'present' => 'running', 'absent' => 'stopped' },
137+
Boolean $service_enable = ($service_ensure == 'running'),
130138
Optional[Stdlib::Absolutepath] $include_dir = undef,
131139
Stdlib::Filemode $include_dir_mode = '0700',
132140
Boolean $include_dir_purge = true,

manifests/server/service.pp

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,16 @@
11
# @summary
2-
# This class managed ssh server service
2+
# This class manages the ssh server service
33
#
44
# @api private
55
#
6-
# @param ensure
7-
# Ensurable service param
8-
#
9-
# @param enable
10-
# Define if service is enable
11-
#
12-
class ssh::server::service (
13-
Stdlib::Ensure::Service $ensure = 'running',
14-
Boolean $enable = true,
15-
) {
6+
class ssh::server::service {
167
assert_private()
178

189
service { $ssh::server::service_name:
19-
ensure => $ssh::server::service::ensure,
10+
ensure => $ssh::server::service_ensure,
2011
hasstatus => true,
2112
hasrestart => true,
22-
enable => $ssh::server::service::enable,
13+
enable => $ssh::server::service_enable,
2314
require => Class['ssh::server::config'],
2415
}
2516
}

spec/classes/client_spec.rb

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,89 @@
140140
it { is_expected.to compile.with_all_deps }
141141
it { is_expected.not_to contain_ssh__client__config_file('custom') }
142142
end
143+
144+
context 'with use_augeas enabled' do
145+
let :pre_condition do
146+
'define ssh_config ($ensure = present, $key = undef, $value = undef, $target = undef, $host = undef) {}'
147+
end
148+
149+
let :params do
150+
{
151+
use_augeas: true,
152+
options: {
153+
'ForwardAgent' => 'no',
154+
'StrictHostKeyChecking' => 'ask',
155+
},
156+
options_absent: ['GSSAPIAuthentication'],
157+
}
158+
end
159+
160+
it { is_expected.to compile.with_all_deps }
161+
it { is_expected.not_to contain_concat('/etc/ssh/ssh_config') }
162+
163+
it {
164+
is_expected.to contain_ssh_config('ForwardAgent').with(
165+
ensure: 'present',
166+
key: 'ForwardAgent',
167+
value: 'no',
168+
target: '/etc/ssh/ssh_config',
169+
)
170+
}
171+
172+
it {
173+
is_expected.to contain_ssh_config('StrictHostKeyChecking').with(
174+
ensure: 'present',
175+
key: 'StrictHostKeyChecking',
176+
value: 'ask',
177+
)
178+
}
179+
180+
it {
181+
is_expected.to contain_ssh_config('GSSAPIAuthentication').with(
182+
ensure: 'absent',
183+
key: 'GSSAPIAuthentication',
184+
)
185+
}
186+
end
187+
188+
context 'with use_augeas and host block options' do
189+
let :pre_condition do
190+
'define ssh_config ($ensure = present, $key = undef, $value = undef, $target = undef, $host = undef) {}'
191+
end
192+
193+
let :params do
194+
{
195+
use_augeas: true,
196+
options: {
197+
'Host *.example.com' => {
198+
'ForwardAgent' => 'yes',
199+
'BatchMode' => 'yes',
200+
},
201+
},
202+
options_absent: [],
203+
}
204+
end
205+
206+
it { is_expected.to compile.with_all_deps }
207+
208+
it {
209+
is_expected.to contain_ssh_config('ForwardAgent *.example.com').with(
210+
ensure: 'present',
211+
host: '*.example.com',
212+
key: 'ForwardAgent',
213+
value: 'yes',
214+
)
215+
}
216+
217+
it {
218+
is_expected.to contain_ssh_config('BatchMode *.example.com').with(
219+
ensure: 'present',
220+
host: '*.example.com',
221+
key: 'BatchMode',
222+
value: 'yes',
223+
)
224+
}
225+
end
143226
end
144227
end
145228
end

0 commit comments

Comments
 (0)