Skip to content

Commit

Permalink
Merge pull request #744 from cmanfre4/fix_auth_token_revoke_self
Browse files Browse the repository at this point in the history
Removed vestigial accessor parameter from auth token revoke_self
  • Loading branch information
jeffwecan committed Sep 22, 2021
2 parents 990e288 + 7830685 commit b77f296
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 12 deletions.
7 changes: 6 additions & 1 deletion docs/usage/auth_methods/token.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,17 @@ Token creation and revocation:
token = client.auth.token.create(policies=['root'], lease='1h')
current_token = client.auth.token.lookup()
current_token = client.auth.token.lookup_self()
some_other_token = client.auth.token.lookup('xxx')
client.auth.token.revoke('xxx')
client.auth.token.revoke('yyy', orphan=True)
# revoke current token
client.auth.token.revoke_self()
# logout and revoke current token
client.logout(revoke_token=True)
client.auth.token.renew('aaa')
Expand Down
10 changes: 2 additions & 8 deletions hvac/api/auth_methods/token.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,28 +342,22 @@ def revoke(self, token, mount_point=DEFAULT_MOUNT_POINT):
json=params,
)

def revoke_self(self, accessor, mount_point=DEFAULT_MOUNT_POINT):
def revoke_self(self, mount_point=DEFAULT_MOUNT_POINT):
"""Revoke the token used to call it and all child tokens.
When the token is revoked, all dynamic secrets generated with it are also revoked.
Supported methods:
POST: /auth/{mount_point}/revoke-self.
:param accessor: Accessor of the token.
:type accessor: str
:param mount_point: The "path" the method/backend was mounted on.
:type mount_point: str
:return: The response of the revoke_a_self request.
:rtype: requests.Response
"""
params = {
"accessor": accessor,
}
api_path = "/v1/auth/{mount_point}/revoke-self".format(mount_point=mount_point)
return self._adapter.post(
url=api_path,
json=params,
url=api_path
)

def revoke_accessor(self, accessor, mount_point=DEFAULT_MOUNT_POINT):
Expand Down
2 changes: 1 addition & 1 deletion hvac/v1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ def logout(self, revoke_token=False):
:rtype:
"""
if revoke_token:
self.revoke_self_token()
self.auth.token.revoke_self()

self.token = None

Expand Down
4 changes: 2 additions & 2 deletions tests/integration_tests/api/auth_methods/test_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ def test_self_auth_token_manipulation(self):
assert result["auth"]["client_token"]
self.client.token = result["auth"]["client_token"]

lookup = self.client.auth.token.lookup(result["auth"]["client_token"])
lookup = self.client.auth.token.lookup_self()
assert result["auth"]["client_token"] == lookup["data"]["id"]

renew = self.client.auth.token.renew_self()
assert result["auth"]["client_token"] == renew["auth"]["client_token"]

self.client.auth.token.revoke(lookup["data"]["id"])
self.client.auth.token.revoke_self()

try:
lookup = self.client.auth.token.lookup(result["auth"]["client_token"])
Expand Down
13 changes: 13 additions & 0 deletions tests/integration_tests/v1/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,19 @@ def test_client_logout(self):
self.client.logout()
assert not self.client.is_authenticated()

def test_client_logout_and_revoke(self):
# create a new token
result = self.client.auth.token.create(ttl="1h", renewable=True)
# set the token
self.client.token = result["auth"]["client_token"]

# logout and revoke the token
self.client.logout(revoke_token=True)
# set the original token back
self.client.token = result["auth"]["client_token"]
# confirm that it no longer is able to authenticate
assert not self.client.is_authenticated()

def test_revoke_self_token(self):
if "userpass/" in self.client.sys.list_auth_methods()["data"]:
self.client.sys.disable_auth_method("userpass")
Expand Down

0 comments on commit b77f296

Please sign in to comment.