From 36f8bcbb5df95c10deea461ee5afddbfbf746f16 Mon Sep 17 00:00:00 2001 From: Pablo SEMINARIO Date: Sat, 17 Oct 2015 22:58:34 +0200 Subject: [PATCH 1/4] Add a basic test for the creatersakey management command --- oidc_provider/tests/test_creatersakey_command.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 oidc_provider/tests/test_creatersakey_command.py diff --git a/oidc_provider/tests/test_creatersakey_command.py b/oidc_provider/tests/test_creatersakey_command.py new file mode 100644 index 0000000..81f676e --- /dev/null +++ b/oidc_provider/tests/test_creatersakey_command.py @@ -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()) From daee582207d13e0f210376222e0fa2e740425467 Mon Sep 17 00:00:00 2001 From: Pablo SEMINARIO Date: Sat, 17 Oct 2015 23:02:37 +0200 Subject: [PATCH 2/4] Remove unused CommandError import --- oidc_provider/management/commands/creatersakey.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/oidc_provider/management/commands/creatersakey.py b/oidc_provider/management/commands/creatersakey.py index fb406f1..12034b0 100644 --- a/oidc_provider/management/commands/creatersakey.py +++ b/oidc_provider/management/commands/creatersakey.py @@ -1,7 +1,7 @@ from Crypto.PublicKey import RSA from django.conf import settings -from django.core.management.base import BaseCommand, CommandError +from django.core.management.base import BaseCommand class Command(BaseCommand): From b89115165c55e51e76a533ba4eb9637897319e0a Mon Sep 17 00:00:00 2001 From: Pablo SEMINARIO Date: Sat, 17 Oct 2015 23:06:41 +0200 Subject: [PATCH 3/4] Fix use of deprecated Exception.message in Python 3 --- oidc_provider/management/commands/creatersakey.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/oidc_provider/management/commands/creatersakey.py b/oidc_provider/management/commands/creatersakey.py index 12034b0..c1954ff 100644 --- a/oidc_provider/management/commands/creatersakey.py +++ b/oidc_provider/management/commands/creatersakey.py @@ -15,4 +15,4 @@ class Command(BaseCommand): f.write(key.exportKey('PEM')) self.stdout.write('RSA key successfully created at: ' + file_path) except Exception as e: - self.stdout.write('Something goes wrong: ' + e.message) + self.stdout.write('Something goes wrong: {0}'.format(e)) From db977f65a6f986508c826b645b9c94e5eff4f83f Mon Sep 17 00:00:00 2001 From: Pablo SEMINARIO Date: Sat, 17 Oct 2015 23:12:15 +0200 Subject: [PATCH 4/4] Append binary file mode to write RSA exported key needed by Python 3 --- oidc_provider/management/commands/creatersakey.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/oidc_provider/management/commands/creatersakey.py b/oidc_provider/management/commands/creatersakey.py index c1954ff..c6a5352 100644 --- a/oidc_provider/management/commands/creatersakey.py +++ b/oidc_provider/management/commands/creatersakey.py @@ -11,7 +11,7 @@ class Command(BaseCommand): try: key = RSA.generate(1024) 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')) self.stdout.write('RSA key successfully created at: ' + file_path) except Exception as e: