#!/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(
Esempio n. 2
0
    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()
Esempio n. 3
0
        json={
            'batch_type': 'accesses',
            'events': [
                {
                    'type': 'access.add'
                },
                {
                    'type': 'state.lifecycle'
                },
            ]
        },
        expected_status_code=400,
    )
    assert r.json()['details']['events'] != ''


with testContext():
    # Init 2 user sessions for creator rules testing
    s1 = get_authenticated_session(acr_values=2)
    s2 = get_authenticated_session(acr_values=2)

    print('--------\nBasics...')
    test_basics(s1, s2)

    print('--------\nMessages...')
    test_box_messages(s1, s2)

    print('--------\nAccesses...')
    test_accesses(s1, s2)
    print('All OK')
Esempio n. 4
0
    for event in event_list:
        assert 'id' in event
        assert 'server_event_created_at' in event
        assert 'type' in event
        assert 'content' in event

        sender = event['sender']
        assert sender['display_name'] == s.email
        assert sender['identifier']['value'] == s.email

    return box_id


with testContext():
    # Init 2 user sessions for creator rules testing
    s1 = get_authenticated_session()
    s2 = get_authenticated_session()

    box1_id = create_box_and_post_some_events_to_it(session=s1)
    # Testing posting event on unexisting box id
    r = s1.post(
        f'{URL_PREFIX}/boxes/457d5c70-03c2-4179-92a5-f945e666b922/events',
        json={
            'type': 'msg.text',
            'content': {
                'encrypted': b64encode(os.urandom(32)).decode(),
                'public_key': b64encode(os.urandom(32)).decode()
            }
        },
        expected_status_code=404)