diff --git a/doc/reference/api/config.rst b/doc/reference/api/config.rst index 5d98e35..05dc0ef 100644 --- a/doc/reference/api/config.rst +++ b/doc/reference/api/config.rst @@ -63,7 +63,7 @@ You would also need to add the authentication middleware in the following way to MIDDLEWARE = [ # ... other middlewares - "rest_framework_statelessauth.middleware.AuthMiddleware" + "statelessauth.middleware.AuthMiddleware" ] .. toctree:: diff --git a/doc/reference/api/index.rst b/doc/reference/api/index.rst index 45daf42..5e8177c 100644 --- a/doc/reference/api/index.rst +++ b/doc/reference/api/index.rst @@ -4,7 +4,7 @@ API Reference ============= -This page documents the inner API of the ``statelessauth`` project. The project is separated into the following modules (all relative to ``rest_framework_statelessauth``). +This page documents the inner API of the ``statelessauth`` project. The project is separated into the following modules (all relative to ``statelessauth``). #. :ref:`Wire ` - ``.wire`` : responsible for encoding and decoding objects from and to JSON. #. :ref:`Engine ` - ``.engine`` : contains the different engines for the encoding and decoding as well as views. diff --git a/rest_framework_statelessauth/tests/__init__.py b/rest_framework_statelessauth/tests/__init__.py deleted file mode 100644 index ad055f2..0000000 --- a/rest_framework_statelessauth/tests/__init__.py +++ /dev/null @@ -1,15 +0,0 @@ - -from django.test import TestCase - -from rest_framework_statelessauth.tests.wire \ - import CustomAuthWireTestCases, DefaultAuthWireTestCases, \ - AuthPermissionTests, AuthGroupTests, AuthUserTests -from rest_framework_statelessauth.tests.config import ConfigTestCases -from rest_framework_statelessauth.tests.engine \ - import AbstractEngineTestCases, AcquireEngineTestCases, RefreshEngineTestCases -from rest_framework_statelessauth.tests.middlewares import MiddlewareTestCases -from rest_framework_statelessauth.tests.prometheus import PrometheusMetricsTest - -class InitialTestCases (TestCase): - def test_initial(self): - assert 1 == 1 diff --git a/setup.py b/setup.py index 906000d..3717c6c 100644 --- a/setup.py +++ b/setup.py @@ -3,11 +3,11 @@ install_requires = open("requirements.txt", "r").readlines() setuptools.setup( - name="rest_framework_statelessauth", + name="statelessauth", version="1.0.0", author="Polympiads", description="Django Rest Framework Stateless Auth", install_requires=install_requires, url="https://github.com/polympiads/djangorestapi-statelessauth", - packages=["rest_framework_statelessauth"] + packages=["statelessauth"] ) \ No newline at end of file diff --git a/rest_framework_statelessauth/config.py b/statelessauth/config.py similarity index 93% rename from rest_framework_statelessauth/config.py rename to statelessauth/config.py index a301242..d0f39c6 100644 --- a/rest_framework_statelessauth/config.py +++ b/statelessauth/config.py @@ -1,10 +1,10 @@ from typing import TYPE_CHECKING, Dict, List, Self, Tuple, Union -from rest_framework_statelessauth.wire import AuthWire +from statelessauth.wire import AuthWire if TYPE_CHECKING: - from rest_framework_statelessauth.engine.abstract import AuthEngine + from statelessauth.engine.abstract import AuthEngine from jose.jws import Key from django.conf import settings diff --git a/rest_framework_statelessauth/contrib/auth/models.py b/statelessauth/contrib/auth/models.py similarity index 100% rename from rest_framework_statelessauth/contrib/auth/models.py rename to statelessauth/contrib/auth/models.py diff --git a/rest_framework_statelessauth/contrib/auth/views.py b/statelessauth/contrib/auth/views.py similarity index 85% rename from rest_framework_statelessauth/contrib/auth/views.py rename to statelessauth/contrib/auth/views.py index 029fd25..45b709c 100644 --- a/rest_framework_statelessauth/contrib/auth/views.py +++ b/statelessauth/contrib/auth/views.py @@ -1,6 +1,6 @@ from django.http import HttpRequest -from rest_framework_statelessauth.contrib.auth.models import User +from statelessauth.contrib.auth.models import User def user_acquire_view (request: HttpRequest) -> "User | None": import django.contrib.auth.models as dmodels diff --git a/rest_framework_statelessauth/contrib/auth/wire.py b/statelessauth/contrib/auth/wire.py similarity index 91% rename from rest_framework_statelessauth/contrib/auth/wire.py rename to statelessauth/contrib/auth/wire.py index e552c66..1be7f11 100644 --- a/rest_framework_statelessauth/contrib/auth/wire.py +++ b/statelessauth/contrib/auth/wire.py @@ -1,8 +1,8 @@ from typing import TYPE_CHECKING, Any, Callable -from rest_framework_statelessauth.contrib.auth.models import Group, Permission, User -from rest_framework_statelessauth.wire import AuthWire +from statelessauth.contrib.auth.models import Group, Permission, User +from statelessauth.wire import AuthWire class PermissionWire(AuthWire[Permission]): def encode(self, permission: Permission) -> Any: diff --git a/rest_framework_statelessauth/engine/abstract.py b/statelessauth/engine/abstract.py similarity index 86% rename from rest_framework_statelessauth/engine/abstract.py rename to statelessauth/engine/abstract.py index b89839f..949b440 100644 --- a/rest_framework_statelessauth/engine/abstract.py +++ b/statelessauth/engine/abstract.py @@ -1,8 +1,8 @@ from typing import Generic, List, Tuple, TypeVar -from rest_framework_statelessauth.config import StatelessAuthConfig -from rest_framework_statelessauth.prometheus import stateless_auth_decode_decorator, stateless_auth_encode_decorator -from rest_framework_statelessauth.wire import AuthWire +from statelessauth.config import StatelessAuthConfig +from statelessauth.prometheus import stateless_auth_decode_decorator, stateless_auth_encode_decorator +from statelessauth.wire import AuthWire from jose.jws import Key from jose import jws, JWSError diff --git a/rest_framework_statelessauth/engine/acquire.py b/statelessauth/engine/acquire.py similarity index 81% rename from rest_framework_statelessauth/engine/acquire.py rename to statelessauth/engine/acquire.py index 26b1afe..3307711 100644 --- a/rest_framework_statelessauth/engine/acquire.py +++ b/statelessauth/engine/acquire.py @@ -3,9 +3,9 @@ from django.http import HttpRequest, JsonResponse from django.urls import path -from rest_framework_statelessauth.engine.abstract import AuthEngine -from rest_framework_statelessauth.prometheus import engine_view_decorator, acquire_engine_acquire_metrics -from rest_framework_statelessauth.wire import AuthWire +from statelessauth.engine.abstract import AuthEngine +from statelessauth.prometheus import engine_view_decorator, acquire_engine_acquire_metrics +from statelessauth.wire import AuthWire T = TypeVar("T") diff --git a/rest_framework_statelessauth/engine/refresh.py b/statelessauth/engine/refresh.py similarity index 90% rename from rest_framework_statelessauth/engine/refresh.py rename to statelessauth/engine/refresh.py index edc549a..1e82f60 100644 --- a/rest_framework_statelessauth/engine/refresh.py +++ b/statelessauth/engine/refresh.py @@ -4,9 +4,9 @@ from django.http import HttpRequest, JsonResponse from django.urls import path -from rest_framework_statelessauth.engine.abstract import AuthEngine -from rest_framework_statelessauth.prometheus import engine_view_decorator, refresh_engine_acquire_metrics, refresh_engine_refresh_metrics -from rest_framework_statelessauth.wire import AuthWire +from statelessauth.engine.abstract import AuthEngine +from statelessauth.prometheus import engine_view_decorator, refresh_engine_acquire_metrics, refresh_engine_refresh_metrics +from statelessauth.wire import AuthWire import time diff --git a/rest_framework_statelessauth/middlewares.py b/statelessauth/middlewares.py similarity index 90% rename from rest_framework_statelessauth/middlewares.py rename to statelessauth/middlewares.py index 58d551b..cbd9f1e 100644 --- a/rest_framework_statelessauth/middlewares.py +++ b/statelessauth/middlewares.py @@ -3,8 +3,8 @@ from django.http import HttpRequest, HttpResponse, HttpResponseForbidden -from rest_framework_statelessauth.config import StatelessAuthConfig -from rest_framework_statelessauth.prometheus import RunningOnMetric, middleware_decorator, middleware_metrics +from statelessauth.config import StatelessAuthConfig +from statelessauth.prometheus import RunningOnMetric, middleware_decorator, middleware_metrics class AuthMiddleware: def __init__(self, get_response, config = None): diff --git a/rest_framework_statelessauth/prometheus.py b/statelessauth/prometheus.py similarity index 100% rename from rest_framework_statelessauth/prometheus.py rename to statelessauth/prometheus.py diff --git a/statelessauth/tests/__init__.py b/statelessauth/tests/__init__.py new file mode 100644 index 0000000..28b052b --- /dev/null +++ b/statelessauth/tests/__init__.py @@ -0,0 +1,15 @@ + +from django.test import TestCase + +from statelessauth.tests.wire \ + import CustomAuthWireTestCases, DefaultAuthWireTestCases, \ + AuthPermissionTests, AuthGroupTests, AuthUserTests +from statelessauth.tests.config import ConfigTestCases +from statelessauth.tests.engine \ + import AbstractEngineTestCases, AcquireEngineTestCases, RefreshEngineTestCases +from statelessauth.tests.middlewares import MiddlewareTestCases +from statelessauth.tests.prometheus import PrometheusMetricsTest + +class InitialTestCases (TestCase): + def test_initial(self): + assert 1 == 1 diff --git a/rest_framework_statelessauth/tests/config.py b/statelessauth/tests/config.py similarity index 91% rename from rest_framework_statelessauth/tests/config.py rename to statelessauth/tests/config.py index 506ef4e..a18f0f2 100644 --- a/rest_framework_statelessauth/tests/config.py +++ b/statelessauth/tests/config.py @@ -1,13 +1,13 @@ from django.test import TestCase -from rest_framework_statelessauth.config import * -from rest_framework_statelessauth.engine.abstract import AuthEngine +from statelessauth.config import * +from statelessauth.engine.abstract import AuthEngine from jose.backends.rsa_backend import RSAKey from django.conf import settings -from rest_framework_statelessauth.contrib.auth.wire import UserWire +from statelessauth.contrib.auth.wire import UserWire class ConfigTestCases(TestCase): def test_simple_auth_write (self): diff --git a/rest_framework_statelessauth/tests/engine.py b/statelessauth/tests/engine.py similarity index 92% rename from rest_framework_statelessauth/tests/engine.py rename to statelessauth/tests/engine.py index 3b73300..b84bfca 100644 --- a/rest_framework_statelessauth/tests/engine.py +++ b/statelessauth/tests/engine.py @@ -7,12 +7,12 @@ from django.contrib.auth.models import AnonymousUser, User from django.urls import include, path -from rest_framework_statelessauth.contrib.auth.models import Group, Permission, User -from rest_framework_statelessauth.contrib.auth.views import user_acquire_view -from rest_framework_statelessauth.contrib.auth.wire import PermissionWire, UserWire -from rest_framework_statelessauth.engine.abstract import AuthEngine -from rest_framework_statelessauth.engine.acquire import AcquireEngine -from rest_framework_statelessauth.engine.refresh import RefreshEngine +from statelessauth.contrib.auth.models import Group, Permission, User +from statelessauth.contrib.auth.views import user_acquire_view +from statelessauth.contrib.auth.wire import PermissionWire, UserWire +from statelessauth.engine.abstract import AuthEngine +from statelessauth.engine.acquire import AcquireEngine +from statelessauth.engine.refresh import RefreshEngine from jose.backends.rsa_backend import RSAKey from django.conf import settings @@ -188,7 +188,7 @@ def test_simple_user_request (self): "token": token } assert response.content == bytes( json.dumps(payload), "utf-8" ) - @override_settings(ROOT_URLCONF="rest_framework_statelessauth.tests.engine") + @override_settings(ROOT_URLCONF="statelessauth.tests.engine") def test_with_url_dispatch_login (self): client = Client() user = dmodels.User.objects.create_user( "user", "user@gmail.com", "user" ) @@ -203,7 +203,7 @@ def test_with_url_dispatch_login (self): "token": token } assert response.content == bytes( json.dumps(payload), "utf-8" ) - @override_settings(ROOT_URLCONF="rest_framework_statelessauth.tests.engine") + @override_settings(ROOT_URLCONF="statelessauth.tests.engine") def test_with_url_dispatch_logout (self): client = Client() @@ -375,7 +375,7 @@ def test_refresh_deadline_fine (self): assert ctime + int(1e9) * 57 <= payload['alt'] <= ctime + int(1e9) * 63 assert ctime + int(1e9) * (3600 * 24 * 14 - 3) <= payload['rlt'] <= ctime + int(1e9) * (3600 * 24 * 14 + 3) - @override_settings(ROOT_URLCONF="rest_framework_statelessauth.tests.engine") + @override_settings(ROOT_URLCONF="statelessauth.tests.engine") def test_with_url_dispatch_logout (self): client = Client() @@ -383,7 +383,7 @@ def test_with_url_dispatch_logout (self): assert isinstance(response, JsonResponse) assert response.status_code == 401 assert response.content == b'{"valid": false, "token": ""}' - @override_settings(ROOT_URLCONF="rest_framework_statelessauth.tests.engine") + @override_settings(ROOT_URLCONF="statelessauth.tests.engine") def test_with_url_dispatch_wrong_password (self): client = Client() user = dmodels.User.objects.create_user("user", "user@user.com", "somepassword") @@ -392,7 +392,7 @@ def test_with_url_dispatch_wrong_password (self): assert isinstance(response, JsonResponse) assert response.status_code == 401 assert response.content == b'{"valid": false, "token": ""}' - @override_settings(ROOT_URLCONF="rest_framework_statelessauth.tests.engine") + @override_settings(ROOT_URLCONF="statelessauth.tests.engine") def test_with_url_dispatch_login (self): client = Client() user = dmodels.User.objects.create_user("user", "user@user.com", "somepassword") @@ -412,7 +412,7 @@ def test_with_url_dispatch_login (self): assert ctime + int(1e9) * 297 <= payload['alt'] <= ctime + int(1e9) * 303 assert ctime + int(1e9) * (3600 * 24 * 14 - 3) <= payload['rlt'] <= ctime + int(1e9) * (3600 * 24 * 14 + 3) - @override_settings(ROOT_URLCONF="rest_framework_statelessauth.tests.engine") + @override_settings(ROOT_URLCONF="statelessauth.tests.engine") def test_with_url_dispatch_deadline_passed (self): engine = RefreshEngine( "default", UserWire(), user_acquire_view, 0, 0 ) @@ -435,7 +435,7 @@ def test_with_url_dispatch_deadline_passed (self): assert isinstance(response, JsonResponse) assert response.status_code == 401 assert response.content == b'{"valid": false, "token": ""}' - @override_settings(ROOT_URLCONF="rest_framework_statelessauth.tests.engine") + @override_settings(ROOT_URLCONF="statelessauth.tests.engine") def test_with_url_dispatch_no_header (self): engine = RefreshEngine( "default", UserWire(), user_acquire_view, 0, 0 ) @@ -458,7 +458,7 @@ def test_with_url_dispatch_no_header (self): assert isinstance(response, JsonResponse) assert response.status_code == 400 assert response.content == b'{"valid": false, "token": ""}' - @override_settings(ROOT_URLCONF="rest_framework_statelessauth.tests.engine") + @override_settings(ROOT_URLCONF="statelessauth.tests.engine") def test_with_url_dispatch_deadline_fine (self): engine2 = RefreshEngine( "default", UserWire(), user_acquire_view, 60 ) diff --git a/rest_framework_statelessauth/tests/middlewares.py b/statelessauth/tests/middlewares.py similarity index 83% rename from rest_framework_statelessauth/tests/middlewares.py rename to statelessauth/tests/middlewares.py index f1d93df..d8ff2e6 100644 --- a/rest_framework_statelessauth/tests/middlewares.py +++ b/statelessauth/tests/middlewares.py @@ -4,12 +4,12 @@ from django.contrib.auth import models -from rest_framework_statelessauth.contrib.auth.models import User -from rest_framework_statelessauth.contrib.auth.views import user_acquire_view -from rest_framework_statelessauth.contrib.auth.wire import UserWire -from rest_framework_statelessauth.engine.refresh import RefreshEngine -from rest_framework_statelessauth.middlewares import AuthMiddleware -from rest_framework_statelessauth.config import StatelessAuthConfig +from statelessauth.contrib.auth.models import User +from statelessauth.contrib.auth.views import user_acquire_view +from statelessauth.contrib.auth.wire import UserWire +from statelessauth.engine.refresh import RefreshEngine +from statelessauth.middlewares import AuthMiddleware +from statelessauth.config import StatelessAuthConfig def home_page (request: HttpRequest): user: "User | None" = getattr(request, 'user', None) diff --git a/rest_framework_statelessauth/tests/prometheus.py b/statelessauth/tests/prometheus.py similarity index 94% rename from rest_framework_statelessauth/tests/prometheus.py rename to statelessauth/tests/prometheus.py index 70ea7b6..af44f98 100644 --- a/rest_framework_statelessauth/tests/prometheus.py +++ b/statelessauth/tests/prometheus.py @@ -7,14 +7,14 @@ from django_prometheus.conf import PROMETHEUS_LATENCY_BUCKETS from django.contrib.auth import models -from rest_framework_statelessauth.contrib.auth.models import User -from rest_framework_statelessauth.contrib.auth.views import user_acquire_view -from rest_framework_statelessauth.contrib.auth.wire import UserWire -from rest_framework_statelessauth.engine.acquire import AcquireEngine -from rest_framework_statelessauth.engine.refresh import RefreshEngine -from rest_framework_statelessauth.prometheus import clear_metrics -from rest_framework_statelessauth.tests.middlewares import home_page -from rest_framework_statelessauth.config import StatelessAuthConfig +from statelessauth.contrib.auth.models import User +from statelessauth.contrib.auth.views import user_acquire_view +from statelessauth.contrib.auth.wire import UserWire +from statelessauth.engine.acquire import AcquireEngine +from statelessauth.engine.refresh import RefreshEngine +from statelessauth.prometheus import clear_metrics +from statelessauth.tests.middlewares import home_page +from statelessauth.config import StatelessAuthConfig urlpatterns = [ path('account/', include(StatelessAuthConfig.instance().get_engine("default").urlpatterns)), @@ -24,12 +24,12 @@ MIDDLEWARE = [ 'django_prometheus.middleware.PrometheusBeforeMiddleware', - 'rest_framework_statelessauth.middlewares.AuthMiddleware', + 'statelessauth.middlewares.AuthMiddleware', 'django_prometheus.middleware.PrometheusAfterMiddleware' ] def loverride_settings (f): - return override_settings(ROOT_URLCONF="rest_framework_statelessauth.tests.prometheus", MIDDLEWARE=MIDDLEWARE)(f) + return override_settings(ROOT_URLCONF="statelessauth.tests.prometheus", MIDDLEWARE=MIDDLEWARE)(f) BUCKETS = ( "0.01", diff --git a/rest_framework_statelessauth/tests/utils.py b/statelessauth/tests/utils.py similarity index 91% rename from rest_framework_statelessauth/tests/utils.py rename to statelessauth/tests/utils.py index 634fc94..8325305 100644 --- a/rest_framework_statelessauth/tests/utils.py +++ b/statelessauth/tests/utils.py @@ -1,7 +1,7 @@ from typing import Any, Generic, List, Tuple, TypeVar -from rest_framework_statelessauth.wire import AuthWire +from statelessauth.wire import AuthWire T = TypeVar("T") diff --git a/rest_framework_statelessauth/tests/wire.py b/statelessauth/tests/wire.py similarity index 93% rename from rest_framework_statelessauth/tests/wire.py rename to statelessauth/tests/wire.py index 46d70e0..f3a6478 100644 --- a/rest_framework_statelessauth/tests/wire.py +++ b/statelessauth/tests/wire.py @@ -4,11 +4,11 @@ from django.test import TestCase from django.contrib.auth import models from django.contrib.contenttypes.models import ContentType -from rest_framework_statelessauth.tests.utils import TestWire -from rest_framework_statelessauth.wire import AuthWire +from statelessauth.tests.utils import TestWire +from statelessauth.wire import AuthWire -from rest_framework_statelessauth.contrib.auth.models import User, Group, Permission -from rest_framework_statelessauth.contrib.auth.wire import UserWire, GroupWire, PermissionWire +from statelessauth.contrib.auth.models import User, Group, Permission +from statelessauth.contrib.auth.wire import UserWire, GroupWire, PermissionWire class SimpleUserModel: username: str diff --git a/rest_framework_statelessauth/wire.py b/statelessauth/wire.py similarity index 100% rename from rest_framework_statelessauth/wire.py rename to statelessauth/wire.py diff --git a/test.sh b/test.sh index db415e3..f54a647 100644 --- a/test.sh +++ b/test.sh @@ -1,5 +1,5 @@ export DJANGO_SETTINGS_MODULE="test_settings" -python3 -m coverage run -m django test rest_framework_statelessauth +python3 -m coverage run -m django test statelessauth python3 -m coverage report --fail-under 100 diff --git a/test_settings.py b/test_settings.py index 4c36b4a..1d169ac 100644 --- a/test_settings.py +++ b/test_settings.py @@ -1,16 +1,16 @@ from jose.backends.rsa_backend import RSAKey -from rest_framework_statelessauth.contrib.auth.views import user_acquire_view -from rest_framework_statelessauth.contrib.auth.wire import UserWire -from rest_framework_statelessauth.engine.refresh import RefreshEngine +from statelessauth.contrib.auth.views import user_acquire_view +from statelessauth.contrib.auth.wire import UserWire +from statelessauth.engine.refresh import RefreshEngine -SECRET_KEY = 'rest_framework_statelessauth' +SECRET_KEY = 'statelessauth' INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', - 'rest_framework_statelessauth', + 'statelessauth', ) DATABASES = {