File: test_rfc7662.py

package info (click to toggle)
python-authlib 1.6.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 3,024 kB
  • sloc: python: 27,284; makefile: 53; sh: 14
file content (61 lines) | stat: -rw-r--r-- 1,538 bytes parent folder | download | duplicates (2)
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
50
51
52
53
54
55
56
57
58
59
60
61
import pytest

from authlib.oauth2.rfc7662 import IntrospectionToken


def test_client_id():
    token = IntrospectionToken()
    assert token.client_id is None
    assert token.get_client_id() is None

    token = IntrospectionToken({"client_id": "foo"})
    assert token.client_id == "foo"
    assert token.get_client_id() == "foo"


def test_scope():
    token = IntrospectionToken()
    assert token.scope is None
    assert token.get_scope() is None

    token = IntrospectionToken({"scope": "foo"})
    assert token.scope == "foo"
    assert token.get_scope() == "foo"


def test_expires_in():
    token = IntrospectionToken()
    assert token.get_expires_in() == 0


def test_expires_at():
    token = IntrospectionToken()
    assert token.exp is None
    assert token.get_expires_at() == 0

    token = IntrospectionToken({"exp": 3600})
    assert token.exp == 3600
    assert token.get_expires_at() == 3600


def test_all_attributes():
    # https://tools.ietf.org/html/rfc7662#section-2.2
    token = IntrospectionToken()
    assert token.active is None
    assert token.scope is None
    assert token.client_id is None
    assert token.username is None
    assert token.token_type is None
    assert token.exp is None
    assert token.iat is None
    assert token.nbf is None
    assert token.sub is None
    assert token.aud is None
    assert token.iss is None
    assert token.jti is None


def test_invalid_attr():
    token = IntrospectionToken()
    with pytest.raises(AttributeError):
        token.invalid  # noqa:B018