This commit is contained in:
Tasos Katsoulas 2022-05-30 14:26:26 +03:00
Родитель 95090b1709
Коммит f47385bec0
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 522F81314743785E
13 изменённых файлов: 167 добавлений и 113 удалений

Просмотреть файл

@ -51,97 +51,163 @@ jobs:
root: workspace
paths:
- mozilla-django-oidc-dev.tar.gz
e2e_test_py3_rs_django220:
e2e_test_py37_rs_django320:
docker:
- image: mozilla/oidc-testprovider:oidc_e2e_setup_py3-latest
name: testoidcsetup
environment:
- TEST_OIDC_ALGO=rs
- DJANGO_VERSION=Django>=2.2.0,<3.0
<<: *common_steps
e2e_test_py3_hs_django220:
docker:
- image: mozilla/oidc-testprovider:oidc_e2e_setup_py3-latest
name: testoidcsetup
environment:
- TEST_OIDC_ALGO=hs
- DJANGO_VERSION=Django>=2.2.0,<3.0
<<: *common_steps
e2e_test_py3_rs_django300:
docker:
- image: mozilla/oidc-testprovider:oidc_e2e_setup_py3-latest
name: testoidcsetup
environment:
- TEST_OIDC_ALGO=rs
- DJANGO_VERSION=Django>=3.0.0,<3.1
<<: *common_steps
e2e_test_py3_hs_django300:
docker:
- image: mozilla/oidc-testprovider:oidc_e2e_setup_py3-latest
name: testoidcsetup
environment:
- TEST_OIDC_ALGO=hs
- DJANGO_VERSION=Django>=3.0.0,<3.1
<<: *common_steps
e2e_test_py3_rs_django310:
docker:
- image: mozilla/oidc-testprovider:oidc_e2e_setup_py3-latest
name: testoidcsetup
environment:
- TEST_OIDC_ALGO=rs
- DJANGO_VERSION=Django>=3.1.0,<3.2
<<: *common_steps
e2e_test_py3_hs_django310:
docker:
- image: mozilla/oidc-testprovider:oidc_e2e_setup_py3-latest
name: testoidcsetup
environment:
- TEST_OIDC_ALGO=hs
- DJANGO_VERSION=Django>=3.1.0,<3.2
<<: *common_steps
e2e_test_py3_rs_django320:
docker:
- image: mozilla/oidc-testprovider:oidc_e2e_setup_py3-latest
- image: mozilla/oidc-testprovider:oidc_e2e_setup_py37-latest
name: testoidcsetup
environment:
- TEST_OIDC_ALGO=rs
- DJANGO_VERSION=Django>=3.2.0,<4.0
<<: *common_steps
e2e_test_py3_hs_django320:
e2e_test_py38_rs_django320:
docker:
- image: mozilla/oidc-testprovider:oidc_e2e_setup_py3-latest
- image: mozilla/oidc-testprovider:oidc_e2e_setup_py38-latest
name: testoidcsetup
environment:
- TEST_OIDC_ALGO=rs
- DJANGO_VERSION=Django>=3.2.0,<4.0
<<: *common_steps
e2e_test_py39_rs_django320:
docker:
- image: mozilla/oidc-testprovider:oidc_e2e_setup_py39-latest
name: testoidcsetup
environment:
- TEST_OIDC_ALGO=rs
- DJANGO_VERSION=Django>=3.2.0,<4.0
<<: *common_steps
e2e_test_py310_rs_django320:
docker:
- image: mozilla/oidc-testprovider:oidc_e2e_setup_py310-latest
name: testoidcsetup
environment:
- TEST_OIDC_ALGO=rs
- DJANGO_VERSION=Django>=3.2.0,<4.0
<<: *common_steps
e2e_test_py37_hs_django320:
docker:
- image: mozilla/oidc-testprovider:oidc_e2e_setup_py37-latest
name: testoidcsetup
environment:
- TEST_OIDC_ALGO=hs
- DJANGO_VERSION=Django>=3.2.0,<4.0
<<: *common_steps
e2e_test_py38_hs_django320:
docker:
- image: mozilla/oidc-testprovider:oidc_e2e_setup_py38-latest
name: testoidcsetup
environment:
- TEST_OIDC_ALGO=hs
- DJANGO_VERSION=Django>=3.2.0,<4.0
<<: *common_steps
e2e_test_py39_hs_django320:
docker:
- image: mozilla/oidc-testprovider:oidc_e2e_setup_py39-latest
name: testoidcsetup
environment:
- TEST_OIDC_ALGO=hs
- DJANGO_VERSION=Django>=3.2.0,<4.0
<<: *common_steps
e2e_test_py310_hs_django320:
docker:
- image: mozilla/oidc-testprovider:oidc_e2e_setup_py310-latest
name: testoidcsetup
environment:
- TEST_OIDC_ALGO=hs
- DJANGO_VERSION=Django>=3.2.0,<4.0
<<: *common_steps
e2e_test_py38_rs_django400:
docker:
- image: mozilla/oidc-testprovider:oidc_e2e_setup_py38-latest
name: testoidcsetup
environment:
- TEST_OIDC_ALGO=rs
- DJANGO_VERSION=Django>=4.0,<4.1
<<: *common_steps
e2e_test_py39_rs_django400:
docker:
- image: mozilla/oidc-testprovider:oidc_e2e_setup_py39-latest
name: testoidcsetup
environment:
- TEST_OIDC_ALGO=rs
- DJANGO_VERSION=Django>=4.0,<4.1
<<: *common_steps
e2e_test_py310_rs_django400:
docker:
- image: mozilla/oidc-testprovider:oidc_e2e_setup_py310-latest
name: testoidcsetup
environment:
- TEST_OIDC_ALGO=rs
- DJANGO_VERSION=Django>=4.0,<4.1
<<: *common_steps
e2e_test_py38_hs_django400:
docker:
- image: mozilla/oidc-testprovider:oidc_e2e_setup_py38-latest
name: testoidcsetup
environment:
- TEST_OIDC_ALGO=hs
- DJANGO_VERSION=Django>=4.0,<4.1
<<: *common_steps
e2e_test_py39_hs_django400:
docker:
- image: mozilla/oidc-testprovider:oidc_e2e_setup_py39-latest
name: testoidcsetup
environment:
- TEST_OIDC_ALGO=hs
- DJANGO_VERSION=Django>=4.0,<4.1
<<: *common_steps
e2e_test_py310_hs_django400:
docker:
- image: mozilla/oidc-testprovider:oidc_e2e_setup_py310-latest
name: testoidcsetup
environment:
- TEST_OIDC_ALGO=hs
- DJANGO_VERSION=Django>=4.0,<4.1
<<: *common_steps
workflows:
version: 2
build_and_test:
jobs:
- build_lib
- e2e_test_py3_rs_django220:
- e2e_test_py37_rs_django320:
requires:
- build_lib
- e2e_test_py3_hs_django220:
- e2e_test_py38_rs_django320:
requires:
- build_lib
- e2e_test_py3_rs_django300:
- e2e_test_py39_rs_django320:
requires:
- build_lib
- e2e_test_py3_hs_django300:
- e2e_test_py310_rs_django320:
requires:
- build_lib
- e2e_test_py3_rs_django310:
- e2e_test_py37_hs_django320:
requires:
- build_lib
- e2e_test_py3_hs_django310:
- e2e_test_py38_hs_django320:
requires:
- build_lib
- e2e_test_py3_rs_django320:
- e2e_test_py39_hs_django320:
requires:
- build_lib
- e2e_test_py3_hs_django320:
- e2e_test_py310_hs_django320:
requires:
- build_lib
- e2e_test_py38_rs_django400:
requires:
- build_lib
- e2e_test_py39_rs_django400:
requires:
- build_lib
- e2e_test_py310_rs_django400:
requires:
- build_lib
- e2e_test_py38_hs_django400:
requires:
- build_lib
- e2e_test_py39_hs_django400:
requires:
- build_lib
- e2e_test_py310_hs_django400:
requires:
- build_lib

