Skip to content

Commit

Permalink
Add ability to specify a name for a cert to check for auth#tls (#256)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
Lauren Voswinkel and calvn authored Aug 11, 2021
1 parent 44d180d commit 714a305
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/vault/api/auth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -286,12 +286,17 @@ def gcp(role, jwt, path = 'gcp')
# @param [String] path (default: 'cert')
# The path to the auth backend to use for the login procedure.
#
# @param [String] name optional
# The named certificate role provided to the login request.
#
# @return [Secret]
def tls(pem = nil, path = 'cert')
def tls(pem = nil, path = 'cert', name: nil)
new_client = client.dup
new_client.ssl_pem_contents = pem if !pem.nil?

json = new_client.post("/v1/auth/#{CGI.escape(path)}/login")
opts = {}
opts[:name] = name if name
json = new_client.post("/v1/auth/#{CGI.escape(path)}/login", opts)
secret = Secret.decode(json)
client.token = secret.auth.client_token
return secret
Expand Down
7 changes: 7 additions & 0 deletions spec/integration/api/auth_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,13 @@ module Vault
expect(subject.token).to eq(result.auth.client_token)
end

it "returns nil if a certificate name is provided that doesn't exist" do
pending "dev server does not support tls"
secret = subject.auth.tls(auth_cert, name: "not_here")

expect(secret).to_be nil
end

it "raises an error if the authentication is bad", vault: "> 0.6.1" do
subject.sys.disable_auth("cert")

Expand Down

0 comments on commit 714a305

Please sign in to comment.