A fully functional OAUTH2 / OpenID Connect (OIDC) server to be used in your testsuite
Project description
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_server
fixture 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.
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.1.0.tar.gz
(5.0 kB
view details)
Built Distribution
File details
Details for the file pytest_iam-0.1.0.tar.gz
.
File metadata
- Download URL: pytest_iam-0.1.0.tar.gz
- Upload date:
- Size: 5.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.4 Linux/6.10.0-arch1-2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3be9e5f370e505fa19f54d0786085d03d0cf9b5e99d5579862eea26e9321785f |
|
MD5 | 09c501964f29ddf10b72c57d85177324 |
|
BLAKE2b-256 | 3332012e5c88f6812ab439ffa131304ecaf1bf1d844eb8da23e447335bff9527 |
File details
Details for the file pytest_iam-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: pytest_iam-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.4 Linux/6.10.0-arch1-2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fca152edca2d93b53028860eec3c8167341d0c0a4416a7e0413e2b72f6ea6cd2 |
|
MD5 | eb54ef9526e3db95c18191b3e97be877 |
|
BLAKE2b-256 | a55e2d5811eaf81ee1e1ae7d3a368989a3e823e29944d9ca17a0122b1182eed4 |