Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Identity,
User,
Optional[User],
Optional[Identity]
])
def test_identity_binder_by_param_type(annotation_type):
async def handler(param):
...
handler.__annotations__['param'] = annotation_type
binders = get_binders(Route(b'/', handler), {})
assert isinstance(binders[0], IdentityBinder)
def __init__(self, identity=None):
if identity is None:
identity = Identity({
'id': '001',
'name': 'Charlie Brown'
}, 'JWT')
self.identity = identity
async def test_authorization_policy_success():
app = FakeApplication()
admin = Identity({
'id': '001',
'name': 'Charlie Brown',
'role': 'admin'
}, 'JWT')
app.use_authentication()\
.add(MockAuthHandler(admin))
app.use_authorization()\
.add(AdminsPolicy())
@auth('admin')
@app.router.get(b'/')
async def home():
return None
async def authenticate(self, context: Any) -> Optional[Identity]:
context.identity = Identity({
'id': '007',
}) # NB: an identity without authentication scheme is treated as anonymous identity
return context.identity
async def authenticate(self, context: Any) -> Optional[Identity]:
context.identity = Identity({
'id': '007',
}) # NB: an identity without authentication scheme is treated as anonymous identity
return context.identity
def __init__(self):
super().__init__('identity', Identity)