Skip to content

Commit 6e4be33

Browse files
authored
Merge pull request #98 from taikaa/PE-40175
PE-40175
2 parents da321a4 + 821562b commit 6e4be33

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

lib/puppet/type/sshkey.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,16 @@ def self.title_patterns
5252
end
5353

5454
newproperty(:key) do
55-
desc "The key itself; generally a long string of uuencoded characters. The `key`
56-
attribute may not contain whitespace.
55+
desc "The key itself; generally a long string of unencoded characters. The `key`
56+
attribute may not contain leading or trailing whitespace.
5757
5858
Make sure to omit the following in this attribute (and specify them in
5959
other attributes):
6060
61-
* Key headers, such as 'ssh-rsa' --- put these in the `type` attribute.
62-
* Key identifiers / comments, such as 'joescomputer.local' --- put these in
63-
the `name` attribute/resource title."
61+
* Key headers, such as 'ssh-rsa' --- put these in the `type` attribute."
62+
validate do |value|
63+
raise Puppet::Error, _('Key must contain neither leading nor trailing whitespace: %{value}') % { value: value } if %r{^\s|\s$}.match?(value)
64+
end
6465
end
6566

6667
# FIXME: This should automagically check for aliases to the hosts, just

spec/unit/type/sshkey_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@
7676
}.to raise_error(Puppet::Error, %r{cannot include whitespace})
7777
end
7878

79+
it "doesn't accept leading or trailing whitespace in the key contents" do
80+
expect {
81+
described_class.new(name: 'foo', key: ' AAAFA==')
82+
}.to raise_error(Puppet::Error, %r{Key must contain neither leading nor trailing whitespace})
83+
end
84+
7985
it "doesn't accept aliases in the resourcename" do
8086
expect {
8187
described_class.new(name: 'host,host.domain,ip')

0 commit comments

Comments
 (0)