2
.github/workflows/ci.yml поставляемый
Просмотреть файл

@ -7,10 +7,10 @@ jobs:
strategy:
matrix:
python_version:
- "3.6"
- "3.7"
- "3.8"
- "3.9"
- "3.10"
name: Python ${{ matrix.python_version }}
steps:
- name: Checkout repository

2
.github/workflows/codecov.yml поставляемый
Просмотреть файл

@ -11,7 +11,7 @@ jobs:
- name: Setup python
uses: actions/setup-python@v2
with:
python-version: 3.7
python-version: '3.10'
- name: Install dependencies
run: pip install codecov tox tox-gh-actions
- name: Run tox

2
.github/workflows/release.yml поставляемый
Просмотреть файл

@ -14,7 +14,7 @@ jobs:
- name: Setup python
uses: actions/setup-python@v2
with:
python-version: "3.9"
python-version: "3.10"
- name: Install dependencies
run: pip install tox tox-gh-actions build
- name: Run tox

Просмотреть файл

@ -125,9 +125,9 @@ To run a specific environment, use the ``-e`` argument::
You can also run the tests in a virtual environment without tox::
$ DJANGO_SETTINGS_MODULE=tests.settings django-admin.py test
$ DJANGO_SETTINGS_MODULE=tests.settings django-admin test
You can specify test modules to run rather than the whole suite::
$ DJANGO_SETTINGS_MODULE=tests.settings django-admin.py test tests.test_views
$ DJANGO_SETTINGS_MODULE=tests.settings django-admin test tests.test_views

