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.urlreturns the temporary server urliam_server.modelsprovides a modules containing different models (User,Group,Client,TokenandAuthorizationCode). 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!")
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 details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pytest_iam-0.0.1.tar.gz.
File metadata
- Download URL: pytest_iam-0.0.1.tar.gz
- Upload date:
- Size: 3.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
poetry/1.5.1 CPython/3.11.3 Linux/6.4.10-arch1-1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
203660438236de0d5941a9c925d46df53d49754df7edd64a5509b70fc38265e7
|
|
| MD5 |
a66b3394b067273439285d5343f97322
|
|
| BLAKE2b-256 |
09343574f32e34bff3933b5fafe39de8025817e82c8efac12b20ce0b5d56d6bb
|
File details
Details for the file pytest_iam-0.0.1-py3-none-any.whl.
File metadata
- Download URL: pytest_iam-0.0.1-py3-none-any.whl
- Upload date:
- Size: 3.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
poetry/1.5.1 CPython/3.11.3 Linux/6.4.10-arch1-1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
298addde44260e6b927efcfb199a572407fea31ee60e3188fc326fb39a0a0692
|
|
| MD5 |
8646edc6f955392792aa879960ee9d2d
|
|
| BLAKE2b-256 |
2d004a11a1657f131fb6f307bcef31b635c26c31ab491ac5a186c27e68fde170
|