Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/redundant sql query during ca cert creation #170

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,5 @@ Pipfile

# IDE specific files
.idea

venv/
9 changes: 2 additions & 7 deletions django_x509/base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,17 +200,12 @@ def clean(self):
self._verify_extension_format()

def save(self, *args, **kwargs):
generate = False
if not self.pk and not self.certificate and not self.private_key:
generate = True
super().save(*args, **kwargs)
if generate:
# automatically determine serial number
#removed these lines and any reference to the generate variable
if not self.serial_number:
self.serial_number = self._generate_serial_number()
self._generate()
kwargs['force_insert'] = False
super().save(*args, **kwargs)
super().save(*args, **kwargs)

@cached_property
def x509(self):
Expand Down
1 change: 1 addition & 0 deletions django_x509/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@
settings, 'DJANGO_X509_CERT_KEYUSAGE_VALUE', 'digitalSignature, keyEncipherment'
) # noqa
CRL_PROTECTED = getattr(settings, 'DJANGO_X509_CRL_PROTECTED', False)
DJANGO_X509_CA_MODEL = 'django_x509.Ca' # Adjust the model if necessary
5 changes: 4 additions & 1 deletion django_x509/tests/test_cert.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from OpenSSL import crypto
from swapper import load_model


from .. import settings as app_settings
from ..base.models import generalized_time
from . import TestX509Mixin
Expand Down Expand Up @@ -81,7 +82,9 @@ class TestCert(TestX509Mixin, TestCase):
"""

def test_new(self):
cert = self._create_cert()
#added assertNumQueries to check the number of queries made
with self.assertNumQueries(3): # 3 query to be made
cert = self._create_cert()
self.assertNotEqual(cert.certificate, '')
self.assertNotEqual(cert.private_key, '')
x509 = cert.x509
Expand Down
Binary file modified requirements.txt
Binary file not shown.