pytest-iam


Namepytest-iam JSON
Version 0.1.0 PyPI version JSON
download
home_pagehttps://github.com/pytest-dev/pytest-iam
SummaryA fully functional OAUTH2 / OpenID Connect (OIDC) server to be used in your testsuite
upload_time2024-07-25 15:27:34
maintainerNone
docs_urlNone
authorYaal Coop
requires_python<4.0,>=3.9
licenseMIT
keywords oidc oauth oauth2 openid identity pytest unit tests iam
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            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](https://canaille.yaal.coop) and [Authlib](https://authlib.org).

- [Repository](https://github.com/pytest-dev/pytest-iam)
- [Package](https://pypi.org/project/pytest-iam)
- [Documentation](https://pytest-iam.readthedocs.io)

Installation
------------

```console
pip install pytest-iam
```

Usage
-----

pytest-iam provides tools to test your application authentication mechanism against a OAuth2/OIDC server:

- It launches a [Canaille](https://canaille.yaal.coop) 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](https://pytest-iam.readthedocs.io/en/latest/reference.html)
    - 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:

```python
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](https://pytest-iam.readthedocs.io/en/latest/client-applications.html) or
[resource server](https://pytest-iam.readthedocs.io/en/latest/resource-servers.html) tutorials
for more usecases.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/pytest-dev/pytest-iam",
    "name": "pytest-iam",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.9",
    "maintainer_email": null,
    "keywords": "oidc, oauth, oauth2, openid, identity, pytest, unit tests, iam",
    "author": "Yaal Coop",
    "author_email": "contact@yaal.coop",
    "download_url": "https://files.pythonhosted.org/packages/33/32/012e5c88f6812ab439ffa131304ecaf1bf1d844eb8da23e447335bff9527/pytest_iam-0.1.0.tar.gz",
    "platform": null,
    "description": "pytest-iam\n==========\n\npytest-iam spawns a lightweight OAuth2 / OpenID Server (OIDC) in a thread to be used in your test suite.\nThe machinery involves [Canaille](https://canaille.yaal.coop) and [Authlib](https://authlib.org).\n\n- [Repository](https://github.com/pytest-dev/pytest-iam)\n- [Package](https://pypi.org/project/pytest-iam)\n- [Documentation](https://pytest-iam.readthedocs.io)\n\nInstallation\n------------\n\n```console\npip install pytest-iam\n```\n\nUsage\n-----\n\npytest-iam provides tools to test your application authentication mechanism against a OAuth2/OIDC server:\n\n- It launches a [Canaille](https://canaille.yaal.coop) instance\n- It provides a ``iam_server`` fixture that comes with several features:\n    - the URL of the IAM server to configure your application\n    - IAM models (Users, groups, clients, tokens etc.) to prepare your tests and check the side effects.\n      More details on [the reference](https://pytest-iam.readthedocs.io/en/latest/reference.html)\n    - utilities to log-in users and give their consent to your application\n    - utilities to generate random users and groups\n\nTo run a full authentication process for a client application in your test,\nyou can write something like this:\n\n```python\ndef test_authentication(iam_server, testapp, client):\n    # create a random user on the IAM server\n    user = iam_server.random_user()\n\n    # logs the user in give its consent to your application\n    iam_server.login(user)\n    iam_server.consent(user)\n\n    # simulate an attempt to access a protected page of your app\n    response = testapp.get(\"/protected\", status=302)\n\n    # get an authorization code request at the IAM\n    res = requests.get(res.location, allow_redirects=False)\n\n    # access to the redirection URI\n    res = testclient.get(res.headers[\"Location\"])\n    res.mustcontain(\"Hello World!\")\n```\n\nCheck the [client application](https://pytest-iam.readthedocs.io/en/latest/client-applications.html) or\n[resource server](https://pytest-iam.readthedocs.io/en/latest/resource-servers.html) tutorials\nfor more usecases.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A fully functional OAUTH2 / OpenID Connect (OIDC) server to be used in your testsuite",
    "version": "0.1.0",
    "project_urls": {
        "Documentation": "https://pytest-iam.readthedocs.io/en/latest/",
        "Homepage": "https://github.com/pytest-dev/pytest-iam",
        "Repository": "https://github.com/pytest-dev/pytest-iam"
    },
    "split_keywords": [
        "oidc",
        " oauth",
        " oauth2",
        " openid",
        " identity",
        " pytest",
        " unit tests",
        " iam"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a55e2d5811eaf81ee1e1ae7d3a368989a3e823e29944d9ca17a0122b1182eed4",
                "md5": "eb54ef9526e3db95c18191b3e97be877",
                "sha256": "fca152edca2d93b53028860eec3c8167341d0c0a4416a7e0413e2b72f6ea6cd2"
            },
            "downloads": -1,
            "filename": "pytest_iam-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "eb54ef9526e3db95c18191b3e97be877",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.9",
            "size": 5260,
            "upload_time": "2024-07-25T15:27:33",
            "upload_time_iso_8601": "2024-07-25T15:27:33.445716Z",
            "url": "https://files.pythonhosted.org/packages/a5/5e/2d5811eaf81ee1e1ae7d3a368989a3e823e29944d9ca17a0122b1182eed4/pytest_iam-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3332012e5c88f6812ab439ffa131304ecaf1bf1d844eb8da23e447335bff9527",
                "md5": "09c501964f29ddf10b72c57d85177324",
                "sha256": "3be9e5f370e505fa19f54d0786085d03d0cf9b5e99d5579862eea26e9321785f"
            },
            "downloads": -1,
            "filename": "pytest_iam-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "09c501964f29ddf10b72c57d85177324",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.9",
            "size": 5005,
            "upload_time": "2024-07-25T15:27:34",
            "upload_time_iso_8601": "2024-07-25T15:27:34.797747Z",
            "url": "https://files.pythonhosted.org/packages/33/32/012e5c88f6812ab439ffa131304ecaf1bf1d844eb8da23e447335bff9527/pytest_iam-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-07-25 15:27:34",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "pytest-dev",
    "github_project": "pytest-iam",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "pytest-iam"
}
        
Elapsed time: 0.27918s