[MIG] migration of keychain to v11

remove coding utf8
add base_sparse_field to get Serialized fields
run 2to3
bump version
manual adaptation of python3
This commit is contained in:
Martin trigaux 2017-10-30 17:04:34 +01:00 committed by Florian da Costa
parent 2027176a36
commit f54438b3cd
5 changed files with 13 additions and 17 deletions

View File

@ -1,10 +1,9 @@
# -*- coding: utf-8 -*-
# Copyright <2016> Akretion # Copyright <2016> Akretion
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{ {
"name": "Keychain", "name": "Keychain",
"summary": "Store accounts and credentials", "summary": "Store accounts and credentials",
"version": "10.0.1.0.0", "version": "11.0.1.0.0",
"category": "Uncategorized", "category": "Uncategorized",
"website": "https://akretion.com/", "website": "https://akretion.com/",
"author": "Akretion, Odoo Community Association (OCA)", "author": "Akretion, Odoo Community Association (OCA)",
@ -17,6 +16,7 @@
}, },
"depends": [ "depends": [
"base_setup", "base_setup",
"base_sparse_field",
], ],
"data": [ "data": [
"security/ir.model.access.csv", "security/ir.model.access.csv",

View File

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# © 2016 Akretion Mourad EL HADJ MIMOUNE, David BEAL, Raphaël REVERDY # © 2016 Akretion Mourad EL HADJ MIMOUNE, David BEAL, Raphaël REVERDY
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from functools import wraps from functools import wraps
@ -153,13 +152,13 @@ class KeychainAccount(models.Model):
@classmethod @classmethod
def _encode_password(cls, data, env): def _encode_password(cls, data, env):
cipher = cls._get_cipher(env) cipher = cls._get_cipher(env)
return cipher.encrypt(str((data or '').encode('UTF-8'))) return cipher.encrypt((data or '').encode())
@classmethod @classmethod
def _decode_password(cls, data): def _decode_password(cls, data):
cipher = cls._get_cipher() cipher = cls._get_cipher()
try: try:
return unicode(cipher.decrypt(str(data)), 'UTF-8') return str(cipher.decrypt(data.encode()), 'UTF-8')
except InvalidToken: except InvalidToken:
raise Warning(_( raise Warning(_(
"Password has been encrypted with a different " "Password has been encrypted with a different "

View File

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# © 2016 Akretion Sebastien Beau # © 2016 Akretion Sebastien Beau
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

View File

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# © 2016 Akretion Raphaël REVERDY # © 2016 Akretion Raphaël REVERDY
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
@ -62,7 +61,7 @@ class TestKeychain(TransactionCase):
def test_password(self): def test_password(self):
"""It should encrypt passwords.""" """It should encrypt passwords."""
account = self._create_account() account = self._create_account()
passwords = ('', '12345', 'djkqfljfqm', u""""'(§è!ç""") passwords = ('', '12345', 'djkqfljfqm', """"'(§è!ç""")
for password in passwords: for password in passwords:
account.clear_password = password account.clear_password = password

View File

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# © 2016 Akretion Mourad EL HADJ MIMOUNE # © 2016 Akretion Mourad EL HADJ MIMOUNE
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
@ -57,25 +56,25 @@ class TestKeychain(TransactionCase):
backend = self.keychain_backend.new(vals) backend = self.keychain_backend.new(vals)
backend._inverse_keychain() backend._inverse_keychain()
account = backend._get_existing_keychain() account = backend._get_existing_keychain()
self.assertEqual( self.assertDictEqual(
account.data, '{"a": "o", "c": "b"}', account.get_data(), {"a": "o", "c": "b"},
'Account data is not correct') 'Account data is not correct')
backend._inverse_password() backend._inverse_password()
self.assertTrue(account, 'Account was not created') self.assertTrue(account, 'Account was not created')
self.assertEqual( self.assertEqual(
account.clear_password, u'test', account.clear_password, 'test',
'Account clear password is not correct') 'Account clear password is not correct')
self.assertEqual(backend.password, u'test') self.assertEqual(backend.password, 'test')
backend._compute_password() backend._compute_password()
self.assertEqual( self.assertEqual(
backend.password, u'******', 'Backend password was not computed') backend.password, '******', 'Backend password was not computed')
self.assertEqual( self.assertEqual(
account.name, u'backend_test dev', 'Account name is not correct') account.name, 'backend_test dev', 'Account name is not correct')
self.assertEqual( self.assertEqual(
account.namespace, u'test_backend', account.namespace, 'test_backend',
'Account namespace is not correct') 'Account namespace is not correct')
self.assertEqual( self.assertEqual(
account.environment, u'dev', 'Account environment is not correct') account.environment, 'dev', 'Account environment is not correct')
self.assertEqual( self.assertEqual(
account.technical_name, '%s,%s' % (backend._name, backend.id), account.technical_name, '%s,%s' % (backend._name, backend.id),
'Account technical_name is not correct') 'Account technical_name is not correct')