Просмотреть файл

@ -20,13 +20,13 @@ lint: ## check style with flake8
flake8 mozilla_django_oidc tests
test: ## run tests quickly with the default Python
DJANGO_SETTINGS_MODULE=tests.settings django-admin.py test
DJANGO_SETTINGS_MODULE=tests.settings django-admin test
test-all: ## run tests on every Python version with tox
tox
coverage: ## check code coverage quickly with the default Python
DJANGO_SETTINGS_MODULE=tests.settings coverage run --source mozilla_django_oidc `which django-admin.py` test
DJANGO_SETTINGS_MODULE=tests.settings coverage run --source mozilla_django_oidc `which django-admin` test
coverage report -m
coverage html
open htmlcov/index.html

Просмотреть файл

@ -58,17 +58,17 @@ Django of your choice. Here is such an example:
.. code-block:: shell
$ virtualenv -p /path/to/bin/python3.5 venv
$ virtualenv -p /path/to/bin/python3.7 venv
$ source venv
(venv) $ pip install -r requirements/requirements_dev.txt
(venv) $ DJANGO_SETTINGS_MODULE=tests.settings django-admin.py test
(venv) $ DJANGO_SETTINGS_MODULE=tests.settings django-admin test
Measuring code coverage, continuing the steps above:
.. code-block:: shell
(venv) $ pip install coverage
(venv) $ DJANGO_SETTINGS_MODULE=tests.settings coverage run --source mozilla_django_oidc `which django-admin.py` test
(venv) $ DJANGO_SETTINGS_MODULE=tests.settings coverage run --source mozilla_django_oidc `which django-admin` test
(venv) $ coverage report
(venv) $ coverage html
(venv) $ open htmlcov/index.html

Просмотреть файл

@ -1,5 +1,5 @@
# Based in the `docker-test-mozilla-django-oidc` images
# https://github.com/mozilla-parsys/docker-test-mozilla-django-oidc
# https://github.com/mozilla/docker-test-mozilla-django-oidc
version: '3'
services:
@ -19,7 +19,7 @@ services:
- ./:/mozilla-django-oidc
environment:
- TEST_OIDC_ALGO=${TEST_OIDC_ALGO:-hs}
- DJANGO_VERSION=${DJANGO_VERSION:-Django>=2.2}
- DJANGO_VERSION=${DJANGO_VERSION:-Django>=3.2}
command: >-
bash -c "cd /mozilla-django-oidc/ &&
pip install -I . &&

