Skip to content

Commit

Permalink
Release of v1.13.1
Browse files Browse the repository at this point in the history
  • Loading branch information
dennissiemensma committed Jan 28, 2018
1 parent 5a1363c commit 74c1ac1
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 2 deletions.
9 changes: 9 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ Please make sure you have a fresh **database backup** before upgrading! Upgradin



v1.13.1 - 2018-01-28
^^^^^^^^^^^^^^^^^^^^

**Tickets resolved in this release:**

- [`#428 <https://github.com/dennissiemensma/dsmr-reader/issues/428>`_] Django 2.0: Null characters are not allowed in telegram (esp8266)



v1.13.0 - 2018-01-23
^^^^^^^^^^^^^^^^^^^^

Expand Down
16 changes: 15 additions & 1 deletion dsmr_api/forms.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
from django import forms
from django.core import validators


class NullCharField(forms.CharField):
""" Disables the ProhibitNullCharactersValidator, so we can clean it later on. """
def __init__(self, *args, **kwargs):
super(NullCharField, self).__init__(*args, **kwargs)
self.validators.remove(validators.ProhibitNullCharactersValidator())


class DsmrReadingForm(forms.Form):
telegram = forms.CharField()
telegram = NullCharField()

def clean_telegram(self):
""" Since we allow null characters, we should strip them right away. """
telegram = self.cleaned_data['telegram']
telegram = telegram.strip('\x00')
return telegram
14 changes: 14 additions & 0 deletions dsmr_api/tests/v1/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,17 @@ def test_okay(self, verify_telegram_checksum_mock):
self.assertTrue(DsmrReading.objects.exists())
self.assertEqual(response.status_code, 201)
self.assertEqual(response.content, b'')

@mock.patch('dsmr_datalogger.services.telegram_to_reading')
def test_null_data_validation(self, telegram_to_reading_mock):
""" Shallow data verification. """
response = self.client.post(
self._api_url,
data={'telegram': '\x00' + self._telegram}, # Add null byte.
HTTP_X_AUTHKEY=self._api_settings.auth_key
)
self.assertTrue(telegram_to_reading_mock.called)

# Make sure null characters are stripped.
self.assertNotIn('\x00', telegram_to_reading_mock.call_args[1]['data'])
self.assertEqual(response.status_code, 201)
2 changes: 1 addition & 1 deletion dsmrreader/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
from django.utils.version import get_version


VERSION = (1, 13, 0, 'final', 0)
VERSION = (1, 13, 1, 'final', 0)

__version__ = get_version(VERSION)

0 comments on commit 74c1ac1

Please sign in to comment.