diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 176a3cb..216dd3e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -56,6 +56,6 @@ jobs: key: ${{ matrix.python-version }}-pdm-${{ hashFiles('pdm.lock') }} restore-keys: ${{ matrix.python-version }}-pdm- - name: Install dependencies - run: python -m pip install --upgrade 'nox==2024.3.2' 'pdm==2.13.2' + run: python -m pip install --upgrade 'nox==2024.3.2' 'pdm>=2.12,<3' - name: Run unit tests run: nox -vs test diff --git a/demo/demo/admin.py b/demo/demo/admin.py index d393707..ec5fd27 100644 --- a/demo/demo/admin.py +++ b/demo/demo/admin.py @@ -1,7 +1,6 @@ -from fingerprint.admin import UserFingerprintAdmin from django.contrib import admin from django.contrib.auth import get_user_model - +from fingerprint.admin import UserFingerprintAdmin admin.site.unregister(get_user_model()) @@ -9,8 +8,12 @@ @admin.register(get_user_model()) class UserAdmin(UserFingerprintAdmin): list_display = ( - 'pk', 'email', 'date_joined', - 'sessions', - 'num_browser_fingerprints', 'browser_fingerprints', - 'num_request_fingerprints', 'request_fingerprints', + "pk", + "email", + "date_joined", + "sessions", + "num_browser_fingerprints", + "browser_fingerprints", + "num_request_fingerprints", + "request_fingerprints", ) diff --git a/demo/demo/tests/test_views.py b/demo/demo/tests/test_views.py index 6915377..c8f5c3a 100644 --- a/demo/demo/tests/test_views.py +++ b/demo/demo/tests/test_views.py @@ -1,8 +1,8 @@ from datetime import timedelta from django.utils.timezone import now -from freezegun import freeze_time from fingerprint.models import BrowserFingerprint, RequestFingerprint, UserSession +from freezegun import freeze_time def test__request__anonymous(client, db): diff --git a/pdm.lock b/pdm.lock index 714cabe..5f5e480 100644 --- a/pdm.lock +++ b/pdm.lock @@ -245,14 +245,14 @@ files = [ [[package]] name = "executing" -version = "2.0.1" -requires_python = ">=3.5" +version = "2.1.0" +requires_python = ">=3.8" summary = "Get the currently executing AST node of a frame, and other information" groups = ["dev", "test"] marker = "python_version > \"3.6\"" files = [ - {file = "executing-2.0.1-py2.py3-none-any.whl", hash = "sha256:eac49ca94516ccc753f9fb5ce82603156e590b27525a8bc32cce8ae302eb61bc"}, - {file = "executing-2.0.1.tar.gz", hash = "sha256:35afe2ce3affba8ee97f2d69927fa823b08b472b7b994e36a52a964b93d16147"}, + {file = "executing-2.1.0-py2.py3-none-any.whl", hash = "sha256:8d63781349375b5ebccc3142f4b30350c0cd9c79f921cde38be2be4637e98eaf"}, + {file = "executing-2.1.0.tar.gz", hash = "sha256:8ea27ddd260da8150fa5a708269c4a10e76161e2496ec3e587da9e3c0fe4b9ab"}, ] [[package]] @@ -750,29 +750,29 @@ files = [ [[package]] name = "ruff" -version = "0.6.2" +version = "0.6.3" requires_python = ">=3.7" summary = "An extremely fast Python linter and code formatter, written in Rust." groups = ["lint"] files = [ - {file = "ruff-0.6.2-py3-none-linux_armv6l.whl", hash = "sha256:5c8cbc6252deb3ea840ad6a20b0f8583caab0c5ef4f9cca21adc5a92b8f79f3c"}, - {file = "ruff-0.6.2-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:17002fe241e76544448a8e1e6118abecbe8cd10cf68fde635dad480dba594570"}, - {file = "ruff-0.6.2-py3-none-macosx_11_0_arm64.whl", hash = "sha256:3dbeac76ed13456f8158b8f4fe087bf87882e645c8e8b606dd17b0b66c2c1158"}, - {file = "ruff-0.6.2-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:094600ee88cda325988d3f54e3588c46de5c18dae09d683ace278b11f9d4d534"}, - {file = "ruff-0.6.2-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:316d418fe258c036ba05fbf7dfc1f7d3d4096db63431546163b472285668132b"}, - {file = "ruff-0.6.2-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:d72b8b3abf8a2d51b7b9944a41307d2f442558ccb3859bbd87e6ae9be1694a5d"}, - {file = "ruff-0.6.2-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:2aed7e243be68487aa8982e91c6e260982d00da3f38955873aecd5a9204b1d66"}, - {file = "ruff-0.6.2-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:d371f7fc9cec83497fe7cf5eaf5b76e22a8efce463de5f775a1826197feb9df8"}, - {file = "ruff-0.6.2-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:a8f310d63af08f583363dfb844ba8f9417b558199c58a5999215082036d795a1"}, - {file = "ruff-0.6.2-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:7db6880c53c56addb8638fe444818183385ec85eeada1d48fc5abe045301b2f1"}, - {file = "ruff-0.6.2-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:1175d39faadd9a50718f478d23bfc1d4da5743f1ab56af81a2b6caf0a2394f23"}, - {file = "ruff-0.6.2-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:5b939f9c86d51635fe486585389f54582f0d65b8238e08c327c1534844b3bb9a"}, - {file = "ruff-0.6.2-py3-none-musllinux_1_2_i686.whl", hash = "sha256:d0d62ca91219f906caf9b187dea50d17353f15ec9bb15aae4a606cd697b49b4c"}, - {file = "ruff-0.6.2-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:7438a7288f9d67ed3c8ce4d059e67f7ed65e9fe3aa2ab6f5b4b3610e57e3cb56"}, - {file = "ruff-0.6.2-py3-none-win32.whl", hash = "sha256:279d5f7d86696df5f9549b56b9b6a7f6c72961b619022b5b7999b15db392a4da"}, - {file = "ruff-0.6.2-py3-none-win_amd64.whl", hash = "sha256:d9f3469c7dd43cd22eb1c3fc16926fb8258d50cb1b216658a07be95dd117b0f2"}, - {file = "ruff-0.6.2-py3-none-win_arm64.whl", hash = "sha256:f28fcd2cd0e02bdf739297516d5643a945cc7caf09bd9bcb4d932540a5ea4fa9"}, - {file = "ruff-0.6.2.tar.gz", hash = "sha256:239ee6beb9e91feb8e0ec384204a763f36cb53fb895a1a364618c6abb076b3be"}, + {file = "ruff-0.6.3-py3-none-linux_armv6l.whl", hash = "sha256:97f58fda4e309382ad30ede7f30e2791d70dd29ea17f41970119f55bdb7a45c3"}, + {file = "ruff-0.6.3-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:3b061e49b5cf3a297b4d1c27ac5587954ccb4ff601160d3d6b2f70b1622194dc"}, + {file = "ruff-0.6.3-py3-none-macosx_11_0_arm64.whl", hash = "sha256:34e2824a13bb8c668c71c1760a6ac7d795ccbd8d38ff4a0d8471fdb15de910b1"}, + {file = "ruff-0.6.3-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:bddfbb8d63c460f4b4128b6a506e7052bad4d6f3ff607ebbb41b0aa19c2770d1"}, + {file = "ruff-0.6.3-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:ced3eeb44df75353e08ab3b6a9e113b5f3f996bea48d4f7c027bc528ba87b672"}, + {file = "ruff-0.6.3-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:47021dff5445d549be954eb275156dfd7c37222acc1e8014311badcb9b4ec8c1"}, + {file = "ruff-0.6.3-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:7d7bd20dc07cebd68cc8bc7b3f5ada6d637f42d947c85264f94b0d1cd9d87384"}, + {file = "ruff-0.6.3-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:500f166d03fc6d0e61c8e40a3ff853fa8a43d938f5d14c183c612df1b0d6c58a"}, + {file = "ruff-0.6.3-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:42844ff678f9b976366b262fa2d1d1a3fe76f6e145bd92c84e27d172e3c34500"}, + {file = "ruff-0.6.3-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:70452a10eb2d66549de8e75f89ae82462159855e983ddff91bc0bce6511d0470"}, + {file = "ruff-0.6.3-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:65a533235ed55f767d1fc62193a21cbf9e3329cf26d427b800fdeacfb77d296f"}, + {file = "ruff-0.6.3-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:d2e2c23cef30dc3cbe9cc5d04f2899e7f5e478c40d2e0a633513ad081f7361b5"}, + {file = "ruff-0.6.3-py3-none-musllinux_1_2_i686.whl", hash = "sha256:d8a136aa7d228975a6aee3dd8bea9b28e2b43e9444aa678fb62aeb1956ff2351"}, + {file = "ruff-0.6.3-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:f92fe93bc72e262b7b3f2bba9879897e2d58a989b4714ba6a5a7273e842ad2f8"}, + {file = "ruff-0.6.3-py3-none-win32.whl", hash = "sha256:7a62d3b5b0d7f9143d94893f8ba43aa5a5c51a0ffc4a401aa97a81ed76930521"}, + {file = "ruff-0.6.3-py3-none-win_amd64.whl", hash = "sha256:746af39356fee2b89aada06c7376e1aa274a23493d7016059c3a72e3b296befb"}, + {file = "ruff-0.6.3-py3-none-win_arm64.whl", hash = "sha256:14a9528a8b70ccc7a847637c29e56fd1f9183a9db743bbc5b8e0c4ad60592a82"}, + {file = "ruff-0.6.3.tar.gz", hash = "sha256:183b99e9edd1ef63be34a3b51fee0a9f4ab95add123dbf89a71f7b1f0c991983"}, ] [[package]] diff --git a/src/fingerprint/views.py b/src/fingerprint/views.py index 2a39f37..296597a 100644 --- a/src/fingerprint/views.py +++ b/src/fingerprint/views.py @@ -1,7 +1,7 @@ from datetime import timedelta from functools import wraps -from typing import Optional from logging import getLogger +from typing import Optional from django.conf import settings from django.core.exceptions import BadRequest, DisallowedRedirect @@ -43,14 +43,14 @@ def wrapper(request, *args, **kwargs): with transaction.atomic(): fingerprint, created = RequestFingerprint.objects.get_or_create( user_session=UserSession.objects.get_or_create(session_key=session_key)[0], - url=Url.from_value(request.build_absolute_uri()[:max_length['url']]), + url=Url.from_value(request.build_absolute_uri()[: max_length["url"]]), created__gte=now() - debounce_period, defaults=dict( ip=get_client_ip(request)[0], - user_agent=request.META.get('HTTP_USER_AGENT', '')[:max_length['user_agent']], - accept=request.META.get('HTTP_ACCEPT', '')[:max_length['accept']], - content_encoding=request.META.get('HTTP_CONTENT_ENCODING', '')[:max_length['content_encoding']], - content_language=request.META.get('HTTP_CONTENT_LANGUAGE', '')[:max_length['content_language']], + user_agent=request.META.get("HTTP_USER_AGENT", "")[: max_length["user_agent"]], + accept=request.META.get("HTTP_ACCEPT", "")[: max_length["accept"]], + content_encoding=request.META.get("HTTP_CONTENT_ENCODING", "")[: max_length["content_encoding"]], + content_language=request.META.get("HTTP_CONTENT_LANGUAGE", "")[: max_length["content_language"]], referer=request.META.get("HTTP_REFERER", "")[: max_length["referer"]], cf_ipcountry=request.META.get("HTTP_CF_IPCOUNTRY", "")[: max_length["cf_ipcountry"]], ),