| 1 |
import urllib.parse |
| 2 |
import uuid |
| 3 |
|
| 4 |
import pytest |
| 5 |
|
| 6 |
import globus_sdk |
| 7 |
from globus_sdk.testing import get_last_request, load_response |
| 8 |
|
| 9 |
|
| 10 |
@pytest.fixture |
| 11 |
def client_id(): |
| 12 |
return str(uuid.uuid4()) |
| 13 |
|
| 14 |
|
| 15 |
@pytest.fixture |
| 16 |
def base_client(client_id): |
| 17 |
return globus_sdk.AuthLoginClient(client_id=client_id) |
| 18 |
|
| 19 |
|
| 20 |
@pytest.fixture |
| 21 |
def confidential_client(client_id): |
| 22 |
return globus_sdk.ConfidentialAppAuthClient( |
| 23 |
client_id=client_id, client_secret="somesecret" |
| 24 |
) |
| 25 |
|
| 26 |
|
| 27 |
def test_oauth2_revoke_token_works(client_id, base_client): |
| 28 |
load_response(base_client.oauth2_revoke_token) |
| 29 |
response = base_client.oauth2_revoke_token("sometoken") |
| 30 |
assert response["active"] is False |
| 31 |
lastreq = get_last_request() |
| 32 |
body = lastreq.body |
| 33 |
assert body != "" |
| 34 |
parsed_body = urllib.parse.parse_qs(body) |
| 35 |
assert parsed_body == {"token": ["sometoken"], "client_id": [client_id]} |
| 36 |
|
| 37 |
|
| 38 |
def test_oauth2_revoke_token_does_not_send_client_id_when_authenticated( |
| 39 |
client_id, |
| 40 |
confidential_client, |
| 41 |
): |
| 42 |
load_response(confidential_client.oauth2_revoke_token) |
| 43 |
response = confidential_client.oauth2_revoke_token("sometoken") |
| 44 |
assert response["active"] is False |
| 45 |
lastreq = get_last_request() |
| 46 |
body = lastreq.body |
| 47 |
assert body != "" |
| 48 |
parsed_body = urllib.parse.parse_qs(body) |
| 49 |
assert parsed_body == {"token": ["sometoken"]} |