Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Use "inspect" when listing certificates

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...
commit 9607bd784b2f04b759932d36e843ba42d82635f1 1 parent 0144e68
Nick Lewis authored June 21, 2012
6  lib/puppet/ssl/certificate_authority/interface.rb
@@ -88,6 +88,8 @@ def list(ca)
88 88
           names = certs.values.map(&:keys).flatten
89 89
 
90 90
           name_width = names.sort_by(&:length).last.length rescue 0
  91
+          # We quote these names, so account for those characters
  92
+          name_width += 2
91 93
 
92 94
           output = [:request, :signed, :invalid].map do |type|
93 95
             next if certs[type].empty?
@@ -113,11 +115,11 @@ def format_host(ca, host, type, info, width)
113 115
 
114 116
           alt_names.delete(host)
115 117
 
116  
-          alt_str = "(alt names: #{alt_names.join(', ')})" unless alt_names.empty?
  118
+          alt_str = "(alt names: #{alt_names.map(&:inspect).join(', ')})" unless alt_names.empty?
117 119
 
118 120
           glyph = {:signed => '+', :request => ' ', :invalid => '-'}[type]
119 121
 
120  
-          name = host.ljust(width)
  122
+          name = host.inspect.ljust(width)
121 123
           fingerprint = "(#{ca.fingerprint(host, @digest)})"
122 124
 
123 125
           explanation = "(#{verify_error})" if verify_error
34  spec/unit/ssl/certificate_authority/interface_spec.rb
@@ -212,9 +212,9 @@
212 212
           applier = @class.new(:list, :to => [])
213 213
 
214 214
           applier.expects(:puts).with(<<-OUTPUT.chomp)
215  
-  host1 (fingerprint)
216  
-  host2 (fingerprint)
217  
-  host3 (fingerprint)
  215
+  "host1" (fingerprint)
  216
+  "host2" (fingerprint)
  217
+  "host3" (fingerprint)
218 218
           OUTPUT
219 219
 
220 220
           applier.apply(@ca)
@@ -228,12 +228,12 @@
228 228
           applier = @class.new(:list, :to => :all)
229 229
 
230 230
           applier.expects(:puts).with(<<-OUTPUT.chomp)
231  
-  host1 (fingerprint)
232  
-  host2 (fingerprint)
233  
-  host3 (fingerprint)
234  
-+ host5 (fingerprint)
235  
-+ host6 (fingerprint)
236  
-- host4 (fingerprint) (certificate revoked)
  231
+  "host1" (fingerprint)
  232
+  "host2" (fingerprint)
  233
+  "host3" (fingerprint)
  234
++ "host5" (fingerprint)
  235
++ "host6" (fingerprint)
  236
+- "host4" (fingerprint) (certificate revoked)
237 237
           OUTPUT
238 238
 
239 239
           applier.apply(@ca)
@@ -245,9 +245,9 @@
245 245
           applier = @class.new(:list, :to => :signed)
246 246
 
247 247
           applier.expects(:puts).with(<<-OUTPUT.chomp)
248  
-+ host4 (fingerprint)
249  
-+ host5 (fingerprint)
250  
-+ host6 (fingerprint)
  248
++ "host4" (fingerprint)
  249
++ "host5" (fingerprint)
  250
++ "host6" (fingerprint)
251 251
           OUTPUT
252 252
 
253 253
           applier.apply(@ca)
@@ -260,7 +260,7 @@
260 260
           applier = @class.new(:list, :to => ['host1'])
261 261
 
262 262
           applier.expects(:puts).with(<<-OUTPUT.chomp)
263  
-  host1 (fingerprint) (alt names: DNS:foo, DNS:bar)
  263
+  "host1" (fingerprint) (alt names: "DNS:foo", "DNS:bar")
264 264
           OUTPUT
265 265
 
266 266
           applier.apply(@ca)
@@ -272,10 +272,10 @@
272 272
           applier = @class.new(:list, :to => %w{host1 host2 host4 host5})
273 273
 
274 274
           applier.expects(:puts).with(<<-OUTPUT.chomp)
275  
-  host1 (fingerprint)
276  
-  host2 (fingerprint)
277  
-+ host4 (fingerprint)
278  
-+ host5 (fingerprint)
  275
+  "host1" (fingerprint)
  276
+  "host2" (fingerprint)
  277
++ "host4" (fingerprint)
  278
++ "host5" (fingerprint)
279 279
             OUTPUT
280 280
 
281 281
           applier.apply(@ca)

0 notes on commit 9607bd7

Please sign in to comment.
Something went wrong with that request. Please try again.