Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/reference/api/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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::
Expand Down
2 changes: 1 addition & 1 deletion doc/reference/api/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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>` - ``.wire`` : responsible for encoding and decoding objects from and to JSON.
#. :ref:`Engine <engine>` - ``.engine`` : contains the different engines for the encoding and decoding as well as views.
Expand Down
15 changes: 0 additions & 15 deletions rest_framework_statelessauth/tests/__init__.py

This file was deleted.

4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
)
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
File renamed without changes.
15 changes: 15 additions & 0 deletions statelessauth/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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" )
Expand All @@ -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()

Expand Down Expand Up @@ -375,15 +375,15 @@ 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()

response = client.get("/refr/acquire/")
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")
Expand All @@ -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")
Expand All @@ -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 )

Expand All @@ -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 )

Expand All @@ -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 )

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand All @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion test.sh
Original file line number Diff line number Diff line change
@@ -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
10 changes: 5 additions & 5 deletions test_settings.py
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down
Loading