Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
do9xe authored Jul 19, 2024
2 parents c5a0e03 + fd02e44 commit 26e61f8
Show file tree
Hide file tree
Showing 50 changed files with 2,904 additions and 3,802 deletions.
4 changes: 4 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[flake8]
ignore = E731,W503,W504,E501
max-complexity = 50
max-line-length = 200
67 changes: 30 additions & 37 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,94 +13,87 @@ on:

jobs:
test_py3:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
python-version:
- "3.5"
- "3.6"
- "3.7"
- "3.8"
- "3.9"
- "3.10"
- "3.11"
- "3.12"
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- uses: actions/cache@v2
- uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/setup.py') }}
key: ${{ runner.os }}-pip-${{ hashFiles('**/pyproject.toml') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install dependencies
run: |
pip install -U setuptools
sudo apt-get update -qq
sudo apt-get install -qq swig python-dev libxml2-dev libxmlsec1-dev
sudo apt-get install -qq swig libxml2-dev libxmlsec1-dev
make install-req
make install-test
- name: Test
run: make pytest
test_py2:
runs-on: ubuntu-20.04
container:
image: python:2.7.18-buster
strategy:
fail-fast: false
lint:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: actions/cache@v2
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/setup.py') }}
key: ${{ runner.os }}-pip-${{ hashFiles('**/pyproject.toml') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install dependencies
run: |
pip install -U setuptools
apt-get update -qq
apt-get install -qq swig python-dev libxml2-dev libxmlsec1-dev
sudo apt-get update -qq
sudo apt-get install -qq swig libxml2-dev libxmlsec1-dev
make install-req
make install-test
- name: Test
run: make pytest
lint:
runs-on: ubuntu-20.04
make install-lint
- name: Run linters
run: |
make flake8
make black
coveralls:
runs-on: ubuntu-22.04
environment: CI
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v2
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- uses: actions/cache@v2
- uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/setup.py') }}
key: ${{ runner.os }}-pip-${{ hashFiles('**/pyproject.toml') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install dependencies
run: |
pip install -U setuptools
sudo apt-get update -qq
sudo apt-get install -qq swig python-dev libxml2-dev libxmlsec1-dev
pip install --force-reinstall --no-binary lxml lxml
sudo apt-get install -qq swig libxml2-dev libxmlsec1-dev
make install-req
make install-test
- name: Run linters
run: |
make pycodestyle
make flake8
- name: Run coveralls
env:
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
run: |
pip install coveralls
coverage run setup.py test
coverage report -m
coveralls
make coverage
make coveralls
28 changes: 0 additions & 28 deletions .travis.yml

This file was deleted.

6 changes: 0 additions & 6 deletions MANIFEST.in

This file was deleted.

25 changes: 17 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
PIP=pip
BLACK=black
FLAKE8=flake8
PYTEST=pytest
PYCODESTYLE=pycodestyle
COVERAGE=coverage
COVERAGE_CONFIG=tests/coverage.rc
PEP8_CONFIG=tests/pep8.rc
COVERALLS=coveralls
MAIN_SOURCE=src/onelogin/saml2
DEMOS=demo-django demo-flask demo-tornado demo_pyramid
TESTS=tests/src/OneLogin/saml2_tests
Expand All @@ -14,19 +14,28 @@ install-req:
$(PIP) install .

install-test:
$(PIP) install -e ".[test]"
$(PIP) install -e ".[test]"

install-lint:
$(PIP) install -e ".[lint]"

pytest:
$(COVERAGE) run --source $(MAIN_SOURCE) --rcfile=$(COVERAGE_CONFIG) -m pytest
$(COVERAGE) report -m --rcfile=$(COVERAGE_CONFIG)
$(PYTEST)

coverage:
$(COVERAGE) run -m $(PYTEST)
$(COVERAGE) report -m

coveralls:
$(COVERALLS)

pycodestyle:
$(PYCODESTYLE) --ignore=E501,E731,W504 $(SOURCES) --config=$(PEP8_CONFIG)
black:
$(BLACK) $(SOURCES)

flake8:
$(FLAKE8) $(SOURCES)

clean:
clean:
rm -rf .pytest_cache/
rm -rf .eggs/
find . -type d -name "__pycache__" -exec rm -r {} +
Expand Down
46 changes: 19 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
![PyPI Downloads](https://img.shields.io/pypi/dm/python3-saml.svg?label=PyPI%20Downloads)
[![Coverage Status](https://coveralls.io/repos/github/SAML-Toolkits/python3-saml/badge.svg?branch=master)](https://coveralls.io/github/SAML-Toolkits/python3-saml?branch=master)
[![PyPi Version](https://img.shields.io/pypi/v/python3-saml.svg)](https://pypi.python.org/pypi/python3-saml)
![Python versions](https://img.shields.io/pypi/pyversions/python3-saml.svg)
![Python versions](https://img.shields.io/python/required-version-toml?tomlFilePath=https%3A%2F%2Fraw.luolix.top%2FSAML-Toolkits%2Fpython3-saml%2Fmaster%2Fpyproject.toml)

Add SAML support to your Python software using this library.
Forget those complicated libraries and use the open source library provided by the SAML tool community.
Expand All @@ -13,7 +13,7 @@ This version supports Python3. Python 2 support was deprecated on Jan 1st, 2020:

#### Warning ####

Version 1.16.X is the latest version supporting Python2, consider its use deprecated. 1.17 won't be Python2 compatible.
Version 1.16.X is the latest version supporting Python2, consider its use deprecated. 1.17 won't be Python2 and old Python3 compatible.

Version 1.13.0 sets sha256 and rsa-sha256 as default algorithms

Expand Down Expand Up @@ -90,13 +90,13 @@ Installation

### Dependencies ###

* python 2.7 (deprecated) // python 3.6
* python => 3.7
* [xmlsec](https://pypi.python.org/pypi/xmlsec) Python bindings for the XML Security Library.
* [lxml](https://pypi.python.org/pypi/lxml) Python bindings for the libxml2 and libxslt libraries.
* [isodate](https://pypi.python.org/pypi/isodate) An ISO 8601 date/time/
duration parser and formatter

Review the ``setup.py`` file to know the version of the library that ``python3-saml`` is using
Review the ``pyproject.toml`` file to know the version of the library that ``python3-saml`` is using

### Code ###

Expand All @@ -107,7 +107,7 @@ The toolkit is hosted on GitHub. You can download it from:
* Latest release: https://github.com/saml-toolkits/python3-saml/releases/latest
* Master repo: https://github.com/saml-toolkits/python3-saml/tree/master

Copy the core of the library ``(src/onelogin/saml2 folder)`` and merge the ``setup.py`` inside the Python application. (Each application has its structure so take your time to locate the Python SAML toolkit in the best place).
Find the core of the library at ``src/onelogin/saml2`` folder.

#### Option 2. Download from pypi ####

Expand Down Expand Up @@ -217,32 +217,32 @@ This folder contains a Pyramid project that will be used as demo to show how to

This folder contains a Tornado project that will be used as demo to show how to add SAML support to the Tornado Framework. ``views.py`` (with its ``settings.py``) is the main Flask file that has all the code, this file uses the templates stored at the ``templates`` folder. In the ``saml`` folder we found the ``certs`` folder to store the X.509 public and private key, and the SAML toolkit settings (``settings.json`` and ``advanced_settings.json``).

It requires python3.5 (it's using tornado 6.0.3)
It requires python3.8 (it's using tornado 6.4.1)

#### setup.py ####

Setup script is the centre of all activity in building, distributing, and installing modules.
Read more at https://pythonhosted.org/an_example_pypi_project/setuptools.html

#### tests ####

Contains the unit test of the toolkit.

In order to execute the test you only need to load the virtualenv with the toolkit installed on it properly:
```
pip install -e ".[test]"
make install-test
```

and execute:
```
python setup.py test
make pytest
```
The previous line will run the tests for the whole toolkit. You can also run the tests for a specific module. To do so for the auth module you would have to execute this:
```
python setup.py test --test-suite tests.src.OneLogin.saml2_tests.auth_test.OneLogin_Saml2_Auth_Test
pytest tests/src/OneLogin/saml2_tests/auth_test.py::OneLogin_Saml2_Auth_Test
```

Or for an specific method:
```
pytest tests/src/OneLogin/saml2_tests/auth_test.py::OneLogin_Saml2_Auth_Test::testBuildRequestSignature
```

With the ``--test-suite`` parameter you can specify the module to test. You'll find all the module available and their class names at ``tests/src/OneLogin/saml2_tests/``.

### How It Works ###

Expand Down Expand Up @@ -650,7 +650,7 @@ def prepare_from_django_request(request):
def prepare_from_flask_request(request):
url_data = urlparse(request.url)
return {
'http_host': request.host,
'http_host': request.netloc,
'script_name': request.path,
'get_data': request.args.copy(),
'post_data': request.form.copy()
Expand Down Expand Up @@ -772,7 +772,7 @@ Notice that we saved the user data in the session before the redirection to have
In order to retrieve attributes we use:

```python
attributes = auth.get_attributes();
attributes = auth.get_attributes()
```

With this method we get a dict with all the user data provided by the IdP in the assertion of the SAML response.
Expand All @@ -793,7 +793,7 @@ Each attribute name can be used as a key to obtain the value. Every attribute is
The following code is equivalent:

```python
attributes = auth.get_attributes();
attributes = auth.get_attributes()
print(attributes['cn'])

print(auth.get_attribute('cn'))
Expand Down Expand Up @@ -1212,17 +1212,9 @@ can find more details and an installation guide in the
[official documentation](http://virtualenv.readthedocs.org/en/latest/).

Once you have your virtualenv ready and loaded, then you can install the
toolkit on it in development mode executing this:
```
python setup.py develop
```

Using this method of deployment the toolkit files will be linked instead of
copied, so if you make changes on them you won't need to reinstall the toolkit.

If you want install it in a normal mode, execute:
toolkit executing this:
```
python setup.py install
make install-req
```

### Demo Flask ###
Expand Down
7 changes: 4 additions & 3 deletions demo-django/demo/urls.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from django.urls import re_path
from django.contrib import admin
from .views import attrs, index, metadata

admin.autodiscover()

urlpatterns = [
re_path(r'^$', index, name='index'),
re_path(r'^attrs/$', attrs, name='attrs'),
re_path(r'^metadata/$', metadata, name='metadata'),
re_path(r"^$", index, name="index"),
re_path(r"^attrs/$", attrs, name="attrs"),
re_path(r"^metadata/$", metadata, name="metadata"),
]
Loading

0 comments on commit 26e61f8

Please sign in to comment.