Skip to content

Commit

Permalink
0.6.0 - Major Update
Browse files Browse the repository at this point in the history
  * Drop Python 2 Support
  * Drop support for Django < 2.2
  * Add support for Django 2.2, 3.0, 3.1, and 3.2
  * Drop support for Python < 3.6
  * Add Support for Python 3.6, 3.7, 3.8, and 3.9
  * Move travis-ci testing to gitlab
  * Remove Support for EncryptedNullBooleanField (deprecated by Django 4.0)
  * Update Test App to Django 2.2 standard
  • Loading branch information
lanshark committed Aug 25, 2021
1 parent 34d878e commit 91106ab
Show file tree
Hide file tree
Showing 15 changed files with 169 additions and 84 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
django-encrypted-model-field Changelog
---------------------------------------
- 0.6.0 - Major Update
* Drop Python 2 Support
* Drop support for Django < 2.2
* Add support for Django 2.2, 3.0, 3.1, and 3.2
* Drop support for Python < 3.6
* Add Support for Python 3.6, 3.7, 3.8, and 3.9
* Move travis-ci testing to gitlab
* Remove Support for EncryptedNullBooleanField (deprecated by Django 4.0)
* Update Test App to Django 2.2 standard

- 0.5.8 - Move to GITLAB repository

- 0.5.7 - rearrange requirements and update dependencies
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2015 FounderTherapy, 2017-18 LANshark Consulting Group, LLC.
Copyright (c) 2015 FounderTherapy, 2017-21 LANshark Consulting Group, LLC.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
11 changes: 6 additions & 5 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,16 @@ Development Environment
-----------------------

Added Tox for testing with different versions of Django and Python. To get started:
pip install -r dev-requirements.txt
pip install -r requirements/dev.txt

using ``pyenv`` add the requisite python interpreters:
pyenv install 3.6.5
pyenv install 3.5.5
pyenv install 2.7.15
pyenv install 3.6.14
pyenv install 3.7.11
pyenv install 3.8.11
pyenv install 3.9.6

Add the requisite versions to the local version:
pyenv local 2.7.15 3.5.5 3.6.5
pyenv local 3.6.14 3.7.11 3.8.11 3.9.6

Run ``tox``
tox
2 changes: 1 addition & 1 deletion encrypted_model_fields/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.5.8'
__version__ = '0.6.0'
17 changes: 3 additions & 14 deletions encrypted_model_fields/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,19 +129,6 @@ def get_db_prep_save(self, value, connection):
return encrypt_str(str(value)).decode('utf-8')


class EncryptedNullBooleanField(EncryptedMixin, django.db.models.NullBooleanField):

def get_db_prep_save(self, value, connection):
if value is None:
return value
if value is True:
value = '1'
elif value is False:
value = '0'
# decode the encrypted value to a unicode string, else this breaks in pgsql
return encrypt_str(str(value)).decode('utf-8')


class EncryptedNumberMixin(EncryptedMixin):
max_length = 20

