Merge pull request #52 from pabluk/creatersakey-command-py3
Fix creatersakey management command support for Python 3.x
This commit is contained in:
commit
4c9dfefedd
|
@ -1,7 +1,7 @@
|
||||||
from Crypto.PublicKey import RSA
|
from Crypto.PublicKey import RSA
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core.management.base import BaseCommand, CommandError
|
from django.core.management.base import BaseCommand
|
||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
|
@ -11,8 +11,8 @@ class Command(BaseCommand):
|
||||||
try:
|
try:
|
||||||
key = RSA.generate(1024)
|
key = RSA.generate(1024)
|
||||||
file_path = settings.BASE_DIR + '/OIDC_RSA_KEY.pem'
|
file_path = settings.BASE_DIR + '/OIDC_RSA_KEY.pem'
|
||||||
with open(file_path, 'w') as f:
|
with open(file_path, 'wb') as f:
|
||||||
f.write(key.exportKey('PEM'))
|
f.write(key.exportKey('PEM'))
|
||||||
self.stdout.write('RSA key successfully created at: ' + file_path)
|
self.stdout.write('RSA key successfully created at: ' + file_path)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.stdout.write('Something goes wrong: ' + e.message)
|
self.stdout.write('Something goes wrong: {0}'.format(e))
|
||||||
|
|
11
oidc_provider/tests/test_creatersakey_command.py
Normal file
11
oidc_provider/tests/test_creatersakey_command.py
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
from django.core.management import call_command
|
||||||
|
from django.test import TestCase, override_settings
|
||||||
|
from django.utils.six import StringIO
|
||||||
|
|
||||||
|
|
||||||
|
class CreateRSAKeyTest(TestCase):
|
||||||
|
@override_settings(BASE_DIR='/tmp')
|
||||||
|
def test_command_output(self):
|
||||||
|
out = StringIO()
|
||||||
|
call_command('creatersakey', stdout=out)
|
||||||
|
self.assertIn('RSA key successfully created', out.getvalue())
|
Loading…
Reference in a new issue