-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use Vonage JWT generator instead of PyJWT for requests
- Loading branch information
Showing
8 changed files
with
80 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ coverage: | |
coverage html | ||
|
||
test: | ||
pytest -v | ||
pytest -vv --disable-warnings | ||
|
||
clean: | ||
rm -rf dist build | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,12 @@ | ||
from util import * | ||
|
||
@responses.activate | ||
def test_getters(client, dummy_data): | ||
assert client.host() == dummy_data.host | ||
assert client.api_host() == dummy_data.api_host | ||
|
||
@responses.activate | ||
def test_setters(client, dummy_data): | ||
try: | ||
client.host('host.nexmo.com') | ||
client.api_host('host.nexmo.com') | ||
client.host('host.vonage.com') | ||
client.api_host('host.vonage.com') | ||
assert client.host() != dummy_data.host | ||
assert client.api_host() != dummy_data.api_host | ||
except: | ||
assert False | ||
|
||
@responses.activate | ||
def test_fail_setter_url_format(client, dummy_data): | ||
try: | ||
client.host('1000.1000') | ||
assert False | ||
except: | ||
assert True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from time import time | ||
from unittest.mock import patch | ||
|
||
now = int(time()) | ||
|
||
|
||
def test_auth_sets_claims_from_kwargs(client): | ||
client.auth(jti='asdfzxcv1234', nbf=now + 100, exp=now + 1000) | ||
assert client._jwt_claims['jti'] == 'asdfzxcv1234' | ||
assert client._jwt_claims['nbf'] == now + 100 | ||
assert client._jwt_claims['exp'] == now + 1000 | ||
|
||
|
||
def test_auth_sets_claims_from_dict(client): | ||
custom_jwt_claims = {'jti': 'asdfzxcv1234', 'nbf': now + 100, 'exp': now + 1000} | ||
client.auth(custom_jwt_claims) | ||
assert client._jwt_claims['jti'] == 'asdfzxcv1234' | ||
assert client._jwt_claims['nbf'] == now + 100 | ||
assert client._jwt_claims['exp'] == now + 1000 | ||
|
||
|
||
test_jwt = b'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJhcHBsaWNhdGlvbl9pZCI6ImFzZGYxMjM0IiwiaWF0IjoxNjg1NzMxMzkxLCJqdGkiOiIwYzE1MDJhZS05YmI5LTQ4YzQtYmQyZC0yOGFhNWUxYjZkMTkiLCJleHAiOjE2ODU3MzIyOTF9.mAkGeVgWOb7Mrzka7DSj32vSM8RaFpYse_2E7jCQ4DuH8i32wq9FxXGgfwdBQDHzgku3RYIjLM1xlVrGjNM3MsnZgR7ymQ6S4bdTTOmSK0dKbk91SrN7ZAC9k2a6JpCC2ZYgXpZ5BzpDTdy9BYu6msHKmkL79_aabFAhrH36Nk26pLvoI0-KiGImEex-aRR4iiaXhOebXBeqiQTRPKoKizREq4-8zBQv_j6yy4AiEYvBatQ8L_sjHsLj9jjITreX8WRvEW-G4TPpPLMaHACHTDMpJSOZAnegAkzTV2frVRmk6DyVXnemm4L0RQD1XZDaH7JPsKk24Hd2WZQyIgHOqQ' | ||
|
||
|
||
def vonage_jwt_mock(self, claims): | ||
return test_jwt | ||
|
||
|
||
def test_generate_application_jwt(client): | ||
with patch('vonage.client.JwtClient.generate_application_jwt', vonage_jwt_mock): | ||
jwt = client._generate_application_jwt() | ||
assert jwt == test_jwt | ||
|
||
|
||
def test_add_jwt_to_request_headers(client): | ||
with patch('vonage.client.JwtClient.generate_application_jwt', vonage_jwt_mock): | ||
headers = client._add_jwt_to_request_headers() | ||
assert headers['Accept'] == 'application/json' | ||
assert headers['Authorization'] == b'Bearer ' + test_jwt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters