async def test_set_password(self, user): client = Client(client_type='confidential', title='Test', user_id=user.id, password='******') assert set(asdict(client)) == { 'id', 'client_type', 'user_id', 'title', 'redirect_uris', 'crypt', 'salt', } assert client.salt assert client.crypt assert client.verify_password('123') assert not client.verify_password('12345') old_salt = client.salt old_crypt = client.crypt client.set_password('12345') assert client.salt != old_salt assert client.crypt != old_crypt assert client.verify_password('12345') assert not client.verify_password('123')
async def public_client_w_pass(store, user): yield await store.clients.put( Client(client_type='public', user_id=user.id, password='******', title='Test web client', redirect_uris=['http://localhost/feedback']))
async def test_has_password(self, user): client = Client( client_type='public', title='Test', user_id=user.id, ) assert not client.has_password() client.set_password('123') assert client.has_password() client.set_password(None) assert not client.has_password()
async def client(store, user, redirect_uri): logger.debug('Creating client') from bigur.auth.model import Client yield await store.clients.put( Client(client_type='confidential', user_id=user.id, title='Test web client', password='******', redirect_uris=[ redirect_uri, redirect_uri + '?foo=bar', redirect_uri + '?foo=bar&foo=baz', redirect_uri + '?foo=bar#baz=xyz', ]))
async def test_redirect_uri(self, user): client = Client(client_type='confidential', title='Test', user_id=user.id, password='******') assert client.redirect_uris is None assert not client.check_redirect_uri('http://localhost/back') client.redirect_uris = ['http://localhost/back', 'https://bigur.com'] assert client.check_redirect_uri('http://localhost/back') assert not client.check_redirect_uri('https://gmail.com/')
async def test_miss_confidential_password(self, user): with raises(TypeError) as ei: Client(client_type='confidential', title='Test', user_id=user.id) assert ei.value.args[0] == ('Password is required for ' 'confidential clients')
async def test_incorrect_client_type(self, user): with raises(TypeError) as ei: Client(client_type='some_type', title='Test', user_id=user.id) assert ei.value.args[0] == 'Client type must be public or confidential'
async def create(self, **kwargs) -> Client: client = Client(**kwargs) await self.put(client) return client