|
4 | 4 | from google.protobuf.empty_pb2 import Empty |
5 | 5 |
|
6 | 6 | from feast.errors import FeastPermissionError, ProjectObjectNotFoundException |
| 7 | +from feast.infra.infra_object import Infra |
7 | 8 | from feast.permissions.permission import AuthzedAction, Permission |
8 | 9 | from feast.permissions.policy import RoleBasedPolicy |
9 | 10 | from feast.permissions.security_manager import ( |
@@ -75,6 +76,8 @@ def get_project(name: str, allow_cache: bool = False): |
75 | 76 | registry.get_project = Mock(side_effect=get_project) |
76 | 77 | registry.refresh = Mock() |
77 | 78 | registry.commit = Mock() |
| 79 | + registry.get_infra = Mock(return_value=Infra()) |
| 80 | + registry.update_infra = Mock() |
78 | 81 | return RegistryServer(registry=registry), registry |
79 | 82 |
|
80 | 83 |
|
@@ -193,3 +196,81 @@ def test_commit_allows_with_only_create_permission_on_new_project( |
193 | 196 |
|
194 | 197 | assert response == Empty() |
195 | 198 | registry.commit.assert_called_once() |
| 199 | + |
| 200 | + |
| 201 | +def test_get_infra_allows_missing_project_without_auth(): |
| 202 | + no_security_manager() |
| 203 | + server, registry = _server_with_projects("existing") |
| 204 | + |
| 205 | + response = server.GetInfra( |
| 206 | + RegistryServer_pb2.GetInfraRequest(project="brand-new", allow_cache=True), |
| 207 | + None, |
| 208 | + ) |
| 209 | + |
| 210 | + assert response == Infra().to_proto() |
| 211 | + registry.get_infra.assert_called_once_with(project="brand-new", allow_cache=True) |
| 212 | + |
| 213 | + |
| 214 | +def test_get_infra_allows_missing_project_with_create_permission(auth_security_manager): |
| 215 | + auth_security_manager.set_current_user(User("creator", ["team-a-creator"])) |
| 216 | + server, registry = _server_with_projects("team-b-project") |
| 217 | + |
| 218 | + response = server.GetInfra( |
| 219 | + RegistryServer_pb2.GetInfraRequest(project="team-a-new", allow_cache=True), |
| 220 | + None, |
| 221 | + ) |
| 222 | + |
| 223 | + assert response == Infra().to_proto() |
| 224 | + registry.get_infra.assert_called_once_with(project="team-a-new", allow_cache=True) |
| 225 | + |
| 226 | + |
| 227 | +def test_get_infra_denies_missing_project_without_create_permission( |
| 228 | + auth_security_manager, |
| 229 | +): |
| 230 | + auth_security_manager.set_current_user(User("bob", ["team-b"])) |
| 231 | + server, _ = _server_with_projects("team-b-project") |
| 232 | + |
| 233 | + with pytest.raises(FeastPermissionError): |
| 234 | + server.GetInfra( |
| 235 | + RegistryServer_pb2.GetInfraRequest(project="team-a-new", allow_cache=True), |
| 236 | + None, |
| 237 | + ) |
| 238 | + |
| 239 | + |
| 240 | +def test_get_infra_requires_describe_for_existing_project(auth_security_manager): |
| 241 | + auth_security_manager.set_current_user(User("alice", ["team-a"])) |
| 242 | + server, registry = _server_with_projects("team-a-project", "team-b-project") |
| 243 | + |
| 244 | + response = server.GetInfra( |
| 245 | + RegistryServer_pb2.GetInfraRequest(project="team-a-project", allow_cache=True), |
| 246 | + None, |
| 247 | + ) |
| 248 | + assert response == Infra().to_proto() |
| 249 | + registry.get_infra.assert_called_once_with( |
| 250 | + project="team-a-project", allow_cache=True |
| 251 | + ) |
| 252 | + |
| 253 | + with pytest.raises(FeastPermissionError): |
| 254 | + server.GetInfra( |
| 255 | + RegistryServer_pb2.GetInfraRequest( |
| 256 | + project="team-b-project", allow_cache=True |
| 257 | + ), |
| 258 | + None, |
| 259 | + ) |
| 260 | + |
| 261 | + |
| 262 | +def test_update_infra_allows_missing_project_with_create_permission( |
| 263 | + auth_security_manager, |
| 264 | +): |
| 265 | + auth_security_manager.set_current_user(User("creator", ["team-a-creator"])) |
| 266 | + server, registry = _server_with_projects("team-b-project") |
| 267 | + |
| 268 | + response = server.UpdateInfra( |
| 269 | + RegistryServer_pb2.UpdateInfraRequest( |
| 270 | + infra=Infra().to_proto(), project="team-a-new", commit=True |
| 271 | + ), |
| 272 | + None, |
| 273 | + ) |
| 274 | + |
| 275 | + assert response == Empty() |
| 276 | + registry.update_infra.assert_called_once() |
0 commit comments