Esempio n. 1
0
def test_client_can_make_application_requests_without_api_key(dummy_data):
    stub(responses.POST, "https://api.nexmo.com/v1/calls")

    client = nexmo.Client(application_id="myid",
                          private_key=dummy_data.private_key)
    voice = nexmo.Voice(client)
    voice.create_call("123455")
Esempio n. 2
0
def test_user_provided_authorization(client, dummy_data):
    stub(responses.GET, "https://api.nexmo.com/v1/calls/xx-xx-xx-xx")

    application_id = "different-nexmo-application-id"
    nbf = int(time.time())
    exp = nbf + 3600

    client.auth(application_id=application_id, nbf=nbf, exp=exp)
    voice = nexmo.Voice(client)
    voice.get_call("xx-xx-xx-xx")

    token = request_authorization().split()[1]

    token = jwt.decode(token, dummy_data.public_key, algorithm="RS256")

    assert token["application_id"] == application_id
    assert token["nbf"] == nbf
    assert token["exp"] == exp
Esempio n. 3
0
def test_authorization_with_private_key_path(dummy_data):
    stub(responses.GET, "https://api.nexmo.com/v1/calls/xx-xx-xx-xx")

    private_key = os.path.join(os.path.dirname(__file__),
                               "data/private_key.txt")

    client = nexmo.Client(
        key=dummy_data.api_key,
        secret=dummy_data.api_secret,
        application_id=dummy_data.application_id,
        private_key=private_key,
    )
    voice = nexmo.Voice(client)
    voice.get_call("xx-xx-xx-xx")

    token = jwt.decode(request_authorization().split()[1],
                       dummy_data.public_key,
                       algorithm="RS256")
    assert token["application_id"] == dummy_data.application_id
Esempio n. 4
0
def voice(client, dummy_data):
    import nexmo

    return nexmo.Voice(client)