Пример #1
0
def test_user_token_repr_with_metadata():
    ut = UserToken(username='******',
                   email='*****@*****.**',
                   avatar='',
                   metadata={'foo': 'bar'})

    assert str(ut) == "crl: {'foo': 'bar'}"
Пример #2
0
def test_user_token_repr():
    ut = UserToken(username='******',
                   email='*****@*****.**',
                   avatar='',
                   metadata={})

    assert str(ut) == "crl: {}"
Пример #3
0
def test_user_token_repr_with_metadata():
    ut = UserToken(username='******',
                   email='*****@*****.**',
                   photo_url='',
                   app_meta={'foo': 'bar'})

    assert str(ut) == "I'am crl and have user permissions."
Пример #4
0
def test_only_match_allow_admin():
    ut = UserToken(username='******',
                   email='',
                   photo_url='',
                   app_meta={},
                   user_meta={},
                   admin=True,
                   staff=True,
                   scopes={
                       'users': {
                           'actions': ['w']
                       }
                   }).to_dict()

    pv = PermissionInspector(user={
        'req': 'staff',
        'match': 'min'
    },
                             rule={
                                 'path': 'scopes.users.actions',
                                 'op': 'in',
                                 'value': 'w'
                             },
                             allow_super=False)
    assert pv.verify(ut) is False
Пример #5
0
def test_user_token_from_dict():
    expected = UserToken(username='******',
                         email='*****@*****.**',
                         photo_url='',
                         app_meta={'foo': 'bar'})
    raw = {
        'username': '******',
        'email': '*****@*****.**',
        'avatar': '',
        'metadata': {
            'foo': 'bar'
        }
    }

    res = UserToken.from_dict(raw)
    assert res == expected
Пример #6
0
def test_get_permissions_user_2():
    ut = UserToken(username='******',
                   email='',
                   admin=False,
                   staff=False,
                   special='').to_dict()
    pv = PermissionInspector()

    assert pv.get_user_type(ut) == 'user'
Пример #7
0
def test_user_token_obj():
    ut = UserToken(username='******',
                   email='*****@*****.**',
                   avatar='',
                   metadata={})

    assert ut.username == 'crl'
    assert ut.email == '*****@*****.**'
    assert ut.avatar == ''
    assert ut.metadata == {}
Пример #8
0
 def verify(self, token: str):
     return UserToken('crl',
                      '*****@*****.**',
                      photo_url='',
                      app_meta={
                          'bar': 'foo'
                      },
                      scopes={
                          'bar': 'foo'
                      }).to_dict()
Пример #9
0
def test_user_token_obj():
    ut = UserToken(username='******',
                   email='*****@*****.**',
                   photo_url='',
                   app_meta={})

    assert ut.username == 'crl'
    assert ut.email == '*****@*****.**'
    assert ut.photo_url == ''
    assert ut.app_meta == {}
Пример #10
0
def test_allow_just_with_token():
    ut = UserToken(username='******',
                   email='',
                   photo_url='',
                   app_meta={},
                   user_meta={},
                   admin=False,
                   staff=False,
                   scopes={}).to_dict()

    pv = PermissionInspector(user={'req': 'user'}, rule={}, allow_super=False)
    assert pv.verify(ut) is True
Пример #11
0
def test_not_allow_if_user_is_not_set():
    ut = UserToken(username='******',
                   email='',
                   photo_url='',
                   app_meta={},
                   user_meta={},
                   admin=False,
                   staff=False,
                   scopes={}).to_dict()

    pv = PermissionInspector(user={}, rule={}, allow_super=False)
    assert pv.verify(ut) is False
Пример #12
0
def test_staff_need_permissions():
    ut = UserToken(username='******',
                   email='',
                   photo_url='',
                   app_meta={},
                   user_meta={},
                   admin=False,
                   staff=True,
                   scopes={}).to_dict()
    pv = PermissionInspector(user={'req': 'staff'},
                             rule={
                                 'path': 'scopes.users.actions',
                                 'op': 'in',
                                 'value': 'w'
                             },
                             allow_super=False)
    assert pv.verify(ut) is False
Пример #13
0
def test_admin_cannot_do_anything_if_is_not_allow():
    scopes = {'users': {'actions': ['w', 'r', 'd', 'u']}}
    ut = UserToken(username='******',
                   email='',
                   photo_url='',
                   app_meta={},
                   user_meta={},
                   admin=True,
                   staff=False,
                   scopes=scopes).to_dict()

    pv = PermissionInspector(user={'req': 'staff'},
                             rule={
                                 'path': 'scopes.users.actions',
                                 'op': 'in',
                                 'value': 'w'
                             },
                             allow_super=False)
    assert pv.verify(ut) is False
Пример #14
0
import pytest

from clean.request.inout.ports import Response, Request
from clean.use_case.case import BaseAuthUseCase
from clean.entities.token import UserToken


class ThisCaseNeedUserInfo(BaseAuthUseCase):

    def custom_process(self, req: Request, token: UserToken) -> Response:
        pass


def test_auth_use_case_raises_if_not_user_token_is_passed():

    with pytest.raises(AttributeError):
        ThisCaseNeedUserInfo(usr_token={})


def test_create_auth_use_case():
    case = ThisCaseNeedUserInfo(usr_token=UserToken('', '', ''))

    assert case.usr_token.username == ''
Пример #15
0
 def verify(self, token: str):
     return UserToken('crl',
                      '*****@*****.**',
                      avatar='',
                      metadata={'foo': 'bar'})
Пример #16
0
 def __init__(self, raw_token: str, kwargs_perm: Dict = None):
     self.raw_token = raw_token
     self.user_token = UserToken(username='', email='',
                                 photo_url='').to_dict()
     self.kwargs_perm = {} if kwargs_perm is None else kwargs_perm
Пример #17
0
 def __init__(self, raw_token: str, scopes_check=None, resp_err_fuc=None):
     self.scopes_check = scopes_check if scopes_check is not None else {}
     self.raw_token = raw_token
     self.user_token = UserToken(username='', email='', avatar='')
     self.resp_err_func = resp_err_fuc
Пример #18
0
def test_get_permissions_admin():
    ut = UserToken(username='******', email='', admin=True, staff=True,
                   special=1).to_dict()
    pv = PermissionInspector()

    assert pv.get_user_type(ut) == 'admin'