2020-08-24 12:44:41 +00:00
|
|
|
from . import client_credentials
|
|
|
|
|
|
|
|
|
2020-08-24 12:47:55 +00:00
|
|
|
def test_token_introspection(testclient, user, client, token):
|
2020-08-24 12:44:41 +00:00
|
|
|
res = testclient.post(
|
|
|
|
"/oauth/introspect",
|
2021-09-28 07:30:41 +00:00
|
|
|
params=dict(token=token.oauthAccessToken,),
|
2020-08-24 12:44:41 +00:00
|
|
|
headers={"Authorization": f"Basic {client_credentials(client)}"},
|
2020-10-30 22:41:02 +00:00
|
|
|
status=200,
|
2020-08-24 12:44:41 +00:00
|
|
|
)
|
|
|
|
assert {
|
|
|
|
"active": True,
|
2020-09-07 13:39:51 +00:00
|
|
|
"client_id": client.oauthClientID,
|
2020-08-24 12:44:41 +00:00
|
|
|
"token_type": token.oauthTokenType,
|
|
|
|
"username": user.name,
|
|
|
|
"scope": token.get_scope(),
|
|
|
|
"sub": token.oauthSubject,
|
2020-09-07 13:39:51 +00:00
|
|
|
"aud": client.oauthClientID,
|
2020-08-24 12:44:41 +00:00
|
|
|
"iss": "https://mydomain.tld",
|
|
|
|
"exp": token.get_expires_at(),
|
|
|
|
"iat": token.get_issued_at(),
|
|
|
|
} == res.json
|
2020-08-24 12:47:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_token_invalid(testclient, client):
|
|
|
|
res = testclient.post(
|
|
|
|
"/oauth/introspect",
|
|
|
|
params=dict(token="invalid"),
|
|
|
|
headers={"Authorization": f"Basic {client_credentials(client)}"},
|
2020-10-30 22:41:02 +00:00
|
|
|
status=200,
|
2020-08-24 12:47:55 +00:00
|
|
|
)
|
2020-08-24 13:38:11 +00:00
|
|
|
assert {"active": False} == res.json
|