Merge ~adam-collard/maas:rbac-error-1847244 into maas:master

Proposed by Adam Collard
Status: Merged
Approved by: Adam Collard
Approved revision: 6429e3a29c4a05c0a45cbac3db43bb8638b5abfd
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~adam-collard/maas:rbac-error-1847244
Merge into: maas:master
Diff against target: 56 lines (+26/-5)
2 files modified
src/maasserver/macaroon_auth.py (+2/-5)
src/maasserver/tests/test_macaroon_auth.py (+24/-0)
Reviewer Review Type Date Requested Status
Alberto Donato (community) Approve
MAAS Lander Approve
Review via email: mp+382238@code.launchpad.net

Commit message

Failure to get RBAC user details shouldn't traceback

To post a comment you must log in.
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b rbac-error-1847244 lp:~adam-collard/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: 6429e3a29c4a05c0a45cbac3db43bb8638b5abfd

review: Approve
Revision history for this message
Alberto Donato (ack) wrote :

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/maasserver/macaroon_auth.py b/src/maasserver/macaroon_auth.py
2index 44affa9..90e8c64 100644
3--- a/src/maasserver/macaroon_auth.py
4+++ b/src/maasserver/macaroon_auth.py
5@@ -417,14 +417,11 @@ def _validate_user_rbac(auth_info, username, client=None):
6 "admin-machines",
7 ).values()
8 )
9+ user_details = client.get_user_details(username)
10 except APIError:
11 raise UserValidationFailed()
12
13- return (
14- is_admin or access_to_pools,
15- is_admin,
16- client.get_user_details(username),
17- )
18+ return (is_admin or access_to_pools, is_admin, user_details)
19
20
21 class _IDClient(bakery.IdentityClient):
22diff --git a/src/maasserver/tests/test_macaroon_auth.py b/src/maasserver/tests/test_macaroon_auth.py
23index 1aed07a..d53682b 100644
24--- a/src/maasserver/tests/test_macaroon_auth.py
25+++ b/src/maasserver/tests/test_macaroon_auth.py
26@@ -409,6 +409,30 @@ class TestValidateUserExternalAuthWithRBAC(MAASServerTestCase):
27 # user is still enabled
28 self.assertTrue(self.user.is_active)
29
30+ def test_failed_user_details_check(self):
31+ self.client.allowed_for_user.side_effect = [
32+ {"admin": []},
33+ {
34+ "view": ["pool1", "pool2"],
35+ "view-all": [],
36+ "deploy-machines": [],
37+ "admin-machines": [],
38+ },
39+ ]
40+ self.client.get_user_details.side_effect = APIError(500, "fail!")
41+ valid = validate_user_external_auth(
42+ self.user,
43+ self.auth_info,
44+ now=lambda: self.now,
45+ rbac_client=self.client,
46+ )
47+ self.assertFalse(valid)
48+ # user is checked again, last check time is updated
49+ self.client.get_user_details.assert_called()
50+ self.assertEqual(self.user.userprofile.auth_last_check, self.now)
51+ # user is still enabled
52+ self.assertTrue(self.user.is_active)
53+
54
55 class MacaroonBakeryMockMixin:
56 """Mixin providing mock helpers for tests involving macaroonbakery."""

Subscribers

People subscribed via source and target branches