Merge lp:~sylvain-legal/server-env-tools/7.0-fix-1319391 into lp:~server-env-tools-core-editors/server-env-tools/7.0

Proposed by Sylvain LE GAL (GRAP)
Status: Merged
Approved by: Yannick Vaucher @ Camptocamp
Approved revision: 79
Merged at revision: 77
Proposed branch: lp:~sylvain-legal/server-env-tools/7.0-fix-1319391
Merge into: lp:~server-env-tools-core-editors/server-env-tools/7.0
Diff against target: 145 lines (+123/-1)
3 files modified
auth_admin_passkey/model/res_users.py (+1/-1)
auth_admin_passkey/tests/__init__.py (+23/-0)
auth_admin_passkey/tests/test_auth_admin_passkey.py (+99/-0)
To merge this branch: bzr merge lp:~sylvain-legal/server-env-tools/7.0-fix-1319391
Reviewer Review Type Date Requested Status
Yannick Vaucher @ Camptocamp code review, no test Approve
Pedro Manuel Baeza code review Approve
Maxime Chambreuil (http://www.savoirfairelinux.com) Approve
Review via email: mp+219530@code.launchpad.net

Commit message

[ADD] Regression Tests;
[FIX] Uncaught error is raised when the admin user tries to connect with a bad login and his password;
[ADD] Test for the fixed bug;

Description of the change

Hi all,

I propose for merging this code to fix the bug https://bugs.launchpad.net/server-env-tools/+bug/1319391.

I added Test files to :
- avoid regressions;
- to give the possibility to the community to test more easily this module with other 'auth_...' module;

Regards.

To post a comment you must log in.
Revision history for this message
Maxime Chambreuil (http://www.savoirfairelinux.com) (max3903) :
review: Approve
Revision history for this message
Pedro Manuel Baeza (pedro.baeza) wrote :

LGTM, thanks.

Regards.

review: Approve (code review)
Revision history for this message
Yannick Vaucher @ Camptocamp (yvaucher-c2c) wrote :

LGTM

Thanks for the tests

review: Approve (code review, no test)
Revision history for this message
Yannick Vaucher @ Camptocamp (yvaucher-c2c) wrote :

Please next time explain what you do in your commit message.

Fix bug XY is not really understandable at a first glance.

To link the bug --fixes=lp:XY is there

Revision history for this message
Sylvain LE GAL (GRAP) (sylvain-legal) wrote :

Hi,

i can change it because you did'nt merge it.

BTW i put --fixes=lp:xxx too. (Launchpad indicates that correctly).

Regards.

*Sylvain LE GAL*

* Service informatiqueGroupement Régional Alimentaire de Proximité*
3 Grande rue des feuillants 69001 Lyon
*Bureau : *(+33) 09.72.32.33.17
*Astreinte :* (+33) 06.81.85.61.43
*Site Web** : *www.grap.coop
* Twitter : *@legalsylvain* <https://twitter.com/legalsylvain>*

2014-05-16 16:22 GMT+02:00 Yannick Vaucher @ Camptocamp <
<email address hidden>>:

> Please next time explain what you do in your commit message.
>
> Fix bug XY is not really understandable at a first glance.
>
> To link the bug --fixes=lp:XY is there
> --
>
> https://code.launchpad.net/~sylvain-legal/server-env-tools/7.0-fix-1319391/+merge/219530
> You are the owner of lp:~sylvain-legal/server-env-tools/7.0-fix-1319391.
>

Revision history for this message
Yannick Vaucher @ Camptocamp (yvaucher-c2c) wrote :

Already merged

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'auth_admin_passkey/model/res_users.py'
2--- auth_admin_passkey/model/res_users.py 2014-03-31 14:15:32 +0000
3+++ auth_admin_passkey/model/res_users.py 2014-05-14 13:37:38 +0000
4@@ -96,7 +96,7 @@
5 is admin password. In the second case, send mail to user and admin."""
6 user_id = super(res_users, self).authenticate(
7 db, login, password, user_agent_env)
8- if user_id != SUPERUSER_ID:
9+ if user_id and (user_id != SUPERUSER_ID):
10 same_password = False
11 cr = pooler.get_db(db).cursor()
12 try:
13
14=== added directory 'auth_admin_passkey/tests'
15=== added file 'auth_admin_passkey/tests/__init__.py'
16--- auth_admin_passkey/tests/__init__.py 1970-01-01 00:00:00 +0000
17+++ auth_admin_passkey/tests/__init__.py 2014-05-14 13:37:38 +0000
18@@ -0,0 +1,23 @@
19+# -*- encoding: utf-8 -*-
20+##############################################################################
21+#
22+# Admin Passkey module for OpenERP
23+# Copyright (C) 2013-2014 GRAP (http://www.grap.coop)
24+# @author Sylvain LE GAL (https://twitter.com/legalsylvain)
25+#
26+# This program is free software: you can redistribute it and/or modify
27+# it under the terms of the GNU Affero General Public License as
28+# published by the Free Software Foundation, either version 3 of the
29+# License, or (at your option) any later version.
30+#
31+# This program is distributed in the hope that it will be useful,
32+# but WITHOUT ANY WARRANTY; without even the implied warranty of
33+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34+# GNU Affero General Public License for more details.
35+#
36+# You should have received a copy of the GNU Affero General Public License
37+# along with this program. If not, see <http://www.gnu.org/licenses/>.
38+#
39+##############################################################################
40+
41+from . import test_auth_admin_passkey
42
43=== added file 'auth_admin_passkey/tests/test_auth_admin_passkey.py'
44--- auth_admin_passkey/tests/test_auth_admin_passkey.py 1970-01-01 00:00:00 +0000
45+++ auth_admin_passkey/tests/test_auth_admin_passkey.py 2014-05-14 13:37:38 +0000
46@@ -0,0 +1,99 @@
47+# -*- encoding: utf-8 -*-
48+##############################################################################
49+#
50+# Admin Passkey module for OpenERP
51+# Copyright (C) 2013-2014 GRAP (http://www.grap.coop)
52+# @author Sylvain LE GAL (https://twitter.com/legalsylvain)
53+#
54+# This program is free software: you can redistribute it and/or modify
55+# it under the terms of the GNU Affero General Public License as
56+# published by the Free Software Foundation, either version 3 of the
57+# License, or (at your option) any later version.
58+#
59+# This program is distributed in the hope that it will be useful,
60+# but WITHOUT ANY WARRANTY; without even the implied warranty of
61+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
62+# GNU Affero General Public License for more details.
63+#
64+# You should have received a copy of the GNU Affero General Public License
65+# along with this program. If not, see <http://www.gnu.org/licenses/>.
66+#
67+##############################################################################
68+
69+import threading
70+
71+from openerp.tests.common import TransactionCase
72+
73+
74+class TestAuthAdminPasskey(TransactionCase):
75+ """Tests for 'Auth Admin Passkey' Module"""
76+
77+ # Overload Section
78+ def setUp(self):
79+ super(TestAuthAdminPasskey, self).setUp()
80+
81+ # Get Registries
82+ self.imd_obj = self.registry('ir.model.data')
83+ self.ru_obj = self.registry('res.users')
84+
85+ # Get Database name
86+ self.db = threading.current_thread().dbname
87+
88+ # Get ids from xml_ids
89+ self.admin_user_id = self.imd_obj.get_object_reference(
90+ self.cr, self.uid, 'base', 'user_root')[1]
91+ self.demo_user_id = self.imd_obj.get_object_reference(
92+ self.cr, self.uid, 'base', 'user_demo')[1]
93+
94+ # Test Section
95+ def test_01_normal_login_admin_succeed(self):
96+ """[Regression Test]
97+ Test the succeed of login with 'admin' / 'admin'"""
98+ res = self.ru_obj.authenticate(self.db, 'admin', 'admin', {})
99+ self.assertEqual(
100+ res, self.admin_user_id,
101+ "'admin' / 'admin' login must succeed.")
102+
103+ def test_02_normal_login_admin_fail(self):
104+ """[Regression Test]
105+ Test the fail of login with 'admin' / 'bad_password'"""
106+ res = self.ru_obj.authenticate(self.db, 'admin', 'bad_password', {})
107+ self.assertEqual(
108+ res, False,
109+ "'admin' / 'bad_password' login must fail.")
110+
111+ def test_03_normal_login_demo_succeed(self):
112+ """[Regression Test]
113+ Test the succeed of login with 'demo' / 'demo'"""
114+ res = self.ru_obj.authenticate(self.db, 'demo', 'demo', {})
115+ self.assertEqual(
116+ res, self.demo_user_id,
117+ "'demo' / 'demo' login must succeed.")
118+
119+ def test_04_normal_login_demo_fail(self):
120+ """[Regression Test]
121+ Test the fail of login with 'demo' / 'bad_password'"""
122+ res = self.ru_obj.authenticate(self.db, 'demo', 'bad_password', {})
123+ self.assertEqual(
124+ res, False,
125+ "'demo' / 'bad_password' login must fail.")
126+
127+ def test_05_passkey_login_demo_succeed(self):
128+ """[New Feature]
129+ Test the succeed of login with 'demo' / 'admin'"""
130+ res = self.ru_obj.authenticate(self.db, 'demo', 'admin', {})
131+ self.assertEqual(
132+ res, self.demo_user_id,
133+ "'demo' / 'admin' login must succeed.")
134+
135+ def test_06_passkey_login_demo_succeed(self):
136+ """[Bug #1319391]
137+ Test the correct behaviour of login with 'bad_login' / 'admin'"""
138+ exception_raised = False
139+ try:
140+ res = self.ru_obj.authenticate(self.db, 'bad_login', 'admin', {})
141+ except:
142+ exception_raised = True
143+ self.assertEqual(
144+ exception_raised, False,
145+ "'bad_login' / 'admin' musn't raise Error.")