From f7d161fcb6f111d0dc36b8d6252c0d7061bbc5ae Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sun, 16 Apr 2017 10:20:52 +0300 Subject: Start on functions to check authentication --- distixapi/__init__.py | 1 + distixapi/authn.py | 18 ++++++++++++++++++ distixapi/authn_tests.py | 11 +++++++++++ 3 files changed, 30 insertions(+) create mode 100644 distixapi/authn.py create mode 100644 distixapi/authn_tests.py diff --git a/distixapi/__init__.py b/distixapi/__init__.py index 03a5053..d860521 100644 --- a/distixapi/__init__.py +++ b/distixapi/__init__.py @@ -1 +1,2 @@ from .version import __version__, __version_info__ +from .authn import AuthenticationError, get_credentials diff --git a/distixapi/authn.py b/distixapi/authn.py new file mode 100644 index 0000000..53816b6 --- /dev/null +++ b/distixapi/authn.py @@ -0,0 +1,18 @@ +# Functions for checking authantication for API clients. + + +def get_credentials(request): + '''Return username, password of API client. + + They're assumed to be conveyed in an Authorization header using + Basic Auth. + + ''' + + raise AuthenticationError('No Authorization header') + + + +class AuthenticationError(Exception): + + pass diff --git a/distixapi/authn_tests.py b/distixapi/authn_tests.py new file mode 100644 index 0000000..2a220ab --- /dev/null +++ b/distixapi/authn_tests.py @@ -0,0 +1,11 @@ +import unittest + +import distixapi + + +class GetCredentialsTests(unittest.TestCase): + + def test_raises_error_if_no_Authentication_header(self): + request = {} + with self.assertRaises(distixapi.AuthenticationError): + distixapi.get_credentials(request) -- cgit v1.2.1