async def test_registration_with_confirmation(client, capsys): db = cfg.STORAGE url = url_for('auth_registration') r = await client.get(url) r = await client.post(url, data={ 'email': EMAIL, 'password': PASSWORD, 'confirm': PASSWORD, 'csrf_token': await get_csrf(r), }) assert r.status == 200 assert r.url_obj.path == str(url_for('auth_registration_requested')) user = await db.get_user({'email': EMAIL}) assert user['status'] == 'confirmation' out, err = capsys.readouterr() link = parse_link(out) r = await client.get(link) assert r.url_obj.path == str(url_for(cfg.LOGIN_REDIRECT)) assert cfg.MSG_ACTIVATED in await r.text() assert cfg.MSG_LOGGED_IN in await r.text() user = await db.get_user({'email': EMAIL}) assert user['status'] == 'active' user = await db.get_user({'email': EMAIL}) await db.delete_user(user)
def get_share_data(share_link): user, share_id = parse_link(share_link) if user == None: raise InvalidShareUrlError(share_link) api_url = f'https://taskernet.com/_ah/api/datashare/v1/shares/{user}/{share_id}' resp = requests.get(api_url) if resp.status_code == 404: raise ShareDoesNotExistError(api_url) elif resp.status_code != 200: raise GenericError(api_url) return resp.json()
def get_tasker_data(share_link): user, share_id = parse_link(share_link) if user == None: raise InvalidShareUrlError(share_link) api_url = f'https://taskernet.com/_ah/api/datashare/v1/sharedata/{user}/{share_id}' resp = requests.get(api_url) if resp.status_code == 404: raise ShareDoesNotExistError(api_url) elif resp.status_code != 200: raise GenericError(api_url) share_data = resp.json()['shareData'] share_type, encoded = share_data.split('://') decoded = base64.b64decode(encoded) tasker_data = gzip.decompress(decoded).decode('utf-8') return tasker_data
async def test_reset_and_confirm(client, capsys): url = url_for('auth_reset_password') login_url = url_for('auth_login') r = await client.get(url) async with NewUser() as user: r = await client.post(url, data={ 'email': user['email'], 'csrf_token': await get_csrf(r), }) assert r.status == 200 assert r.url_obj.path == url_for('auth_reset_password_requested').path out, err = capsys.readouterr() confirmation_url = parse_link(out) r = await client.get(confirmation_url) assert r.status == 200 new_password = get_random_string(10) r = await client.post(confirmation_url, data={ 'password': new_password, 'confirm': new_password, 'csrf_token': await get_csrf(r), }) assert r.status == 200 assert r.url_obj.path == url_for(cfg.LOGIN_REDIRECT).path assert cfg.MSG_PASSWORD_CHANGED in await r.text() assert cfg.MSG_LOGGED_IN in await r.text() r = await client.get(url_for('auth_logout')) assert r.status == 200 assert r.url_obj.path == login_url.path r = await client.post(login_url, data={ 'email': user['email'], 'password': new_password, 'csrf_token': await get_csrf(r), }) assert r.status == 200 assert r.url_obj.path == url_for(cfg.LOGIN_REDIRECT).path assert cfg.MSG_LOGGED_IN in await r.text()
def add_share(self, share_link, source_link): user, share_id = utils.parse_link(share_link) object_id = utils.share_object_id(user=user, share_id=share_id) if object_id == None: logging.warning( f'Invalid share link: {share_link} at {source_link}') return False existing_object = self.get_share_by_id(object_id) try: share_data = api.get_share_data(share_link) tasker_data = api.get_tasker_data(share_link) except api.ShareDoesNotExistError: # Share link is removed. Delete any stored record if existing_object != None: self.shares_index.delete_object(object_id) return True except api.GenericError: logging.warning(f'Error when adding: {share_link}, {source_link}') return False # Check if the share description has a tag to ignore this share. Delete any stored record if utils.COLLECTOR_IGNORE_RE.search(share_data['info']['description']): if existing_object != None: self.shares_index.delete_object(object_id) return True # Add this source link to existing source links if any source_links = [source_link] if existing_object != None and 'sourceLinks' in existing_object: source_links.extend(existing_object['sourceLinks']) source_links = list(set(source_links)) try: tags, names, plugin_packages = utils.parse_tasker_data(tasker_data) except: logging.warning(f'Error when parsing tasker data: {share_link}') return False for package in plugin_packages: if plugin := self.get_plugin(package): tags.append(plugin['appName'])
async def test_cnange_and_confirm(client, capsys): url = url_for('auth_change_email') login_url = url_for('auth_login') r = await client.get(url) async with LoggedUser(client) as user: r = await client.post(url, data={ 'email': NEW_EMAIL, 'csrf_token': await get_csrf(r), }) assert r.status == 200 assert r.url_obj.path == url.path assert cfg.MSG_CHANGE_EMAIL_REQUESTED in await r.text() out, err = capsys.readouterr() link = parse_link(out) r = await client.get(link) assert r.status == 200 assert r.url_obj.path == url.path assert cfg.MSG_EMAIL_CHANGED in await r.text() r = await client.get(url_for('auth_logout')) assert r.status == 200 assert r.url_obj.path == login_url.path r = await client.post(login_url, data={ 'email': NEW_EMAIL, 'password': user['raw_password'], 'csrf_token': await get_csrf(r), }) assert r.status == 200 assert r.url_obj.path == url_for(cfg.LOGIN_REDIRECT).path assert cfg.MSG_LOGGED_IN in await r.text()