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 agaist 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.0.5.tar.gz
(4.8 kB
view hashes)
Built Distribution
Close
Hashes for pytest_iam-0.0.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e8c85f1ac6e0fec5528c53154b6a3fd7ac431b8bff68b24848abcc7376edc0cd |
|
MD5 | ef0308dd56eb4b8b4084b5ed4b88c724 |
|
BLAKE2b-256 | 44fd7a73d983b5421c54910217fbaf87b6baa507671657e3ddd4f133b85dfbab |