Skip to content

Commit

Permalink
Use "inspect" when listing certificates
Browse files Browse the repository at this point in the history
This fixes an issue of `puppet cert list` potentially not accurately
depicting the actual certname of the certificate/request. For instance,
"foo^H^H^Hbar" would simply appear as "bar".
  • Loading branch information
nicklewis committed Jun 27, 2012
1 parent 0144e68 commit 9607bd7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
6 changes: 4 additions & 2 deletions lib/puppet/ssl/certificate_authority/interface.rb
Expand Up @@ -88,6 +88,8 @@ def list(ca)
names = certs.values.map(&:keys).flatten

name_width = names.sort_by(&:length).last.length rescue 0
# We quote these names, so account for those characters
name_width += 2

output = [:request, :signed, :invalid].map do |type|
next if certs[type].empty?
Expand All @@ -113,11 +115,11 @@ def format_host(ca, host, type, info, width)

alt_names.delete(host)

alt_str = "(alt names: #{alt_names.join(', ')})" unless alt_names.empty?
alt_str = "(alt names: #{alt_names.map(&:inspect).join(', ')})" unless alt_names.empty?

glyph = {:signed => '+', :request => ' ', :invalid => '-'}[type]

name = host.ljust(width)
name = host.inspect.ljust(width)
fingerprint = "(#{ca.fingerprint(host, @digest)})"

explanation = "(#{verify_error})" if verify_error
Expand Down
34 changes: 17 additions & 17 deletions spec/unit/ssl/certificate_authority/interface_spec.rb
Expand Up @@ -212,9 +212,9 @@
applier = @class.new(:list, :to => [])

applier.expects(:puts).with(<<-OUTPUT.chomp)
host1 (fingerprint)
host2 (fingerprint)
host3 (fingerprint)
"host1" (fingerprint)
"host2" (fingerprint)
"host3" (fingerprint)
OUTPUT

applier.apply(@ca)
Expand All @@ -228,12 +228,12 @@
applier = @class.new(:list, :to => :all)

applier.expects(:puts).with(<<-OUTPUT.chomp)
host1 (fingerprint)
host2 (fingerprint)
host3 (fingerprint)
+ host5 (fingerprint)
+ host6 (fingerprint)
- host4 (fingerprint) (certificate revoked)
"host1" (fingerprint)
"host2" (fingerprint)
"host3" (fingerprint)
+ "host5" (fingerprint)
+ "host6" (fingerprint)
- "host4" (fingerprint) (certificate revoked)
OUTPUT

applier.apply(@ca)
Expand All @@ -245,9 +245,9 @@
applier = @class.new(:list, :to => :signed)

applier.expects(:puts).with(<<-OUTPUT.chomp)
+ host4 (fingerprint)
+ host5 (fingerprint)
+ host6 (fingerprint)
+ "host4" (fingerprint)
+ "host5" (fingerprint)
+ "host6" (fingerprint)
OUTPUT

applier.apply(@ca)
Expand All @@ -260,7 +260,7 @@
applier = @class.new(:list, :to => ['host1'])

applier.expects(:puts).with(<<-OUTPUT.chomp)
host1 (fingerprint) (alt names: DNS:foo, DNS:bar)
"host1" (fingerprint) (alt names: "DNS:foo", "DNS:bar")
OUTPUT

applier.apply(@ca)
Expand All @@ -272,10 +272,10 @@
applier = @class.new(:list, :to => %w{host1 host2 host4 host5})

applier.expects(:puts).with(<<-OUTPUT.chomp)
host1 (fingerprint)
host2 (fingerprint)
+ host4 (fingerprint)
+ host5 (fingerprint)
"host1" (fingerprint)
"host2" (fingerprint)
+ "host4" (fingerprint)
+ "host5" (fingerprint)
OUTPUT

applier.apply(@ca)
Expand Down

0 comments on commit 9607bd7

Please sign in to comment.