pytest-iam
pytest-iam spawns a lightweight OAuth2 / OpenID Server (OIDC) 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 tools to test your application authentication mechanism against a OAuth2/OIDC server:
- It launches a Canaille instance
- It provides a
iam_serverfixture that comes with several features:- the URL of the IAM server to configure your application
- IAM models (Users, groups, clients, tokens etc.) to prepare your tests and check the side effects. More details on the reference
- utilities to log-in users and give their consent to your application
- utilities to generate random users and groups
To run a full authentication process for a client application in your test, you can write something like this:
def test_authentication(iam_server, testapp, client):
# create a random user on the IAM server
user = iam_server.random_user()
# logs the user in give its consent to your application
iam_server.login(user)
iam_server.consent(user)
# simulate an attempt to access a protected page of your app
response = testapp.get("/protected", status=302)
# get an authorization code request at the IAM
res = requests.get(res.location, allow_redirects=False)
# access to the redirection URI
res = testclient.get(res.headers["Location"])
res.mustcontain("Hello World!")
Check the client application or resource server tutorials for more usecases.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
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.10.tar.gz.
File metadata
- Download URL: pytest_iam-0.0.10.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.11.8 Linux/6.8.5-arch1-1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9033a4d812ab97d69fa12a9e8f322ee8ebcdcd5a6b35dbf2b65d99c1246c941d
|
|
| MD5 |
d4ca62a2681ec3ec763cea0542cd7735
|
|
| BLAKE2b-256 |
72b9aefd196a05463f3681482ce6bb136315143ace5d99256dd7ef789630ba23
|
File details
Details for the file pytest_iam-0.0.10-py3-none-any.whl.
File metadata
- Download URL: pytest_iam-0.0.10-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.11.8 Linux/6.8.5-arch1-1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4b6c341b0d0e920ef6014821beadb9e24f430c008b1d3d833a08ebf851e90f68
|
|
| MD5 |
ef5ec912b55efbe25750a73a4aeed35b
|
|
| BLAKE2b-256 |
09d5ee5b3948a91fe3004f46c09b8baff85c82f9c28d4f6307694edac3a9b743
|