Пример #1
0
    def test_not_ok(self):
        auth_mixin = AuthMixin()

        auth_mixin.request = RequestMock(headers={})
        with self.assertRaises(ServiceAuthError) as cm:
            auth_mixin.get_access_token(require_auth=True)
        self.assertEqual(
            'HTTP 401: Authorization header missing (Authorization header is expected)',
            f'{cm.exception}')

        auth_mixin.request = RequestMock(
            headers={'Authorization': 'Beerer my_t0k3n'})
        with self.assertRaises(ServiceAuthError) as cm:
            auth_mixin.get_access_token()
        self.assertEqual(
            'HTTP 401: Invalid header (Authorization header must start with "Bearer")',
            f'{cm.exception}')

        auth_mixin.request = RequestMock(headers={'Authorization': 'Bearer'})
        with self.assertRaises(ServiceAuthError) as cm:
            auth_mixin.get_access_token()
        self.assertEqual('HTTP 401: Invalid header (Bearer token not found)',
                         f'{cm.exception}')

        auth_mixin.request = RequestMock(
            headers={'Authorization': 'Bearer my t0k3n'})
        with self.assertRaises(ServiceAuthError) as cm:
            auth_mixin.get_access_token()
        self.assertEqual(
            'HTTP 401: Invalid header (Authorization header must be Bearer token)',
            f'{cm.exception}')
Пример #2
0
 def test_ok_no_auth(self):
     auth_mixin = AuthMixin()
     auth_mixin.request = RequestMock(headers={})
     self.assertEqual(None, auth_mixin.get_access_token())
Пример #3
0
 def test_ok(self):
     auth_mixin = AuthMixin()
     auth_mixin.request = RequestMock(
         headers={'Authorization': 'Bearer my_t0k3n'})
     self.assertEqual('my_t0k3n', auth_mixin.get_access_token())