Skip to content

Commit 8739c76

Browse files
committed
Tests are updated to match the new behavior
Signed-off-by: jyejare <jyejare@redhat.com>
1 parent 1d1bfb0 commit 8739c76

File tree

3 files changed

+43
-18
lines changed

3 files changed

+43
-18
lines changed

sdk/python/feast/permissions/enforcer.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,19 +72,14 @@ def enforce_policy(
7272
if evaluator.is_decided():
7373
grant, explanations = evaluator.grant()
7474
if not grant:
75-
if not filter_only:
76-
logger.error(f"Permission denied: {','.join(explanations)}")
77-
raise FeastPermissionError(",".join(explanations))
78-
elif filter_only and not p.name_patterns:
79-
logger.error(f"Permission denied: {','.join(explanations)}")
80-
raise FeastPermissionError(",".join(explanations))
81-
else:
75+
if filter_only and p.name_patterns:
8276
continue
83-
if grant:
84-
logger.debug(
85-
f"Permission granted for {type(resource).__name__}:{resource.name}"
86-
)
87-
_permitted_resources.append(resource)
77+
logger.error(f"Permission denied: {','.join(explanations)}")
78+
raise FeastPermissionError(",".join(explanations))
79+
logger.debug(
80+
f"Permission granted for {type(resource).__name__}:{resource.name}"
81+
)
82+
_permitted_resources.append(resource)
8883
break
8984
else:
9085
if not filter_only:

sdk/python/tests/unit/permissions/auth/server/test_auth_registry_server.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@ def _test_get_historical_features(client_fs: FeatureStore):
142142

143143

144144
def _test_get_entity(client_fs: FeatureStore, permissions: list[Permission]):
145+
if _is_auth_enabled(client_fs) and len(permissions) == 0:
146+
with pytest.raises(FeastPermissionError):
147+
client_fs.get_entity("driver")
148+
return
149+
145150
if not _is_auth_enabled(client_fs) or _is_permission_enabled(
146151
client_fs, permissions, read_entities_perm
147152
):
@@ -156,6 +161,18 @@ def _test_get_entity(client_fs: FeatureStore, permissions: list[Permission]):
156161

157162

158163
def _test_list_entities(client_fs: FeatureStore, permissions: list[Permission]):
164+
if _is_auth_enabled(client_fs) and len(permissions) == 0:
165+
with pytest.raises(FeastPermissionError):
166+
client_fs.list_entities()
167+
return
168+
169+
if _is_auth_enabled(client_fs) and _permissions_exist_in_permission_list(
170+
[invalid_list_entities_perm], permissions
171+
):
172+
with pytest.raises(FeastPermissionError):
173+
client_fs.list_entities()
174+
return
175+
159176
entities = client_fs.list_entities()
160177

161178
if not _is_auth_enabled(client_fs) or _is_permission_enabled(
@@ -183,6 +200,10 @@ def _test_list_permissions(
183200
with pytest.raises(Exception):
184201
client_fs.list_permissions()
185202
return []
203+
elif _is_auth_enabled(client_fs) and len(applied_permissions) == 0:
204+
with pytest.raises(FeastPermissionError):
205+
client_fs.list_permissions()
206+
return []
186207
else:
187208
permissions = client_fs.list_permissions()
188209

@@ -229,6 +250,11 @@ def _is_auth_enabled(client_fs: FeatureStore) -> bool:
229250

230251

231252
def _test_get_fv(client_fs: FeatureStore, permissions: list[Permission]):
253+
if _is_auth_enabled(client_fs) and len(permissions) == 0:
254+
with pytest.raises(FeastPermissionError):
255+
client_fs.get_feature_view("driver_hourly_stats")
256+
return
257+
232258
if not _is_auth_enabled(client_fs) or _is_permission_enabled(
233259
client_fs, permissions, read_fv_perm
234260
):
@@ -249,6 +275,10 @@ def _test_list_fvs(client_fs: FeatureStore, permissions: list[Permission]):
249275
with pytest.raises(Exception):
250276
client_fs.list_feature_views()
251277
return []
278+
elif _is_auth_enabled(client_fs) and len(permissions) == 0:
279+
with pytest.raises(FeastPermissionError):
280+
client_fs.list_feature_views()
281+
return []
252282
else:
253283
fvs = client_fs.list_feature_views()
254284
for fv in fvs:

sdk/python/tests/unit/permissions/test_security_manager.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
@pytest.mark.parametrize(
1616
"username, requested_actions, allowed, allowed_single, raise_error_in_assert, raise_error_in_permit, intra_communication_flag",
1717
[
18-
(None, [], False, [False, False], [True, True], False, False),
18+
(None, [], False, [False, False], [True, True], True, False),
1919
(None, [], True, [True, True], [False, False], False, True),
2020
(
2121
"r",
@@ -42,7 +42,7 @@
4242
False,
4343
[False, False],
4444
[True, True],
45-
False,
45+
True,
4646
False,
4747
),
4848
("r", [AuthzedAction.UPDATE], True, [True, True], [False, False], False, True),
@@ -52,7 +52,7 @@
5252
False,
5353
[False, False],
5454
[True, True],
55-
False,
55+
True,
5656
False,
5757
),
5858
(
@@ -116,7 +116,7 @@
116116
False,
117117
[False, False],
118118
[True, True],
119-
True,
119+
False,
120120
False,
121121
),
122122
(
@@ -134,7 +134,7 @@
134134
False,
135135
[False, True],
136136
[True, False],
137-
True,
137+
False,
138138
False,
139139
),
140140
(
@@ -152,7 +152,7 @@
152152
False,
153153
[False, False],
154154
[True, True],
155-
True,
155+
False,
156156
False,
157157
),
158158
(

0 commit comments

Comments
 (0)