Expand Down Expand Up @@ -174,7 +161,9 @@ class EncryptedSmallIntegerField(EncryptedNumberMixin, django.db.models.SmallInt
pass


class EncryptedPositiveSmallIntegerField(EncryptedNumberMixin, django.db.models.PositiveSmallIntegerField):
class EncryptedPositiveSmallIntegerField(
EncryptedNumberMixin, django.db.models.PositiveSmallIntegerField
):
pass


Expand Down
19 changes: 15 additions & 4 deletions manage.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys

if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings_test")

from django.core.management import execute_from_command_line

def main():
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'testapp.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)


if __name__ == '__main__':
main()
5 changes: 2 additions & 3 deletions requirements/base.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
setuptools
cryptography==2.3
Django>=1.9.13
six>=1.11.0
cryptography>=3.4
Django>=2.2
30 changes: 0 additions & 30 deletions settings_test.py

This file was deleted.

2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
maintainer_email="[email protected]",
install_requires=[
'Django>=2.2',
'cryptography>=2.3',
'cryptography>=3.4',
],
tests_require=['tox'],
keywords=['encryption', 'django', 'fields', ],
Expand Down
1 change: 0 additions & 1 deletion testapp/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class Migration(migrations.Migration):
('enc_date_now_add_field', encrypted_model_fields.fields.EncryptedDateField(auto_now_add=True, max_length=100, null=True)),
('enc_datetime_field', encrypted_model_fields.fields.EncryptedDateTimeField(max_length=100, null=True)),
('enc_boolean_field', encrypted_model_fields.fields.EncryptedBooleanField(default=True, max_length=100)),
('enc_null_boolean_field', encrypted_model_fields.fields.EncryptedNullBooleanField(max_length=100)),
('enc_integer_field', encrypted_model_fields.fields.EncryptedIntegerField(null=True)),
('enc_positive_integer_field', encrypted_model_fields.fields.EncryptedPositiveIntegerField(null=True)),
('enc_small_integer_field', encrypted_model_fields.fields.EncryptedSmallIntegerField(null=True)),
Expand Down
1 change: 0 additions & 1 deletion testapp/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class TestModel(django.db.models.Model):
enc_date_now_add_field = fields.EncryptedDateField(auto_now_add=True, null=True)
enc_datetime_field = fields.EncryptedDateTimeField(null=True)
enc_boolean_field = fields.EncryptedBooleanField(default=True)
enc_null_boolean_field = fields.EncryptedNullBooleanField()
enc_integer_field = fields.EncryptedIntegerField(null=True)
enc_positive_integer_field = fields.EncryptedPositiveIntegerField(null=True)
enc_small_integer_field = fields.EncryptedSmallIntegerField(null=True)
Expand Down
105 changes: 105 additions & 0 deletions testapp/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
"""
Django settings for testapp project.
Generated by 'django-admin startproject' using Django 2.2.24.
"""

import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '!eu^!hbz*qa%xa(mxfjn)z6b6y_pys3g!lmfm68-zgmrp9#yvt'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = ['localhost', '127.0.0.1', ]

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'


# Application definition

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django_coverage',
'encrypted_model_fields',
'testapp',
]

FIELD_ENCRYPTION_KEY = '6-QgONW6TUl5rt4Xq8u-wBwPcb15sIYS2CN6d69zueM='

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'testapp.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]

WSGI_APPLICATION = 'testapp.wsgi.application'


DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}


AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]


LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True

STATIC_URL = '/static/'
30 changes: 8 additions & 22 deletions testapp/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ def test_value(self):
inst.enc_date_field = test_date
inst.enc_datetime_field = test_datetime
inst.enc_boolean_field = True
inst.enc_null_boolean_field = True
inst.enc_integer_field = 123456789
inst.enc_positive_integer_field = 123456789
inst.enc_small_integer_field = 123456789
Expand All @@ -41,7 +40,6 @@ def test_value(self):
inst.enc_datetime_field = timezone.make_aware(inst.enc_datetime_field, timezone.utc)
self.assertEqual(inst.enc_datetime_field, test_datetime)
self.assertEqual(inst.enc_boolean_field, True)
self.assertEqual(inst.enc_null_boolean_field, True)
self.assertEqual(inst.enc_integer_field, 123456789)
self.assertEqual(inst.enc_positive_integer_field, 123456789)
self.assertEqual(inst.enc_small_integer_field, 123456789)
Expand All @@ -55,7 +53,6 @@ def test_value(self):
inst.enc_date_field = test_date
inst.enc_datetime_field = test_datetime
inst.enc_boolean_field = False
inst.enc_null_boolean_field = False
inst.enc_integer_field = -123456789
inst.enc_positive_integer_field = 0
inst.enc_small_integer_field = -123456789
Expand All @@ -74,17 +71,14 @@ def test_value(self):
inst.enc_datetime_field = timezone.make_aware(inst.enc_datetime_field, timezone.utc)
self.assertEqual(inst.enc_datetime_field, test_datetime)
self.assertEqual(inst.enc_boolean_field, False)
self.assertEqual(inst.enc_null_boolean_field, False)
self.assertEqual(inst.enc_integer_field, -123456789)
self.assertEqual(inst.enc_positive_integer_field, 0)
self.assertEqual(inst.enc_small_integer_field, -123456789)
self.assertEqual(inst.enc_positive_small_integer_field, 0)
self.assertEqual(inst.enc_big_integer_field, -9223372036854775806)

inst.enc_null_boolean_field = None
inst.save()
inst = models.TestModel.objects.get()
self.assertEqual(inst.enc_null_boolean_field, None)

def test_unicode_value(self):
inst = models.TestModel()
Expand All @@ -106,7 +100,6 @@ def test_raw_value(self, get_converters_method):
inst.enc_date_field = datetime.date(2011, 1, 1)
inst.enc_datetime_field = datetime.datetime(2012, 2, 1, 1, tzinfo=timezone.utc)
inst.enc_boolean_field = True
inst.enc_null_boolean_field = True
inst.enc_integer_field = 123456789
inst.enc_positive_integer_field = 123456789
inst.enc_small_integer_field = 123456789
Expand All @@ -120,31 +113,27 @@ def test_raw_value(self, get_converters_method):
continue
self.assertEqual(value[:7], 'gAAAAAB', '{} failed: {}'.format(key, value))

