|
|
@ -1,4 +1,7 @@ |
|
|
|
# -*- coding: utf-8 -*- |
|
|
|
# © 2016 Akretion Raphaël REVERDY, Mourad EL HADJ MIMOUNE |
|
|
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
|
|
|
|
|
|
|
from odoo.tests.common import TransactionCase |
|
|
|
from odoo.tools.config import config |
|
|
|
from odoo.exceptions import ValidationError |
|
|
@ -20,6 +23,7 @@ class TestKeychain(TransactionCase): |
|
|
|
super(TestKeychain, self).setUp() |
|
|
|
|
|
|
|
self.keychain = self.env['keychain.account'] |
|
|
|
self.keychain_backend = self.env['keychain.backend'] |
|
|
|
config['keychain_key'] = Fernet.generate_key() |
|
|
|
|
|
|
|
self.old_running_env = config.get('running_env', '') |
|
|
@ -36,12 +40,20 @@ class TestKeychain(TransactionCase): |
|
|
|
return 'c' in data |
|
|
|
|
|
|
|
keychain_clss = self.keychain.__class__ |
|
|
|
keychain_clss._test_backend_init_data = _init_data |
|
|
|
keychain_clss._keychain_test_init_data = _init_data |
|
|
|
keychain_clss._keychain_test_validate_data = _validate_data |
|
|
|
keychain_clss._test_backend_validate_data = _validate_data |
|
|
|
|
|
|
|
keychain_backend_clss = self.keychain_backend.__class__ |
|
|
|
keychain_backend_clss._backend_name = 'test_backend' |
|
|
|
|
|
|
|
self.keychain._fields['namespace'].selection.append( |
|
|
|
('keychain_test', 'test') |
|
|
|
) |
|
|
|
self.keychain._fields['namespace'].selection.append( |
|
|
|
('test_backend', 'test backend') |
|
|
|
) |
|
|
|
|
|
|
|
def tearDown(self): |
|
|
|
config['running_env'] = self.old_running_env |
|
|
@ -218,3 +230,40 @@ class TestKeychain(TransactionCase): |
|
|
|
self.assertTrue(True, 'Should validate json') |
|
|
|
except: |
|
|
|
self.assertTrue(False, 'It should validate a good json') |
|
|
|
|
|
|
|
def test_keychain_bakend(self): |
|
|
|
"""It should work with valid data.""" |
|
|
|
config['keychain_key_dev'] = Fernet.generate_key() |
|
|
|
config['running_env'] = 'dev' |
|
|
|
vals = { |
|
|
|
'name': 'backend_test', |
|
|
|
'password': 'test', |
|
|
|
'data': '{"a": "o", "c": "b"}' |
|
|
|
} |
|
|
|
# we use new because keychain.backend is an abstract model |
|
|
|
backend = self.keychain_backend.new(vals) |
|
|
|
backend._inverse_keychain() |
|
|
|
account = backend._get_existing_keychain() |
|
|
|
self.assertEqual( |
|
|
|
account.data, '{"a": "o", "c": "b"}', |
|
|
|
'Account data is not correct') |
|
|
|
backend._inverse_password() |
|
|
|
self.assertTrue(account, 'Account was not created') |
|
|
|
self.assertEqual( |
|
|
|
account.clear_password, u'test', |
|
|
|
'Account clear password is not correct') |
|
|
|
self.assertEqual(backend.password, u'test') |
|
|
|
backend._compute_password() |
|
|
|
self.assertEqual( |
|
|
|
backend.password, u'******', 'Backend password was not computed') |
|
|
|
self.assertEqual( |
|
|
|
account.name, u'backend_test dev', 'Account name is not correct') |
|
|
|
self.assertEqual( |
|
|
|
account.namespace, u'test_backend', |
|
|
|
'Account namespace is not correct') |
|
|
|
self.assertEqual( |
|
|
|
account.environment, u'dev', 'Account environment is not correct') |
|
|
|
self.assertEqual( |
|
|
|
account.technical_name, '%s,%s' % (backend._name, backend.id), |
|
|
|
'Account technical_name is not correct') |
|
|
|
|