forked from openwisp/django-x509
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[improvement] Add Swapper openwisp#86
Closes openwisp#86
- Loading branch information
Showing
33 changed files
with
547 additions
and
304 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +0,0 @@ | ||
""" | ||
test utilities shared among test classes | ||
these mixins are reused also in openwisp2 | ||
change with care. | ||
""" | ||
|
||
|
||
class TestX509Mixin(object): | ||
def _create_ca(self, **kwargs): | ||
options = dict(name='Test CA', | ||
key_length='2048', | ||
digest='sha256', | ||
country_code='IT', | ||
state='RM', | ||
city='Rome', | ||
organization_name='OpenWISP', | ||
email='test@test.com', | ||
common_name='openwisp.org', | ||
extensions=[]) | ||
options.update(kwargs) | ||
ca = self.ca_model(**options) | ||
ca.full_clean() | ||
ca.save() | ||
return ca | ||
|
||
def _create_cert(self, **kwargs): | ||
options = dict(name='TestCert', | ||
ca=None, | ||
key_length='2048', | ||
digest='sha256', | ||
country_code='IT', | ||
state='RM', | ||
city='Rome', | ||
organization_name='Test', | ||
email='test@test.com', | ||
common_name='openwisp.org', | ||
extensions=[]) | ||
options.update(kwargs) | ||
# auto create CA if not supplied | ||
if not options.get('ca'): | ||
options['ca'] = self._create_ca() | ||
cert = self.cert_model(**options) | ||
cert.full_clean() | ||
cert.save() | ||
return cert | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
from django.contrib.messages.storage.fallback import FallbackStorage | ||
from django.http import HttpRequest | ||
|
||
|
||
class MessagingRequest(HttpRequest): | ||
session = 'session' | ||
|
||
def __init__(self): | ||
super().__init__() | ||
self._messages = FallbackStorage(self) | ||
|
||
def get_messages(self): | ||
return getattr(self._messages, '_queued_messages') | ||
|
||
def get_message_strings(self): | ||
return [str(m) for m in self.get_messages()] | ||
|
||
|
||
class TestX509Mixin(object): | ||
def _create_ca(self, **kwargs): | ||
options = dict(name='Test CA', | ||
key_length='2048', | ||
digest='sha256', | ||
country_code='IT', | ||
state='RM', | ||
city='Rome', | ||
organization_name='OpenWISP', | ||
email='test@test.com', | ||
common_name='openwisp.org', | ||
extensions=[]) | ||
options.update(kwargs) | ||
ca = self.ca_model(**options) | ||
ca.full_clean() | ||
ca.save() | ||
return ca | ||
|
||
def _create_cert(self, **kwargs): | ||
options = dict(name='TestCert', | ||
ca=None, | ||
key_length='2048', | ||
digest='sha256', | ||
country_code='IT', | ||
state='RM', | ||
city='Rome', | ||
organization_name='Test', | ||
email='test@test.com', | ||
common_name='openwisp.org', | ||
extensions=[]) | ||
options.update(kwargs) | ||
# auto create CA if not supplied | ||
if not options.get('ca'): | ||
options['ca'] = self._create_ca() | ||
cert = self.cert_model(**options) | ||
cert.full_clean() | ||
cert.save() | ||
return cert |
Oops, something went wrong.