Skip to content

Commit

Permalink
fix: apply no_user_creation for AccessDenied
Browse files Browse the repository at this point in the history
  • Loading branch information
dnplkndll committed Jan 17, 2025
1 parent b14b991 commit a8955ff
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions auth_oauth_multi_token/tests/test_multi_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,11 @@ def test_no_provider_no_access(self):
"user_id": "oauth_uid_no_one",
}
params = self._fake_params()
try:
with self.assertRaises(exceptions.AccessDenied):
self.user_model._auth_oauth_signin(
self.provider_google.id, validation, params
)
# In version 18.0 AccessDenied exception is raising ValueError exception
except ValueError as e:
self.assertEqual(str(e), "Unknown token version")

with self.assertRaises(exceptions.AccessDenied):
self.user_model.with_context(
**{"no_user_creation": True}
)._auth_oauth_signin(self.provider_google.id, validation, params)

def _test_one_token(self):
validation = {
Expand Down

3 comments on commit a8955ff

@kobros-tech
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can not work anymore in version 18.0 as we see:

2025-02-04 14:35:37,065 29586 INFO auth_oauth_multi_token_1 odoo.addons.auth_oauth_multi_token.tests.test_multi_token: Starting TestMultiToken.test_no_provider_no_access ...
2025-02-04 14:35:37,081 29586 INFO auth_oauth_multi_token_1 odoo.addons.auth_oauth_multi_token.tests.test_multi_token: ======================================================================
2025-02-04 14:35:37,081 29586 ERROR auth_oauth_multi_token_1 odoo.addons.auth_oauth_multi_token.tests.test_multi_token: ERROR: TestMultiToken.test_no_provider_no_access
Traceback (most recent call last):
File "/home/kobros/Workspace/odoo18/odoo/addons/auth_oauth/models/res_users.py", line 104, in _auth_oauth_signin
raise AccessDenied()
odoo.exceptions.AccessDenied: Access Denied

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/kobros/Workspace/odoo18/server-auth/auth_oauth_multi_token/tests/test_multi_token.py", line 43, in test_no_provider_no_access
self.user_model._auth_oauth_signin(
File "/home/kobros/Workspace/odoo18/server-auth/auth_oauth_multi_token/models/res_users.py", line 45, in _auth_oauth_signin
res = super()._auth_oauth_signin(provider, validation, params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/kobros/Workspace/odoo18/odoo/addons/auth_oauth/models/res_users.py", line 115, in _auth_oauth_signin
login, _ = self.signup(values, token)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/kobros/Workspace/odoo18/odoo/addons/auth_signup/models/res_users.py", line 67, in signup
partner = self.env['res.partner']._signup_retrieve_partner(token, check_validity=True, raise_exception=True)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/kobros/Workspace/odoo18/odoo/addons/auth_signup/models/res_partner.py", line 128, in _signup_retrieve_partner
partner = self._get_partner_from_token(token)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/kobros/Workspace/odoo18/odoo/addons/auth_signup/models/res_partner.py", line 182, in _get_partner_from_token
if payload := tools.verify_hash_signed(self.sudo().env, 'signup', token):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/kobros/Workspace/odoo18/odoo/odoo/tools/misc.py", line 1821, in verify_hash_signed
raise ValueError('Unknown token version')
ValueError: Unknown token version

2025-02-04 14:35:37,082 29586 INFO auth_oauth_multi_token_1 odoo.addons.auth_oauth_multi_token.tests.test_multi_token: Starting TestMultiToken.test_remove_oauth_access_token ...
2025-02-04 14:35:37,170 29586 INFO auth_oauth_multi_token_1 odoo.addons.base.models.ir_attachment: filestore gc 63 checked, 1 removed
2025-02-04 14:35:37,192 29586 INFO auth_oauth_multi_token_1 odoo.modules.loading: Module auth_oauth_multi_token loaded in 1.06s (incl. 0.46s test), 134 queries (+190 test, +134 other)
2025-02-04 14:35:37,192 29586 ERROR auth_oauth_multi_token_1 odoo.modules.loading: Module auth_oauth_multi_token: 0 failures, 1 errors of 5 tests
2025-02-04 14:35:37,193 29586 INFO auth_oauth_multi_token_1 odoo.modules.loading: 26 modules loaded in 24.70s, 13458 queries (+13649 extra)
2025-02-04 14:35:37,957 29586 ERROR auth_oauth_multi_token_1 odoo.modules.loading: At least one test failed when loading the modules.
2025-02-04 14:35:37,970 29586 INFO auth_oauth_multi_token_1 odoo.modules.registry: Registry changed, signaling through the database
2025-02-04 14:35:37,972 29586 INFO auth_oauth_multi_token_1 odoo.modules.registry: Registry loaded in 48.054s

@dnplkndll
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure I understand. AccessDenied is the error you need to raise to pass the test. is expected.

@kobros-tech
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes it is but because the token was not written in the new version another exception was raised.

Now I updated the looking of the token and access denied is rising

Please sign in to comment.