#!/usr/bin/env python3 import argparse import sys from misapy.get_access_token import get_credentials from misapy.test_context import testContext parser = argparse.ArgumentParser() parser.add_argument('--email') parser.add_argument('--acr') parser.add_argument('--require-account', dest='require_account', action='store_true') args = parser.parse_args() # TODO extract error mgmt out of "testContext" because it's not really a test here with testContext(): creds = get_credentials(args.email, args.require_account, args.acr) print('email:', creds.email) print('acr_values:', args.acr) print('identity_id:', creds.identity_id) if creds.account_id: print('account_id:', creds.account_id) print('consent has been done' if creds.consent_done else 'no consent required') print('access token:', creds.access_token) print('id token:', creds.id_token)
#!/usr/bin/env python3 import os from base64 import b64encode, urlsafe_b64encode from misapy.get_access_token import get_authenticated_session from misapy.test_context import testContext from misapy.check_response import check_response, assert_fn with testContext('Normal scenario'): s = get_authenticated_session(require_account=True) backup_key_share = { 'share': b64encode(os.urandom(16)).decode(), 'other_share_hash': urlsafe_b64encode(os.urandom(16)).decode().rstrip('='), 'account_id': s.account_id, 'salt_base64': b64encode(os.urandom(16)).decode(), } r = s.post( 'https://api.misakey.com.local/backup-key-shares', json=backup_key_share, ) check_response( r, [ lambda r: assert_fn(r.json() == backup_key_share) ] ) r = s.get(
proc.check_returncode() output = proc.stdout.decode() archived_backup = output.strip() return archived_backup def get_current_backup(account_id): proc = subprocess.run( ('docker exec test-and-run_api_db_1 psql -t -d sso -U misakey -h localhost -c' .split() + ["SELECT backup_data " "FROM account " f"WHERE id = '{account_id}' "]), capture_output=True, ) proc.check_returncode() output = proc.stdout.decode() current_backup = output.strip() return current_backup with testContext('Backup Archives'): # We create an account, and then we reset its password creds = get_credentials(require_account=True) s = get_authenticated_session(email=creds.email, reset_password=True) archived_backup = get_archived_backup(creds.account_id) assert archived_backup == b64encode(b'fake backup data').decode() current_backup = get_current_backup(creds.account_id) assert current_backup == b64encode(b'other fake backup data').decode()
#!/usr/bin/env python3 from misapy import http, URL_PREFIX from misapy.box_helpers import create_add_invitation_link_event from misapy.check_response import check_response, assert_fn from misapy.get_access_token import get_authenticated_session from misapy.box_members import join_box from misapy.test_context import testContext with testContext('init invitation changing link test'): s1 = get_authenticated_session(acr_values=2) s2 = get_authenticated_session(acr_values=2) # create a box r = s1.post( f'{URL_PREFIX}/boxes', json={ 'public_key': 'ShouldBeUnpaddedUrlSafeBase64', 'title': 'Test Box', }, ) box_id = r.json()['id'] # a invitation link access to it s1.post( f'{URL_PREFIX}/boxes/{box_id}/batch-events', json={ 'batch_type': 'accesses', 'events': [create_add_invitation_link_event()], }, ) # retrieve the corresponding access id and join the box
def get_current_backup(account_id): proc = subprocess.run( ('docker exec test-and-run_api_db_1 psql -t -d sso -U misakey -h localhost -c' .split() + ["SELECT backup_data " "FROM account " f"WHERE id = '{account_id}' "]), capture_output=True, ) proc.check_returncode() output = proc.stdout.decode() current_backup = output.strip() return current_backup with testContext('archive creation'): # We create an account, and then we reset its password creds = get_credentials(require_account=True) s = get_authenticated_session(email=creds.email, reset_password=True) archived_backup = get_archived_backup(creds.account_id) assert archived_backup == b64encode(b'fake backup data').decode() current_backup = get_current_backup(creds.account_id) assert current_backup == b64encode(b'other fake backup data').decode() r = s.get('https://api.misakey.com.local/backup-archives') assert len(r.json()) == 1 archive_id = r.json()[0]['id'] r = s.get(
"INSERT INTO crypto_action", "(id, account_id, sender_identity_id, type, box_id, encryption_public_key, encrypted)", "VALUES", f"('{uuid4()}', '{owner.account_id}', '{owner.identity_id}',", f"'invitation', '{box_id}', '{fake_data}', '{fake_data}') " ]) proc = subprocess.run( ('docker exec test-and-run_api_db_1 psql -t -d sso -U misakey -h localhost -c' .split() + [sql_command]), capture_output=True, ) proc.check_returncode() with testContext('Listing one\'s actions'): s1 = get_authenticated_session(require_account=True) s2 = get_authenticated_session(require_account=True) r = s2.post(f'{URL_PREFIX}/boxes', json={ 'public_key': 'ShouldBeUnpaddedUrlSafeBase64', 'title': 'Test Box', }) box_id = r.json()['id'] for i in range(5): create_crypto_action(s1, s2, box_id, f'Fake Data Action {i}') r = s1.get(f'{URL_PREFIX}/accounts/{s1.account_id}/crypto/actions') check_response(r, [lambda r: assert_fn(len(r.json()) == 5)])