Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

OHAI-442: Use default ssh_host_keys paths when no HostKey set #137

Closed
wants to merge 1 commit into from

2 participants

@lann

This just changes the logic slightly so that it will fall back to the
default paths if there is no sshd_config (as before) OR if the
sshd_config does not set any HostKey.

Regression spec included.

@lann lann OHAI-442: Use default ssh_host_keys paths when no HostKey set
This just changes the logic slightly so that it will fall back to the
default paths if there is no sshd_config (as before) OR if the
sshd_config does not set any HostKey.

Regression spec included.
18d37a5
@lann

I just noticed this bug is covered by #135 in an almost identical way. That change fixes another bug too, so it should be preferred over this one unless the other change is rejected there.

@btm
Owner

Fixed in PR #135

@btm btm closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 18, 2013
  1. @lann

    OHAI-442: Use default ssh_host_keys paths when no HostKey set

    lann authored
    This just changes the logic slightly so that it will fall back to the
    default paths if there is no sshd_config (as before) OR if the
    sshd_config does not set any HostKey.
    
    Regression spec included.
This page is out of date. Refresh to see the latest.
View
14 lib/ohai/plugins/ssh_host_key.rb
@@ -52,12 +52,12 @@ def is_dsa_or_rsa?(file)
end
end
end
-else
- if keys[:ssh][:host_dsa_public].nil? && File.exists?("/etc/ssh/ssh_host_dsa_key.pub")
- keys[:ssh][:host_dsa_public] = IO.read("/etc/ssh/ssh_host_dsa_key.pub").split[1]
- end
+end
- if keys[:ssh][:host_rsa_public].nil? && File.exists?("/etc/ssh/ssh_host_rsa_key.pub")
- keys[:ssh][:host_rsa_public] = IO.read("/etc/ssh/ssh_host_rsa_key.pub").split[1]
- end
+if keys[:ssh][:host_dsa_public].nil? && File.exists?("/etc/ssh/ssh_host_dsa_key.pub")
+ keys[:ssh][:host_dsa_public] = IO.read("/etc/ssh/ssh_host_dsa_key.pub").split[1]
+end
+
+if keys[:ssh][:host_rsa_public].nil? && File.exists?("/etc/ssh/ssh_host_rsa_key.pub")
+ keys[:ssh][:host_rsa_public] = IO.read("/etc/ssh/ssh_host_rsa_key.pub").split[1]
end
View
14 spec/unit/plugins/ssh_host_keys_spec.rb
@@ -6,9 +6,9 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
-#
+#
# http://www.apache.org/licenses/LICENSE-2.0
-#
+#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -55,7 +55,7 @@
@ohai._require_plugin("ssh_host_key")
@ohai[:keys][:ssh][:host_dsa_public].should eql(@dsa_key.split[1])
end
-
+
it "reads the key and sets the rsa attribute correctly" do
@ohai._require_plugin("ssh_host_key")
@ohai[:keys][:ssh][:host_rsa_public].should eql(@rsa_key.split[1])
@@ -66,6 +66,14 @@
it_behaves_like "loads keys"
end
+ context "when an sshd_config exists but contains no HostKeys" do
+ before do
+ File.stub(:open).with("/etc/ssh/sshd_config").and_yield('')
+ end
+
+ it_behaves_like "loads keys"
+ end
+
context "when an sshd_config can not be found" do
before do
File.stub(:exists?).with("/etc/ssh/sshd_config").and_return(false)
Something went wrong with that request. Please try again.