Skip to content

Commit

Permalink
Correctly pass in arguments as a single array
Browse files Browse the repository at this point in the history
Previously it used << with an array that ended up with a nested array.
Now it correctly uses += resulting in a single flat array.

Fixes: 6e1c856 ("Pass openssl commands as an array")
  • Loading branch information
ekohl committed Sep 30, 2024
1 parent 3fc848a commit e8666df
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
14 changes: 7 additions & 7 deletions lib/puppet/provider/x509_cert/openssl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ def create
'-out', resource[:path]
]
if resource[:ca]
options << ['-extfile', resource[:template]]
options << ['-CAcreateserial']
options << ['-CA', resource[:ca]]
options << ['-CAkey', resource[:cakey]]
options += ['-extfile', resource[:template]]
options += ['-CAcreateserial']
options += ['-CA', resource[:ca]]
options += ['-CAkey', resource[:cakey]]
else
options << ['-signkey', resource[:private_key]]
options += ['-signkey', resource[:private_key]]
if resource[:req_ext]
options << [
options += [
'-extensions', 'v3_req',
'-extfile', resource[:template]
]
Expand All @@ -98,7 +98,7 @@ def create
options += ['-passin', 'env:CERTIFICATE_PASSIN']
env['CERTIFICATE_PASSIN'] = password
end
options << ['-extensions', 'v3_req'] if resource[:req_ext] != :false
options += ['-extensions', 'v3_req'] if resource[:req_ext] != :false
openssl options, environment: env
end

Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/provider/x509_request/openssl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def create
options += ['-passin', 'env:CERTIFICATE_PASSIN']
env['CERTIFICATE_PASSIN'] = resource[:password]
end
options << ['-nodes'] unless resource[:encrypted]
options << '-nodes' unless resource[:encrypted]

openssl options, environment: env
end
Expand Down
24 changes: 12 additions & 12 deletions spec/unit/puppet/provider/x509_cert/openssl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
'-days', 3650,
'-key', '/tmp/foo.key',
'-out', '/tmp/foo.crt',
['-extensions', 'v3_req']
'-extensions', 'v3_req',
], { environment: {} })
resource.provider.create
end
Expand All @@ -56,7 +56,7 @@
'-key', '/tmp/foo.key',
'-out', '/tmp/foo.crt',
'-passin', 'env:CERTIFICATE_PASSIN',
['-extensions', 'v3_req']
'-extensions', 'v3_req',
], { environment: { 'CERTIFICATE_PASSIN' => '2x6${' } })
resource.provider.create
end
Expand All @@ -74,11 +74,11 @@
'-days', 3650,
'-in', '/tmp/foo.csr',
'-out', '/tmp/foo.crt',
['-extfile', '/tmp/foo.cnf'],
['-CAcreateserial'],
['-CA', '/tmp/foo-ca.crt'],
['-CAkey', '/tmp/foo-ca.key'],
['-extensions', 'v3_req']
'-extfile', '/tmp/foo.cnf',
'-CAcreateserial',
'-CA', '/tmp/foo-ca.crt',
'-CAkey', '/tmp/foo-ca.key',
'-extensions', 'v3_req',
], { environment: {} })
resource.provider.create
end
Expand All @@ -96,12 +96,12 @@
'-days', 3650,
'-in', '/tmp/foo.csr',
'-out', '/tmp/foo.crt',
['-extfile', '/tmp/foo.cnf'],
['-CAcreateserial'],
['-CA', '/tmp/foo-ca.crt'],
['-CAkey', '/tmp/foo-ca.key'],
'-extfile', '/tmp/foo.cnf',
'-CAcreateserial',
'-CA', '/tmp/foo-ca.crt',
'-CAkey', '/tmp/foo-ca.key',
'-passin', 'env:CERTIFICATE_PASSIN',
['-extensions', 'v3_req']
'-extensions', 'v3_req',
], { environment: { 'CERTIFICATE_PASSIN' => '5i;6%' } })
resource.provider.create
end
Expand Down

0 comments on commit e8666df

Please sign in to comment.