Skip to content

Commit 3849c52

Browse files
Use inspec.input to load the attribute (#168)
* Use inspec.input to load the attribute Signed-off-by: Michée Lengronne <[email protected]> * valid hostkeys directly in the sshd_spec.rb Signed-off-by: Michée Lengronne <[email protected]> * code in control Signed-off-by: Michée Lengronne <[email protected]>
1 parent bcf6a77 commit 3849c52

File tree

2 files changed

+5
-12
lines changed

2 files changed

+5
-12
lines changed

controls/sshd_spec.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,12 @@
184184
impact 1.0
185185
title 'Server: Specify SSH HostKeys'
186186
desc 'Specify HostKey for protection against Man-In-The-Middle Attacks'
187+
188+
sshd_valid_hostkeys = ssh_crypto.valid_algorithms.map { |alg| "#{sshd_custom_path}/ssh_host_#{alg}_key" }
189+
sshd_valid_hostkeys = sshd_valid_hostkeys[0] if sshd_valid_hostkeys.length == 1
190+
187191
describe sshd_config(sshd_custom_path + '/sshd_config') do
188-
its('HostKey') { should cmp ssh_crypto.valid_hostkeys }
192+
its('HostKey') { should cmp sshd_valid_hostkeys }
189193
end
190194
end
191195

libraries/ssh_crypto.rb

-11
Original file line numberDiff line numberDiff line change
@@ -253,15 +253,4 @@ def valid_algorithms # rubocop:disable Metrics/CyclomaticComplexity
253253

254254
alg
255255
end
256-
257-
# returns the hostkeys value based on valid_algorithms
258-
def valid_hostkeys
259-
hostkeys = valid_algorithms.map { |alg| "#{sshd_custom_path}/ssh_host_#{alg}_key" }
260-
# its('HostKey') provides a string for a single-element value.
261-
# we have to return a string if we have a single-element
262-
# https://github.com/chef/inspec/issues/1434
263-
return hostkeys[0] if hostkeys.length == 1
264-
265-
hostkeys
266-
end
267256
end

0 commit comments

Comments
 (0)