A fully functional OAUTH2 / OpenID Connect server to be used in your testsuite
Project description
pytest-iam
pytest-iam spawns a lightweight OAuth2 / OpenID Server in a thread to be used in your test suite. The machinery involves Canaille and Authlib.
Installation
pip install pytest-iam
Usage
pytest-iam provides a iam_server
fixture that comes with several features:
iam_server.url
returns the temporary server urliam_server.models
provides a modules containing different models (User
,Group
,Client
,Token
andAuthorizationCode
). Read the canaille documentation to find how to handle those models.iam_server.random_user()
andiam_server.random_group()
can generate random data for your tests
To run a full authentication process in your test, you can write something like this:
# We suppose you want to test a Flask application
def test_authentication(iam_server, testapp, client, user):
s = requests.Session()
# The /protected URL is protected and redirects to the identity provider
redirect_uri = testapp.get("/protected", status=302).location
# The IdP presents a login screen
res = s.post(
redirect_uri,
data={
"login": "user",
"password": "password",
},
allow_redirects=False,
)
# The IdP presents a consent screen
res = s.post(
redirect_uri,
data={"answer": "accept"},
allow_redirects=False,
)
# The IdP redirects to the client authorization endpoint
res = testapp.get(res.headers["Location"])
# Then the client endpoint finnaly redirects to the initial /protected page
res = res.follow()
res.mustcontain("Hello World!")
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pytest_iam-0.0.1.tar.gz
(3.5 kB
view hashes)
Built Distribution
Close
Hashes for pytest_iam-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 298addde44260e6b927efcfb199a572407fea31ee60e3188fc326fb39a0a0692 |
|
MD5 | 8646edc6f955392792aa879960ee9d2d |
|
BLAKE2b-256 | 2d004a11a1657f131fb6f307bcef31b635c26c31ab491ac5a186c27e68fde170 |