canaille-globuzma/tests/test_password_flow.py

30 lines
939 B
Python
Raw Normal View History

2020-08-19 08:28:28 +00:00
from . import client_credentials
2020-10-21 12:04:40 +00:00
from canaille.models import Token
2020-08-19 07:09:22 +00:00
2020-08-24 08:52:21 +00:00
def test_password_flow(testclient, slapd_connection, user, client):
2020-08-19 07:09:22 +00:00
res = testclient.post(
"/oauth/token",
2020-08-19 08:28:28 +00:00
params=dict(
2020-08-19 07:09:22 +00:00
grant_type="password",
username=user.name,
password="correct horse battery staple",
2020-08-19 07:09:22 +00:00
scope="profile",
),
2020-08-19 08:28:28 +00:00
headers={"Authorization": f"Basic {client_credentials(client)}"},
2020-08-19 07:09:22 +00:00
)
assert 200 == res.status_code
2020-08-20 12:30:42 +00:00
assert res.json["scope"] == "openid profile"
2020-08-19 07:09:22 +00:00
assert res.json["token_type"] == "Bearer"
access_token = res.json["access_token"]
2020-08-19 14:20:57 +00:00
token = Token.get(access_token, conn=slapd_connection)
2020-08-19 08:28:28 +00:00
assert token is not None
2020-09-25 09:26:41 +00:00
res = testclient.get(
"/oauth/userinfo", headers={"Authorization": f"Bearer {access_token}"}
)
2020-08-19 07:09:22 +00:00
assert 200 == res.status_code
2020-10-20 07:55:05 +00:00
assert {"name": "John Doe", "sub": "user", "family_name": "Doe"} == res.json