File: test_oauth2_revoke_token.py

package info (click to toggle)
python-globus-sdk 4.3.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,144 kB
  • sloc: python: 35,242; sh: 37; makefile: 35
file content (49 lines) | stat: -rw-r--r-- 1,337 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import urllib.parse
import uuid

import pytest

import globus_sdk
from globus_sdk.testing import get_last_request, load_response


@pytest.fixture
def client_id():
    return str(uuid.uuid4())


@pytest.fixture
def base_client(client_id):
    return globus_sdk.AuthLoginClient(client_id=client_id)


@pytest.fixture
def confidential_client(client_id):
    return globus_sdk.ConfidentialAppAuthClient(
        client_id=client_id, client_secret="somesecret"
    )


def test_oauth2_revoke_token_works(client_id, base_client):
    load_response(base_client.oauth2_revoke_token)
    response = base_client.oauth2_revoke_token("sometoken")
    assert response["active"] is False
    lastreq = get_last_request()
    body = lastreq.body
    assert body != ""
    parsed_body = urllib.parse.parse_qs(body)
    assert parsed_body == {"token": ["sometoken"], "client_id": [client_id]}


def test_oauth2_revoke_token_does_not_send_client_id_when_authenticated(
    client_id,
    confidential_client,
):
    load_response(confidential_client.oauth2_revoke_token)
    response = confidential_client.oauth2_revoke_token("sometoken")
    assert response["active"] is False
    lastreq = get_last_request()
    body = lastreq.body
    assert body != ""
    parsed_body = urllib.parse.parse_qs(body)
    assert parsed_body == {"token": ["sometoken"]}