inst.enc_null_boolean_field = None
inst.save()

d = models.TestModel.objects.values()[0]
self.assertEqual(d['enc_null_boolean_field'], None)

def test_get_internal_type(self):
enc_char_field = models.TestModel._meta.fields[1]
enc_text_field = models.TestModel._meta.fields[2]
enc_date_field = models.TestModel._meta.fields[3]
enc_date_now_field = models.TestModel._meta.fields[4]
enc_boolean_field = models.TestModel._meta.fields[7]
enc_null_boolean_field = models.TestModel._meta.fields[8]
enc_integer_field = models.TestModel._meta.fields[9]
enc_positive_integer_field = models.TestModel._meta.fields[10]
enc_small_integer_field = models.TestModel._meta.fields[11]
enc_positive_small_integer_field = models.TestModel._meta.fields[12]
enc_big_integer_field = models.TestModel._meta.fields[13]
enc_integer_field = models.TestModel._meta.fields[8]
enc_positive_integer_field = models.TestModel._meta.fields[9]
enc_small_integer_field = models.TestModel._meta.fields[10]
enc_positive_small_integer_field = models.TestModel._meta.fields[11]
enc_big_integer_field = models.TestModel._meta.fields[12]

self.assertEqual(enc_char_field.get_internal_type(), 'TextField')
self.assertEqual(enc_text_field.get_internal_type(), 'TextField')
self.assertEqual(enc_date_field.get_internal_type(), 'TextField')
self.assertEqual(enc_date_now_field.get_internal_type(), 'TextField')
self.assertEqual(enc_boolean_field.get_internal_type(), 'TextField')
self.assertEqual(enc_null_boolean_field.get_internal_type(), 'TextField')

self.assertEqual(enc_integer_field.get_internal_type(), 'TextField')
self.assertEqual(enc_positive_integer_field.get_internal_type(), 'TextField')
Expand Down Expand Up @@ -193,7 +182,6 @@ def test_rotating_keys(self):
inst.enc_date_field = test_date
inst.enc_datetime_field = test_datetime
inst.enc_boolean_field = True
inst.enc_null_boolean_field = True
inst.enc_integer_field = 123456789
inst.enc_positive_integer_field = 123456789
inst.enc_small_integer_field = 123456789
Expand All @@ -218,7 +206,6 @@ def test_rotating_keys(self):
inst.enc_datetime_field = timezone.make_aware(inst.enc_datetime_field, timezone.utc)
self.assertEqual(inst.enc_datetime_field, test_datetime)
self.assertEqual(inst.enc_boolean_field, True)
self.assertEqual(inst.enc_null_boolean_field, True)
self.assertEqual(inst.enc_integer_field, 123456789)
self.assertEqual(inst.enc_positive_integer_field, 123456789)
self.assertEqual(inst.enc_small_integer_field, 123456789)
Expand Down Expand Up @@ -246,7 +233,6 @@ def test_rotating_keys(self):
inst.enc_datetime_field = timezone.make_aware(inst.enc_datetime_field, timezone.utc)
self.assertEqual(inst.enc_datetime_field, test_datetime)
self.assertEqual(inst.enc_boolean_field, True)
self.assertEqual(inst.enc_null_boolean_field, True)
self.assertEqual(inst.enc_integer_field, 123456789)
self.assertEqual(inst.enc_positive_integer_field, 123456789)
self.assertEqual(inst.enc_small_integer_field, 123456789)
Expand All @@ -260,9 +246,9 @@ def test_rotating_keys(self):

# test that loading the instance from the database results in usable data
# (since it uses the older key that's still configured)
# Note we need to only load the enc_char_field because loading date field types results in
# conversion to python dates, which will be raise a ValidationError when the field can't be
# properly decoded
# Note we need to only load the enc_char_field because loading date field types
# results in conversion to python dates, which will be raise a ValidationError when
# the field can't be properly decoded
inst = models.TestModel.objects.only('enc_char_field').get()
self.assertNotEqual(inst.enc_char_field, 'This is a test string!')
self.assertEqual(inst.enc_char_field[:5], 'gAAAA')
Expand Down
Loading

0 comments on commit 91106ab

Please sign in to comment.