pytest-iam


Namepytest-iam JSON
Version 0.0.12 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-04-22 16:27:24
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/c6/f4/fe2612e9cc273dae72fb4c6990cd8d0f3b2c8f601b1e008e8263eb115faf/pytest_iam-0.0.12.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.0.12",
    "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": "d36f4eacceeacb02a4052e220ff5a080593fc33d9c622d9a5eed45072dc87771",
                "md5": "87af3b87481982bad740ea6d3117f6e6",
                "sha256": "480a7ff195dae5f3b56cb81a7ca80d0dd8ea0274e79f684390d42fe9c4cc101e"
            },
            "downloads": -1,
            "filename": "pytest_iam-0.0.12-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "87af3b87481982bad740ea6d3117f6e6",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.9",
            "size": 5218,
            "upload_time": "2024-04-22T16:27:22",
            "upload_time_iso_8601": "2024-04-22T16:27:22.942807Z",
            "url": "https://files.pythonhosted.org/packages/d3/6f/4eacceeacb02a4052e220ff5a080593fc33d9c622d9a5eed45072dc87771/pytest_iam-0.0.12-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c6f4fe2612e9cc273dae72fb4c6990cd8d0f3b2c8f601b1e008e8263eb115faf",
                "md5": "7aa2899baa7d172057f9f9af33c075ed",
                "sha256": "15b6f343ff3c3649d9355fd8d0fd631553282176104939d4b595048703061b70"
            },
            "downloads": -1,
            "filename": "pytest_iam-0.0.12.tar.gz",
            "has_sig": false,
            "md5_digest": "7aa2899baa7d172057f9f9af33c075ed",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.9",
            "size": 4953,
            "upload_time": "2024-04-22T16:27:24",
            "upload_time_iso_8601": "2024-04-22T16:27:24.357843Z",
            "url": "https://files.pythonhosted.org/packages/c6/f4/fe2612e9cc273dae72fb4c6990cd8d0f3b2c8f601b1e008e8263eb115faf/pytest_iam-0.0.12.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-22 16:27:24",
    "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.27423s