Skip to content

Commit 714a305

Browse files
Lauren Voswinkelcalvn
andauthored
Add ability to specify a name for a cert to check for auth#tls (#256)
* Add ability to specify a name for a cert to check for auth#tls * add @param comment for name Co-authored-by: Calvin Leung Huang <1883212+calvn@users.noreply.github.com>
1 parent 44d180d commit 714a305

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

lib/vault/api/auth.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,12 +286,17 @@ def gcp(role, jwt, path = 'gcp')
286286
# @param [String] path (default: 'cert')
287287
# The path to the auth backend to use for the login procedure.
288288
#
289+
# @param [String] name optional
290+
# The named certificate role provided to the login request.
291+
#
289292
# @return [Secret]
290-
def tls(pem = nil, path = 'cert')
293+
def tls(pem = nil, path = 'cert', name: nil)
291294
new_client = client.dup
292295
new_client.ssl_pem_contents = pem if !pem.nil?
293296

294-
json = new_client.post("/v1/auth/#{CGI.escape(path)}/login")
297+
opts = {}
298+
opts[:name] = name if name
299+
json = new_client.post("/v1/auth/#{CGI.escape(path)}/login", opts)
295300
secret = Secret.decode(json)
296301
client.token = secret.auth.client_token
297302
return secret

spec/integration/api/auth_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,13 @@ module Vault
202202
expect(subject.token).to eq(result.auth.client_token)
203203
end
204204

205+
it "returns nil if a certificate name is provided that doesn't exist" do
206+
pending "dev server does not support tls"
207+
secret = subject.auth.tls(auth_cert, name: "not_here")
208+
209+
expect(secret).to_be nil
210+
end
211+
205212
it "raises an error if the authentication is bad", vault: "> 0.6.1" do
206213
subject.sys.disable_auth("cert")
207214

0 commit comments

Comments
 (0)