|
4 | 4 | from django.contrib.auth.models import User |
5 | 5 |
|
6 | 6 | from api.use_cases.programs.list import ListFunctionsUseCase |
| 7 | +from core.domain.authorization.function_access_entry import FunctionAccessEntry |
7 | 8 | from core.domain.authorization.function_access_result import FunctionAccessResult |
| 9 | +from core.domain.business_models import BusinessModel |
8 | 10 | from core.models import Program, Provider, PLATFORM_PERMISSION_READ |
9 | 11 | from tests.utils import create_function_access_result |
10 | 12 |
|
@@ -71,3 +73,39 @@ def test_empty_list_when_no_functions_exist(self, user): |
71 | 73 | result = ListFunctionsUseCase().execute(user, accessible, None) |
72 | 74 |
|
73 | 75 | assert result == [] |
| 76 | + |
| 77 | + def test_provider_filter_narrows_catalog_to_that_provider(self, user): |
| 78 | + provider_a = Provider.objects.create(name="provider-a") |
| 79 | + provider_b = Provider.objects.create(name="provider-b") |
| 80 | + Program.objects.create(title="fn-a", author=user, provider=provider_a) |
| 81 | + Program.objects.create(title="fn-b", author=user, provider=provider_b) |
| 82 | + accessible = FunctionAccessResult( |
| 83 | + use_legacy_authorization=False, |
| 84 | + functions=[ |
| 85 | + FunctionAccessEntry( |
| 86 | + provider_name="provider-a", |
| 87 | + function_title="fn-a", |
| 88 | + business_model=BusinessModel.SUBSIDIZED, |
| 89 | + permissions={PLATFORM_PERMISSION_READ}, |
| 90 | + ), |
| 91 | + FunctionAccessEntry( |
| 92 | + provider_name="provider-b", |
| 93 | + function_title="fn-b", |
| 94 | + business_model=BusinessModel.SUBSIDIZED, |
| 95 | + permissions={PLATFORM_PERMISSION_READ}, |
| 96 | + ), |
| 97 | + ], |
| 98 | + ) |
| 99 | + |
| 100 | + result = ListFunctionsUseCase().execute(user, accessible, "catalog", provider="provider-a") |
| 101 | + |
| 102 | + assert [f.title for f in result] == ["fn-a"] |
| 103 | + |
| 104 | + def test_provider_filter_does_not_bypass_permissions(self, user, provider): |
| 105 | + # The function exists under the provider, but the user has no access to it. |
| 106 | + Program.objects.create(title="provider-fn", author=user, provider=provider) |
| 107 | + accessible = FunctionAccessResult(use_legacy_authorization=False, functions=[]) |
| 108 | + |
| 109 | + result = ListFunctionsUseCase().execute(user, accessible, "catalog", provider="my-provider") |
| 110 | + |
| 111 | + assert result == [] |
0 commit comments