Add endpoint handling to Token/Endpoint auth

This auth plugin was initially created before get_endpoint was
available. Implement the get_endpoint method so that we can use the
plugin with relative URLs.

Closes-Bug: #1323926
Change-Id: Ic868f509e708ad29faf86ec5ceeab2a9c98a24fc
This commit is contained in:
Jamie Lennox
2014-04-30 11:58:17 +10:00
parent 2a665aa3e7
commit 06fe38ad49
2 changed files with 22 additions and 0 deletions

View File

@@ -29,3 +29,11 @@ class Token(base.BaseAuthPlugin):
def get_token(self, session):
return self.token
def get_endpoint(self, session, **kwargs):
"""Return the supplied endpoint.
Using this plugin the same endpoint is returned regardless of the
parameters passed to the plugin.
"""
return self.endpoint

View File

@@ -33,3 +33,17 @@ class TokenEndpointTest(utils.TestCase):
self.assertEqual(data.text, 'body')
self.assertRequestHeaderEqual('X-Auth-Token', self.TEST_TOKEN)
@httpretty.activate
def test_basic_endpoint_case(self):
self.stub_url(httpretty.GET, ['p'], body='body')
a = token_endpoint.Token(self.TEST_URL, self.TEST_TOKEN)
s = session.Session(auth=a)
data = s.get('/p',
authenticated=True,
endpoint_filter={'service': 'identity'})
self.assertEqual(self.TEST_URL, a.get_endpoint(s))
self.assertEqual('body', data.text)
self.assertRequestHeaderEqual('X-Auth-Token', self.TEST_TOKEN)