Просмотреть файл

@ -1,5 +1,6 @@
import logging
import time
from urllib.parse import quote, urlencode
from django.contrib.auth import BACKEND_SESSION_KEY
from django.http import HttpResponseRedirect, JsonResponse
@ -14,8 +15,6 @@ from mozilla_django_oidc.utils import (absolutify,
add_state_and_nonce_to_session,
import_from_settings)
from urllib.parse import quote, urlencode
try:
# Python 3.7 or later
from re import Pattern as re_Pattern
@ -35,8 +34,8 @@ class SessionRefresh(MiddlewareMixin):
"""
def __init__(self, *args, **kwargs):
super(SessionRefresh, self).__init__(*args, **kwargs)
def __init__(self, get_response):
super(SessionRefresh, self).__init__(get_response)
self.OIDC_EXEMPT_URLS = self.get_settings('OIDC_EXEMPT_URLS', [])
self.OIDC_OP_AUTHORIZATION_ENDPOINT = self.get_settings('OIDC_OP_AUTHORIZATION_ENDPOINT')
self.OIDC_RP_CLIENT_ID = self.get_settings('OIDC_RP_CLIENT_ID')

Просмотреть файл

@ -8,10 +8,8 @@ try:
except ImportError:
from distutils.core import setup
from mozilla_django_oidc import __version__ as VERSION
if sys.argv[-1] == 'publish':
try:
import wheel
@ -33,7 +31,7 @@ readme = open('README.rst').read()
history = open('HISTORY.rst').read().replace('.. :changelog:', '')
install_requirements = [
'Django >= 2.2',
'Django >= 3.2',
'josepy',
'requests',
'cryptography',
@ -56,10 +54,8 @@ setup(
classifiers=[
'Development Status :: 5 - Production/Stable',
'Framework :: Django',
'Framework :: Django :: 2.2',
'Framework :: Django :: 3.0',
'Framework :: Django :: 3.1',
'Framework :: Django :: 3.2',
'Framework :: Django :: 4.0',
'License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)',
'Intended Audience :: Developers',
'Operating System :: MacOS',
@ -67,9 +63,9 @@ setup(
'Natural Language :: English',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3 :: Only',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
],
)

Просмотреть файл

@ -1,25 +1,22 @@
import json
import re
import time
from urllib.parse import parse_qs
from mock import patch
from django.urls import path
from django.contrib.auth import get_user_model
from django.contrib.auth.signals import user_logged_out
from django.contrib.auth.models import AnonymousUser
from django.contrib.auth.signals import user_logged_out
from django.core.cache import cache
from django.dispatch import receiver
from django.http import HttpResponse
from django.test import Client, RequestFactory, TestCase, override_settings
from django.test.client import ClientHandler
from django.urls import path
from mock import MagicMock, patch
from mozilla_django_oidc.middleware import SessionRefresh
from mozilla_django_oidc.urls import urlpatterns as orig_urlpatterns
User = get_user_model()
@ -30,7 +27,7 @@ User = get_user_model()
class SessionRefreshTokenMiddlewareTestCase(TestCase):
def setUp(self):
self.factory = RequestFactory()
self.middleware = SessionRefresh()
self.middleware = SessionRefresh(MagicMock)
self.user = User.objects.create_user('example_username')
def test_anonymous(self, mock_middleware_random):
@ -210,7 +207,7 @@ class MiddlewareTestCase(TestCase):
@override_settings(OIDC_EXEMPT_URLS=['mdo_fake_view'])
def test_get_exempt_urls_setting_view_name(self):
middleware = SessionRefresh()
middleware = SessionRefresh(MagicMock())
self.assertEqual(
sorted(list(middleware.exempt_urls)),
[u'/authenticate/', u'/callback/', u'/logout/', u'/mdo_fake_view/']
@ -218,7 +215,7 @@ class MiddlewareTestCase(TestCase):
@override_settings(OIDC_EXEMPT_URLS=['/foo/'])
def test_get_exempt_urls_setting_url_path(self):
middleware = SessionRefresh()
middleware = SessionRefresh(MagicMock())
self.assertEqual(
sorted(list(middleware.exempt_urls)),
[u'/authenticate/', u'/callback/', u'/foo/', u'/logout/']
@ -228,7 +225,7 @@ class MiddlewareTestCase(TestCase):
request = self.factory.get('/mdo_fake_view/')
request.user = self.user
request.session = dict()
middleware = SessionRefresh()
middleware = SessionRefresh(MagicMock())
assert middleware.is_refreshable_url(request)
@override_settings(OIDC_EXEMPT_URLS=['mdo_fake_view'])
@ -236,7 +233,7 @@ class MiddlewareTestCase(TestCase):
request = self.factory.get('/mdo_fake_view/')
request.user = self.user
request.session = dict()
middleware = SessionRefresh()
middleware = SessionRefresh(MagicMock())
assert not middleware.is_refreshable_url(request)
@override_settings(OIDC_EXEMPT_URLS=['/mdo_fake_view/'])
@ -244,7 +241,7 @@ class MiddlewareTestCase(TestCase):
request = self.factory.get('/mdo_fake_view/')
request.user = self.user
request.session = dict()
middleware = SessionRefresh()
middleware = SessionRefresh(MagicMock())
assert not middleware.is_refreshable_url(request)
@override_settings(OIDC_EXEMPT_URLS=[re.compile(r'^/mdo_.*_view/$')])
@ -252,7 +249,7 @@ class MiddlewareTestCase(TestCase):
request = self.factory.get('/mdo_fake_view/')
request.user = self.user
request.session = dict()
middleware = SessionRefresh()
middleware = SessionRefresh(MagicMock())
assert not middleware.is_refreshable_url(request)
def test_anonymous(self):

Просмотреть файл

@ -2,9 +2,11 @@ from django.contrib.sessions.middleware import SessionMiddleware
from django.core.exceptions import ImproperlyConfigured
from django.test import TestCase, override_settings
from django.test.client import RequestFactory
from mock import MagicMock
from mozilla_django_oidc.utils import absolutify, add_state_and_nonce_to_session, \
import_from_settings
from mozilla_django_oidc.utils import (absolutify,
add_state_and_nonce_to_session,
import_from_settings)
class SettingImportTestCase(TestCase):
@ -57,7 +59,7 @@ class SessionStateTestCase(TestCase):
self.request = RequestFactory().get('/doesnt/matter')
# Setup request with a session for testing
middleware = SessionMiddleware()
middleware = SessionMiddleware(MagicMock())
middleware.process_request(self.request)
self.request.session.save()

22
tox.ini
Просмотреть файл

@ -1,38 +1,32 @@
[tox]
envlist =
lint
py{36,37,38,39}-django220
py{36,37,38,39}-django300
py{36,37,38,39}-django310
py{36,37,38,39}-django320
py{37,38,39,310}-django320
py{38,39,310}-django400
[gh-actions]
python =
3.6: py36
3.7: py37
3.8: py38
3.9: py39, coverage, lint
3.9: py39
3.10: py310, coverage, lint
[testenv]
commands = django-admin.py test
commands = django-admin test
setenv =
DJANGO_SETTINGS_MODULE=tests.settings
PYTHONPATH={toxinidir}
PYTHONWARNINGS=default
deps =
-r{toxinidir}/tests/requirements.txt
django220: Django>=2.2.0,<3.0
django220: djangorestframework>=3.7
django300: Django>=3.0.0,<3.1
django300: djangorestframework>=3.7
django310: Django>=3.1.0,<3.2
django310: djangorestframework>=3.7
django320: Django>=3.2.0,<4.0
django320: djangorestframework>=3.7
django400: Django>=4.0,<4.1
django400: djangorestframework>=3.7
[testenv:coverage]
commands =
coverage run --source mozilla_django_oidc {envbindir}/django-admin.py test
coverage run --source mozilla_django_oidc {envbindir}/django-admin test
deps =
coverage
-r{toxinidir}/tests/requirements.txt