コード例 #1
0
def test_parse_endpoint_success(client, skill_dir):
    test_request = {'text': 'hi', 'challenge': 'a challenge'}

    key = load_public_key(get_file_contents(os.path.join(skill_dir, 'id_rsa.pub')))
    secret = 'some secret'
    encrypted_msg = encrypt(message=json.dumps(test_request), public_key=key)
    signature = generate_signature(secret, json.dumps(test_request))
    response = client.post(
        '/parse',
        data=encrypted_msg,
        content_type='text',
        headers={'X-Webex-Assistant-Signature': signature},
        follow_redirects=True,
    )
    assert response.status_code == 200
    response_data = json.loads(response.data.decode('utf8'))
    assert response_data['dialogue_state'] == 'welcome'
    assert response_data['challenge'] == 'a challenge'
    # Use >= set comparison as newer versions of mindmeld may add fields
    assert set(response_data.keys()) >= {
        'history',
        'params',
        'frame',
        'dialogue_state',
        'request_id',
        'response_time',
        'request',
        'directives',
        'slots',
        'challenge',
    }
コード例 #2
0
def test_health_endpoint_check_failed(client, skill_dir):
    key = load_public_key(get_file_contents(os.path.join(skill_dir, 'id_rsa.pub')))
    secret = 'wrong secret'
    challenge = 'challenge'
    encrypted_challenge = encrypt(message=challenge, public_key=key)
    signature = generate_signature(secret, challenge)
    response = client.get(
        f'/parse?challenge={quote(encrypted_challenge)}',
        headers={'X-Webex-Assistant-Signature': signature},
    )

    assert response.status_code == 400
    response_data = json.loads(response.data.decode('utf8'))

    assert response_data == {'status': 'error', 'error': 'Invalid signature', 'api_version': '1.0'}
コード例 #3
0
def _public_key(keys_dir):
    key_data = get_file_contents(os.path.join(keys_dir, 'id_rsa.pub'))
    public_key = load_public_key(key_data)
    return public_key
コード例 #4
0
def _private_key(keys_dir):
    key_data = get_file_contents(os.path.join(keys_dir, 'id_rsa'))
    private_key = load_private_key(key_data)
    return private_key
コード例 #5
0
def test_load_public_key(key_type, keys_dir):
    key_data = get_file_contents(os.path.join(keys_dir, f'{key_type}.pub'))
    public_key = load_public_key(key_data)

    assert public_key
コード例 #6
0
def test_load_private_key(key_type, keys_dir, passphrase):
    key_data = get_file_contents(os.path.join(keys_dir, key_type))
    password = passphrase if key_type.endswith('.encrypted') else None
    private_key = load_private_key(key_data, password=password)

    assert private_key