Skip to content
This repository has been archived by the owner on Nov 15, 2022. It is now read-only.

Commit

Permalink
Merge pull request #8 from discogs/provide-separate-validate-url
Browse files Browse the repository at this point in the history
Provide separate validate url.
  • Loading branch information
zzsnzmn authored Feb 28, 2019
2 parents 9400de9 + f9db3d0 commit 03359df
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cas_client/_version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version_info__ = (0, 1, 4)
__version_info__ = (0, 1, 5)
__version__ = '.'.join(str(_) for _ in __version_info__)
20 changes: 16 additions & 4 deletions cas_client/cas_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def __init__(
self,
server_url,
service_url=None,
validate_url=None,
auth_prefix='/cas',
proxy_url=None,
proxy_callback=None,
Expand All @@ -42,6 +43,7 @@ def __init__(
self._proxy_url = proxy_url
self._server_url = server_url
self._service_url = service_url
self._validate_url = validate_url or server_url
self._session_storage_adapter = session_storage_adapter
self._verify_certificates = bool(verify_certificates)
self._headers = headers
Expand Down Expand Up @@ -398,22 +400,22 @@ def _get_proxy_url(self, ticket):
return url

def _get_proxy_validate_url(self, ticket):
template = '{server_url}{auth_prefix}/proxy?'
template = '{validate_url}{auth_prefix}/proxy?'
template += 'ticket={ticket}&service={proxy_callback}'
url = template.format(
auth_prefix=self.auth_prefix,
proxy_callback=self.proxy_callback,
server_url=self.server_url,
validate=self.validate_url,
ticket=ticket,
)
return url

def _get_service_validate_url(self, ticket, service_url=None):
template = '{server_url}{auth_prefix}/serviceValidate?'
template = '{validate_url}{auth_prefix}/serviceValidate?'
template += 'ticket={ticket}&service={service_url}'
url = template.format(
auth_prefix=self.auth_prefix,
server_url=self.server_url,
validate_url=self.validate_url,
service_url=service_url or self.service_url,
ticket=ticket,
)
Expand Down Expand Up @@ -507,6 +509,16 @@ def session_storage_adapter(self):
'''
return self._session_storage_adapter

@property
def validate_url(self):
'''
The CAS client's validation URL.
Defaults to the server_url, should only be set if using a separate
hostname for internal calls to /validateService.
'''
return self._validate_url

@property
def verify_certificates(self):
'''
Expand Down
30 changes: 30 additions & 0 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,36 @@ def test_perform_service_validate(self):
ticket='FOO',
service_url='BAR',
)
m.assert_called_once_with(
'https://dummy.url/cas/serviceValidate?ticket=FOO&service=BAR',
headers=None
)
self.assertTrue(response.success)
self.assertEqual(response.attributes, {
u'i2a2characteristics': u'0,3592,2000',
u'puid': u'0012345678',
u'firstname': u'Jeffrey A',
u'lastname': u'Ott',
u'fullname': u'Jeffrey A Ott',
u'email': u'[email protected]',
})
self.assertEqual(response.response_type, 'authenticationSuccess')
self.assertEqual(response.user, 'jott')

def test_perform_service_validate_separate_url(self):
cas_client = CASClient(
'https://dummy.url', validate_url='https://validate.url')
assert not cas_client.headers
with mock.patch('cas_client.CASClient._perform_get') as m:
m.return_value = self.response_text
response = cas_client.perform_service_validate(
ticket='FOO',
service_url='BAR',
)
m.assert_called_once_with(
'https://validate.url/cas/serviceValidate?ticket=FOO&service=BAR',
headers=None
)
self.assertTrue(response.success)
self.assertEqual(response.attributes, {
u'i2a2characteristics': u'0,3592,2000',
Expand Down

0 comments on commit 03359df

Please sign in to comment.