Skip to content

Commit 0190f12

Browse files
committed
PE-40175
Prior to this commit the sshkey type didn't prohibit whitespace in the key property. This change now fails the resource type if a user adds space and adds a spec test
1 parent da321a4 commit 0190f12

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/puppet/type/sshkey.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ 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`
55+
desc "The key itself; generally a long string of unencoded characters. The `key`
5656
attribute may not contain whitespace.
5757
5858
Make sure to omit the following in this attribute (and specify them in
@@ -61,6 +61,9 @@ def self.title_patterns
6161
* Key headers, such as 'ssh-rsa' --- put these in the `type` attribute.
6262
* Key identifiers / comments, such as 'joescomputer.local' --- put these in
6363
the `name` attribute/resource title."
64+
validate do |value|
65+
raise Puppet::Error, _('Key must not contain whitespace: %{value}') % { value: value } if %r{\s}.match?(value)
66+
end
6467
end
6568

6669
# 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 whitespace in the key contents" do
80+
expect {
81+
described_class.new(name: 'foo', key: 'AAA FA==')
82+
}.to raise_error(Puppet::Error, %r{Key must not contain 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)