|
1 | 1 | import pytest |
2 | 2 | import uuid |
| 3 | +from unittest import mock |
3 | 4 |
|
4 | 5 | from api.base.settings.defaults import API_BASE |
5 | 6 | from api_tests import utils |
| 7 | +from framework.auth.cas import CasResponse |
6 | 8 | from framework.auth.core import Auth |
7 | 9 | from osf.models import RegistrationSchema |
8 | 10 | from osf_tests.factories import ( |
@@ -1025,3 +1027,24 @@ def test_POST_search_collections_disease_data_type( |
1025 | 1027 | assert res.status_code == 200 |
1026 | 1028 | assert res.json['links']['meta']['total'] == 2 |
1027 | 1029 | assert len(res.json['data']) == 2 |
| 1030 | + |
| 1031 | + def test_POST_search_collections_scope(self, app, url_collection_search, user): |
| 1032 | + payload = self.post_payload(q='Collection') |
| 1033 | + |
| 1034 | + token_invalid = CasResponse( |
| 1035 | + authenticated=True, |
| 1036 | + user=user._id, |
| 1037 | + attributes={'accessTokenScope': ['osf.full_read']} |
| 1038 | + ) |
| 1039 | + with mock.patch('framework.auth.cas.CasClient.profile', return_value=token_invalid): |
| 1040 | + res = app.post_json_api(url_collection_search, payload, auth='some-invalid-token', expect_errors=True, auth_type='jwt') |
| 1041 | + assert res.status_code == 403 |
| 1042 | + |
| 1043 | + token_valid = CasResponse( |
| 1044 | + authenticated=True, |
| 1045 | + user=user._id, |
| 1046 | + attributes={'accessTokenScope': ['osf.full_read', 'osf.full_write']} |
| 1047 | + ) |
| 1048 | + with mock.patch('framework.auth.cas.CasClient.profile', return_value=token_valid): |
| 1049 | + res = app.post_json_api(url_collection_search, payload, auth='some-valid-token', auth_type='jwt') |
| 1050 | + assert res.status_code == 200 |
0 commit comments