From 4796be6f7d54bb14ef6e0a483d6831195cee1077 Mon Sep 17 00:00:00 2001 From: Deniz Date: Wed, 16 Aug 2023 00:53:07 +0200 Subject: [PATCH 1/3] Fix: HexadecimalField accepts non-hex values (#672) Fixes #671 --- push_notifications/fields.py | 2 +- tests/test_fields.py | 40 ++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 tests/test_fields.py diff --git a/push_notifications/fields.py b/push_notifications/fields.py index 90eb81f0..0b42d182 100644 --- a/push_notifications/fields.py +++ b/push_notifications/fields.py @@ -13,7 +13,7 @@ UNSIGNED_64BIT_INT_MAX_VALUE = 2 ** 64 - 1 -hex_re = re.compile(r"^(([0-9A-f])|(0x[0-9A-f]))+$") +hex_re = re.compile(r"^(0x)?([0-9a-f])+$", re.I) signed_integer_vendors = [ "postgresql", "sqlite", diff --git a/tests/test_fields.py b/tests/test_fields.py new file mode 100644 index 00000000..dcafc94f --- /dev/null +++ b/tests/test_fields.py @@ -0,0 +1,40 @@ +from django.core.exceptions import ValidationError +from django.test import SimpleTestCase + +from push_notifications.fields import HexadecimalField + + +class HexadecimalFieldTestCase(SimpleTestCase): + _INVALID_HEX_VALUES = [ + "foobar", + "GLUTEN", + "HeLLo WoRLd", + "international", + "°!#€%&/()[]{}=?", + "0x", + ] + + _VALID_HEX_VALUES = { + "babe": "babe", + "BEEF": "BEEF", + " \nfeed \t": "feed", + "0x012345789abcdef": "0x012345789abcdef", + "012345789aBcDeF": "012345789aBcDeF", + } + + def test_clean_invalid_values(self): + """Passing invalid values raises ValidationError.""" + f = HexadecimalField() + for invalid in self._INVALID_HEX_VALUES: + self.assertRaisesMessage( + ValidationError, + "'Enter a valid hexadecimal number'", + f.clean, + invalid, + ) + + def test_clean_valid_values(self): + """Passing valid values returns the expected output.""" + f = HexadecimalField() + for valid, expected in self._VALID_HEX_VALUES.items(): + self.assertEqual(expected, f.clean(valid)) From 184391b8f23cc098f6f68f235e10c022a38714f4 Mon Sep 17 00:00:00 2001 From: Jamaal Scarlett Date: Tue, 15 Aug 2023 19:33:21 -0400 Subject: [PATCH 2/3] Update tox.ini (#688) * Update tox.ini * Update release.yml --- .github/workflows/release.yml | 2 +- tox.ini | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e3f78f97..3d2ccf7a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -8,7 +8,7 @@ on: jobs: build: if: github.repository == 'jazzband/django-push-notifications' - runs-on: ubuntu-latest + runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v2 diff --git a/tox.ini b/tox.ini index c926fad3..84e82771 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -skipsdist = True +skipsdist = False usedevelop = true envlist = py{36,37,38,39}-dj{22,32} From 53525ca518e46f7ca458ebf25930619d00098696 Mon Sep 17 00:00:00 2001 From: Jamaal Scarlett Date: Tue, 15 Aug 2023 20:49:43 -0400 Subject: [PATCH 3/3] Update test.yml (#689) * Update test.yml Fixes failing python 3.6 tests * Update test.yml --- .github/workflows/test.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3d30815a..0d312ecf 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -5,7 +5,7 @@ on: [push, pull_request] jobs: build: name: build (Python ${{ matrix.python-version }}, Django ${{ matrix.django-version }}) - runs-on: ubuntu-latest + runs-on: ubuntu-20.04 strategy: fail-fast: false matrix: @@ -37,6 +37,7 @@ jobs: run: | python -m pip install --upgrade pip python -m pip install --upgrade tox tox-gh-actions + python -m pip install setuptools-scm==6.4.2 - name: Tox tests run: |