Skip to content
Snippets Groups Projects
Commit 31c11af0 authored by Jan Mach's avatar Jan Mach
Browse files

Merged blueprints auth_api

(Redmine issue: #7544)
parent a8dd4518
No related branches found
No related tags found
No related merge requests found
...@@ -55,11 +55,11 @@ import flask_principal ...@@ -55,11 +55,11 @@ import flask_principal
from flask_babel import gettext, lazy_gettext from flask_babel import gettext, lazy_gettext
import hawat.const import hawat.const
import vial.forms import hawat.forms
import vial.db import hawat.db
from vial.app import VialBlueprint from hawat.app import HawatBlueprint
from vial.view import ItemChangeView from hawat.view import ItemChangeView
from vial.view.mixin import HTMLMixin, SQLAlchemyMixin from hawat.view.mixin import HTMLMixin, SQLAlchemyMixin
BLUEPRINT_NAME = 'auth_api' BLUEPRINT_NAME = 'auth_api'
...@@ -107,7 +107,7 @@ class GenerateKeyView(HTMLMixin, SQLAlchemyMixin, ItemChangeView): # pylint: di ...@@ -107,7 +107,7 @@ class GenerateKeyView(HTMLMixin, SQLAlchemyMixin, ItemChangeView): # pylint: di
permission_me = flask_principal.Permission( permission_me = flask_principal.Permission(
flask_principal.UserNeed(kwargs['item'].id) flask_principal.UserNeed(kwargs['item'].id)
) )
return vial.acl.PERMISSION_POWER.can() or permission_me.can() return hawat.acl.PERMISSION_POWER.can() or permission_me.can()
@staticmethod @staticmethod
def get_message_success(**kwargs): def get_message_success(**kwargs):
...@@ -180,7 +180,7 @@ class DeleteKeyView(HTMLMixin, SQLAlchemyMixin, ItemChangeView): # pylint: disa ...@@ -180,7 +180,7 @@ class DeleteKeyView(HTMLMixin, SQLAlchemyMixin, ItemChangeView): # pylint: disa
permission_me = flask_principal.Permission( permission_me = flask_principal.Permission(
flask_principal.UserNeed(kwargs['item'].id) flask_principal.UserNeed(kwargs['item'].id)
) )
return vial.acl.PERMISSION_POWER.can() or permission_me.can() return hawat.acl.PERMISSION_POWER.can() or permission_me.can()
@staticmethod @staticmethod
def get_message_success(**kwargs): def get_message_success(**kwargs):
...@@ -211,7 +211,7 @@ class DeleteKeyView(HTMLMixin, SQLAlchemyMixin, ItemChangeView): # pylint: disa ...@@ -211,7 +211,7 @@ class DeleteKeyView(HTMLMixin, SQLAlchemyMixin, ItemChangeView): # pylint: disa
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
class APIAuthBlueprint(VialBlueprint): class APIAuthBlueprint(HawatBlueprint):
"""Pluggable module - API key authentication service (*auth_api*).""" """Pluggable module - API key authentication service (*auth_api*)."""
@classmethod @classmethod
...@@ -255,7 +255,7 @@ class APIAuthBlueprint(VialBlueprint): ...@@ -255,7 +255,7 @@ class APIAuthBlueprint(VialBlueprint):
# Now login the user with provided API key. # Now login the user with provided API key.
if api_key: if api_key:
dbsess = vial.db.db_session() dbsess = hawat.db.db_session()
try: try:
user = dbsess.query(user_model).filter(user_model.apikey == api_key).one() user = dbsess.query(user_model).filter(user_model.apikey == api_key).one()
if user: if user:
...@@ -284,8 +284,8 @@ class APIAuthBlueprint(VialBlueprint): ...@@ -284,8 +284,8 @@ class APIAuthBlueprint(VialBlueprint):
def get_blueprint(): def get_blueprint():
""" """
Mandatory interface for :py:mod:`vial.Vial` and factory function. This function Mandatory interface for :py:mod:`hawat.Hawat` and factory function. This function
must return a valid instance of :py:class:`vial.app.VialBlueprint` or must return a valid instance of :py:class:`hawat.app.HawatBlueprint` or
:py:class:`flask.Blueprint`. :py:class:`flask.Blueprint`.
""" """
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
""" """
Unit tests for :py:mod:`vial.blueprints.auth_api`. Unit tests for :py:mod:`hawat.blueprints.auth_api`.
""" """
...@@ -14,18 +14,18 @@ import sys ...@@ -14,18 +14,18 @@ import sys
import unittest import unittest
import hawat.const import hawat.const
import vial.test import hawat.test
import vial.db import hawat.db
from vial.test import VialTestCase from hawat.test import HawatTestCase
from vial.test.runner import TestRunnerMixin from hawat.test.runner import TestRunnerMixin
_IS_NOSE = sys.argv[0].endswith('nosetests') _IS_NOSE = sys.argv[0].endswith('nosetests')
@unittest.skipIf(_IS_NOSE, "broken under nosetest") @unittest.skipIf(_IS_NOSE, "broken under nosetest")
class AuthAPITestCase(TestRunnerMixin, VialTestCase): class AuthAPITestCase(TestRunnerMixin, HawatTestCase):
""" """
Class for testing :py:mod:`vial.blueprints.auth_api` blueprint. Class for testing :py:mod:`hawat.blueprints.auth_api` blueprint.
""" """
def _req_key_generate(self, uid, status_code, confirm = False): def _req_key_generate(self, uid, status_code, confirm = False):
...@@ -133,7 +133,7 @@ class AuthAPITestCase(TestRunnerMixin, VialTestCase): ...@@ -133,7 +133,7 @@ class AuthAPITestCase(TestRunnerMixin, VialTestCase):
self.assertTrue(b'My account' in response.data) self.assertTrue(b'My account' in response.data)
self.assertTrue(b'data-user-name="admin"' in response.data) self.assertTrue(b'data-user-name="admin"' in response.data)
@vial.test.do_as_user_decorator(hawat.const.ROLE_USER) @hawat.test.do_as_user_decorator(hawat.const.ROLE_USER)
def test_02_keymng_user(self): def test_02_keymng_user(self):
""" """
Test, that 'user' can manage only his own API key. Test, that 'user' can manage only his own API key.
...@@ -142,7 +142,7 @@ class AuthAPITestCase(TestRunnerMixin, VialTestCase): ...@@ -142,7 +142,7 @@ class AuthAPITestCase(TestRunnerMixin, VialTestCase):
self._test_keymng_failure(hawat.const.ROLE_DEVELOPER) self._test_keymng_failure(hawat.const.ROLE_DEVELOPER)
self._test_keymng_failure(hawat.const.ROLE_ADMIN) self._test_keymng_failure(hawat.const.ROLE_ADMIN)
@vial.test.do_as_user_decorator(hawat.const.ROLE_DEVELOPER) @hawat.test.do_as_user_decorator(hawat.const.ROLE_DEVELOPER)
def test_03_keymng_developer(self): def test_03_keymng_developer(self):
""" """
Test, that 'developer' can manage only his own API key. Test, that 'developer' can manage only his own API key.
...@@ -151,7 +151,7 @@ class AuthAPITestCase(TestRunnerMixin, VialTestCase): ...@@ -151,7 +151,7 @@ class AuthAPITestCase(TestRunnerMixin, VialTestCase):
self._test_keymng_success(hawat.const.ROLE_DEVELOPER) self._test_keymng_success(hawat.const.ROLE_DEVELOPER)
self._test_keymng_failure(hawat.const.ROLE_ADMIN) self._test_keymng_failure(hawat.const.ROLE_ADMIN)
@vial.test.do_as_user_decorator(hawat.const.ROLE_ADMIN) @hawat.test.do_as_user_decorator(hawat.const.ROLE_ADMIN)
def test_04_keymng_admin(self): def test_04_keymng_admin(self):
""" """
Test, that 'admin' user is able to manage all API keys. Test, that 'admin' user is able to manage all API keys.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment