canaille-globuzma/tests/test_password_flow.py

28 lines
863 B
Python
Raw Normal View History

2020-08-19 08:28:28 +00:00
from . import client_credentials
from web.models import Token
2020-08-19 07:09:22 +00:00
2020-08-19 08:28:28 +00:00
def test_success(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
assert res.json["scope"] == ["openid", "profile"]
assert res.json["token_type"] == "Bearer"
access_token = res.json["access_token"]
2020-08-19 08:28:28 +00:00
token = Token.get(access_token, slapd_connection)
assert token is not None
res = testclient.get("/api/me", headers={"Authorization": f"Bearer {access_token}"})
2020-08-19 07:09:22 +00:00
assert 200 == res.status_code
assert {"foo": "bar"} == res.json