Archived
Revert "Usersync: Try fixing unicode errors"
This reverts commit 84ba4beb92.
This commit is contained in:
1 parent
84ba4beb92
commit
b29bba2381
6 files changed
+8
-52
No files matched your search
@@ -159,5 +159,4 @@ class NewUserForm(forms.Form):
|
||||
# Rename firstname to first_name and lastname to last_name
|
||||
cleaned_data['first_name'] = cleaned_data.pop('firstname')
|
||||
cleaned_data['last_name'] = cleaned_data.pop('lastname')
|
||||
|
||||
return cleaned_data
|
||||
@@ -27,6 +27,7 @@ If any strings are of the wrong length a ValueError is thrown
|
||||
# an intellectual property claim against the reference
|
||||
# code, in which case it can be made public domain by
|
||||
# deleting all the comments and renaming all the variables
|
||||
|
||||
import copy
|
||||
import string
|
||||
|
||||
@@ -310,7 +311,7 @@ class rijndael:
|
||||
result.append((S[(t[(i + s1) % BC] >> 16) & 0xFF] ^ (tt >> 16)) & 0xFF)
|
||||
result.append((S[(t[(i + s2) % BC] >> 8) & 0xFF] ^ (tt >> 8)) & 0xFF)
|
||||
result.append((S[ t[(i + s3) % BC] & 0xFF] ^ tt ) & 0xFF)
|
||||
return u''.join(map(unichr, result))
|
||||
return ''.join(map(chr, result))
|
||||
|
||||
def decrypt(self, ciphertext):
|
||||
if len(ciphertext) != self.block_size:
|
||||
@@ -353,7 +354,7 @@ class rijndael:
|
||||
result.append((Si[(t[(i + s1) % BC] >> 16) & 0xFF] ^ (tt >> 16)) & 0xFF)
|
||||
result.append((Si[(t[(i + s2) % BC] >> 8) & 0xFF] ^ (tt >> 8)) & 0xFF)
|
||||
result.append((Si[ t[(i + s3) % BC] & 0xFF] ^ tt ) & 0xFF)
|
||||
return u''.join(map(unichr, result))
|
||||
return ''.join(map(chr, result))
|
||||
|
||||
def encrypt(key, block):
|
||||
return rijndael(key, len(block)).encrypt(block)
|
||||
|
||||
@@ -1,44 +1 @@
|
||||
# coding: utf-8
|
||||
from __future__ import unicode_literals
|
||||
from django.conf import settings
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.test import TestCase
|
||||
from neuf_userinfo.utils import decrypt_rijndael, encrypt_rijndael
|
||||
|
||||
|
||||
class UserSyncTest(TestCase):
|
||||
def test_usersync_decode_unicode_password(self):
|
||||
usersync_url = reverse('usersync')
|
||||
clear_password = 'berombråk123'
|
||||
key = settings.INSIDE_USERSYNC_ENC_KEY
|
||||
|
||||
password = encrypt_rijndael(key, clear_password)
|
||||
|
||||
request_params = {
|
||||
'api_key': 'lol',
|
||||
'firstname': 'a',
|
||||
'lastname': 'b',
|
||||
'password': password,
|
||||
'email': 'a@b.com',
|
||||
'username': 'test',
|
||||
'groups': 'dns-alle'
|
||||
}
|
||||
response = self.client.get(usersync_url, request_params)
|
||||
self.assertEqual(response.status_code, 200, response)
|
||||
|
||||
|
||||
class RijndaelTest(TestCase):
|
||||
def test_decode_unicode_password(self):
|
||||
clear_password = 'berombråk123'
|
||||
key = settings.INSIDE_USERSYNC_ENC_KEY
|
||||
|
||||
password = encrypt_rijndael(key, clear_password)
|
||||
self.assertEqual(decrypt_rijndael(key, password), clear_password)
|
||||
|
||||
def test_decode_ascii_password(self):
|
||||
clear_password = 'beromkos123'
|
||||
key = settings.INSIDE_USERSYNC_ENC_KEY
|
||||
|
||||
password = encrypt_rijndael(key, clear_password)
|
||||
self.assertEqual(decrypt_rijndael(key, password), clear_password)
|
||||
|
||||
@@ -44,14 +44,15 @@ def encrypt_rijndael(key, plaintext):
|
||||
for start in range(0, len(padded_text), BLOCK_SIZE):
|
||||
ciphertext += r.encrypt(padded_text[start:start+BLOCK_SIZE])
|
||||
|
||||
encoded = base64.b64encode(ciphertext.encode('utf-8'))
|
||||
encoded = base64.b64encode(ciphertext)
|
||||
|
||||
return encoded
|
||||
|
||||
|
||||
def decrypt_rijndael(key, encoded):
|
||||
padded_key = key.ljust(KEY_SIZE, '\0')
|
||||
ciphertext = base64.b64decode(encoded).decode('utf-8')
|
||||
|
||||
ciphertext = base64.b64decode(encoded)
|
||||
|
||||
r = rijndael.rijndael(padded_key, BLOCK_SIZE)
|
||||
|
||||
|
||||
@@ -118,11 +118,11 @@ class AddNewUserView(View):
|
||||
""" Adds a new user to our internal services. See .utils.add_new_user for details. """
|
||||
|
||||
if not self.validate_api_key(request.GET.get('api_key', '')):
|
||||
return JsonResponse({'errors': 'Invalid api_key'}, status=400)
|
||||
return JsonResponse({'errors': 'Invalid api_key'})
|
||||
|
||||
form = NewUserForm(request.GET)
|
||||
if not form.is_valid():
|
||||
return JsonResponse({'errors': form.errors}, status=400)
|
||||
return JsonResponse({'errors': form.errors})
|
||||
|
||||
user = form.cleaned_data
|
||||
logger.debug('Adding user \'{}\'.'.format(user['username']))
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
# coding: utf-8
|
||||
"""
|
||||
Django settings for this project.
|
||||
|
||||
@@ -10,7 +9,6 @@ https://docs.djangoproject.com/en/1.6/ref/settings/
|
||||
"""
|
||||
|
||||
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
||||
from __future__ import unicode_literals
|
||||
import os
|
||||
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
|
||||
|
||||
|
||||
Reference in new issue
Block a user