Archived
Revert "Usersync: Try fixing unicode errors"
This reverts commit 84ba4beb92.
This commit is contained in:
1 parent
84ba4beb92
commit
b29bba2381
7 files changed
+11
-55
No files matched your search
@@ -37,4 +37,4 @@ def create_radius_user(username, password, dry_run=False):
|
|||||||
|
|
||||||
logger.debug('Created radius user \'{}\''.format(username))
|
logger.debug('Created radius user \'{}\''.format(username))
|
||||||
|
|
||||||
return True
|
return True
|
||||||
@@ -159,5 +159,4 @@ class NewUserForm(forms.Form):
|
|||||||
# Rename firstname to first_name and lastname to last_name
|
# Rename firstname to first_name and lastname to last_name
|
||||||
cleaned_data['first_name'] = cleaned_data.pop('firstname')
|
cleaned_data['first_name'] = cleaned_data.pop('firstname')
|
||||||
cleaned_data['last_name'] = cleaned_data.pop('lastname')
|
cleaned_data['last_name'] = cleaned_data.pop('lastname')
|
||||||
|
return cleaned_data
|
||||||
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
|
# an intellectual property claim against the reference
|
||||||
# code, in which case it can be made public domain by
|
# code, in which case it can be made public domain by
|
||||||
# deleting all the comments and renaming all the variables
|
# deleting all the comments and renaming all the variables
|
||||||
|
|
||||||
import copy
|
import copy
|
||||||
import string
|
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 + s1) % BC] >> 16) & 0xFF] ^ (tt >> 16)) & 0xFF)
|
||||||
result.append((S[(t[(i + s2) % BC] >> 8) & 0xFF] ^ (tt >> 8)) & 0xFF)
|
result.append((S[(t[(i + s2) % BC] >> 8) & 0xFF] ^ (tt >> 8)) & 0xFF)
|
||||||
result.append((S[ t[(i + s3) % BC] & 0xFF] ^ tt ) & 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):
|
def decrypt(self, ciphertext):
|
||||||
if len(ciphertext) != self.block_size:
|
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 + s1) % BC] >> 16) & 0xFF] ^ (tt >> 16)) & 0xFF)
|
||||||
result.append((Si[(t[(i + s2) % BC] >> 8) & 0xFF] ^ (tt >> 8)) & 0xFF)
|
result.append((Si[(t[(i + s2) % BC] >> 8) & 0xFF] ^ (tt >> 8)) & 0xFF)
|
||||||
result.append((Si[ t[(i + s3) % BC] & 0xFF] ^ tt ) & 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):
|
def encrypt(key, block):
|
||||||
return rijndael(key, len(block)).encrypt(block)
|
return rijndael(key, len(block)).encrypt(block)
|
||||||
|
|||||||
+1
-44
@@ -1,44 +1 @@
|
|||||||
# coding: utf-8
|
from django.test import TestCase
|
||||||
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):
|
for start in range(0, len(padded_text), BLOCK_SIZE):
|
||||||
ciphertext += r.encrypt(padded_text[start:start+BLOCK_SIZE])
|
ciphertext += r.encrypt(padded_text[start:start+BLOCK_SIZE])
|
||||||
|
|
||||||
encoded = base64.b64encode(ciphertext.encode('utf-8'))
|
encoded = base64.b64encode(ciphertext)
|
||||||
|
|
||||||
return encoded
|
return encoded
|
||||||
|
|
||||||
|
|
||||||
def decrypt_rijndael(key, encoded):
|
def decrypt_rijndael(key, encoded):
|
||||||
padded_key = key.ljust(KEY_SIZE, '\0')
|
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)
|
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. """
|
""" 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', '')):
|
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)
|
form = NewUserForm(request.GET)
|
||||||
if not form.is_valid():
|
if not form.is_valid():
|
||||||
return JsonResponse({'errors': form.errors}, status=400)
|
return JsonResponse({'errors': form.errors})
|
||||||
|
|
||||||
user = form.cleaned_data
|
user = form.cleaned_data
|
||||||
logger.debug('Adding user \'{}\'.'.format(user['username']))
|
logger.debug('Adding user \'{}\'.'.format(user['username']))
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
# coding: utf-8
|
|
||||||
"""
|
"""
|
||||||
Django settings for this project.
|
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, ...)
|
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
||||||
from __future__ import unicode_literals
|
|
||||||
import os
|
import os
|
||||||
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
|
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user