Skip to content

Commit 3d7f3b4

Browse files
authored
Undo short-term fix and adjust tests (#1261)
1 parent 9f180f1 commit 3d7f3b4

File tree

7 files changed

+18
-37
lines changed

7 files changed

+18
-37
lines changed

apps/capabilities/permissions.py

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,15 @@ def has_permission(self, request, view):
3737
slug__in=token_scopes
3838
).values_list('protected_resources', flat=True).all())
3939

40-
# this is a shorterm fix to reject all tokens that do not have either
41-
# patient/coverage.read or patient/ExplanationOfBenefit.read
42-
if ("patient/Coverage.read" in token_scopes) or ("patient/ExplanationOfBenefit.read" in token_scopes):
43-
for scope in scopes:
44-
for method, path in json.loads(scope):
45-
if method != request.method:
46-
continue
47-
if path == request.path:
48-
return True
49-
if re.fullmatch(path, request.path) is not None:
50-
return True
51-
return False
52-
else:
53-
return False
40+
for scope in scopes:
41+
for method, path in json.loads(scope):
42+
if method != request.method:
43+
continue
44+
if path == request.path:
45+
return True
46+
if re.fullmatch(path, request.path) is not None:
47+
return True
48+
return False
5449
else:
5550
# BB2-237: Replaces ASSERT with exception. We should never reach here.
5651
mesg = ("TokenHasScope requires the `oauth2_provider.rest_framework.OAuth2Authentication`"

apps/capabilities/tests.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import json
2-
import unittest
32

43
from django.contrib.auth.models import Group
54
from django.test import TestCase
@@ -41,7 +40,6 @@ def setUp(self):
4140
protected_resources=json.dumps([["POST", "/path"]]),
4241
)
4342

44-
@unittest.skip("Broke with quick fix")
4543
def test_request_is_protected(self):
4644
request = SimpleRequest("scope")
4745
request.method = "GET"

apps/dot_ext/forms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ def clean(self):
335335
scope = ""
336336

337337
# Remove demographic information scopes, if beneficiary is not sharing
338-
if cleaned_data.get("share_demographic_scopes") == "False":
338+
if cleaned_data.get("share_demographic_scopes") != "True":
339339
cleaned_data["scope"] = " ".join(
340340
[
341341
s

apps/dot_ext/tests/demographic_scopes_test_cases.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
--------------------------------------------------
4848
USED in the following test:
4949
apps.dot_ext.tests.test_form_oauth2
50-
.TestSimpleAllowFormForm.test_form()
50+
.TestSimpleAllowForm.test_form()
5151
Test case dictionary key and value meanings:
5252
REQUEST PARAMETERS:
5353
These are used to setup the authorization request.
@@ -68,7 +68,7 @@
6868
"request_scopes": APPLICATION_SCOPES_FULL,
6969
# Result:
7070
"result_form_is_valid": True,
71-
"result_token_scopes_granted": APPLICATION_SCOPES_FULL,
71+
"result_token_scopes_granted": APPLICATION_SCOPES_NON_DEMOGRAPHIC,
7272
},
7373
"test 2: share_demographic_scopes = False": {
7474
# Request:
@@ -181,7 +181,7 @@
181181
"request_scopes": APPLICATION_SCOPES_FULL,
182182
# Result:
183183
"result_has_error": False,
184-
"result_token_scopes_granted": APPLICATION_SCOPES_FULL,
184+
"result_token_scopes_granted": APPLICATION_SCOPES_NON_DEMOGRAPHIC,
185185
"result_access_token_count": 1,
186186
"result_refresh_token_count": 1,
187187
"result_archived_token_count": 0,
@@ -221,7 +221,7 @@
221221
"request_scopes": APPLICATION_SCOPES_FULL,
222222
# Result:
223223
"result_has_error": False,
224-
"result_token_scopes_granted": APPLICATION_SCOPES_FULL,
224+
"result_token_scopes_granted": APPLICATION_SCOPES_NON_DEMOGRAPHIC,
225225
"result_access_token_count": 3,
226226
"result_refresh_token_count": 3,
227227
"result_archived_token_count": 1,
@@ -314,7 +314,7 @@
314314
"request_scopes": SCOPES_JUST_PATIENT_AND_A,
315315
# Result:
316316
"result_has_error": False,
317-
"result_token_scopes_granted": SCOPES_JUST_PATIENT_AND_A,
317+
"result_token_scopes_granted": SCOPES_JUST_A,
318318
"result_access_token_count": 3,
319319
"result_refresh_token_count": 3,
320320
"result_archived_token_count": 8,

apps/dot_ext/tests/test_form_oauth2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from .demographic_scopes_test_cases import FORM_OAUTH2_SCOPES_TEST_CASES
55

66

7-
class TestSimpleAllowFormForm(BaseApiTest):
7+
class TestSimpleAllowForm(BaseApiTest):
88
fixtures = ['scopes.json']
99

1010
def test_form(self):

apps/dot_ext/tests/test_verify_bfd_headers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def _create_test_token(self, user, application):
6363
"scope": application.scopes().split(" "),
6464
"expires_in": 86400,
6565
"allow": True,
66+
"share_demographic_scopes": True
6667
}
6768
if application.authorization_grant_type == Application.GRANT_IMPLICIT:
6869
payload["response_type"] = "token"

apps/dot_ext/tests/test_views.py

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import json
22
import base64
3-
import unittest
43
from datetime import date, timedelta
54

65
from django.conf import settings
@@ -163,20 +162,8 @@ def test_post_with_restricted_scopes_issues_token_with_same_scopes(self):
163162
# and here we test that only the capability-a scope has been issued
164163
self.assertEqual(content["scope"], "capability-a")
165164

166-
@unittest.skip("Broke with quick fix")
167-
def test_post_with_share_demographic_scopes(self):
168-
# Test with-out new_auth switch
169-
self.testing_post_with_share_demographic_scopes()
170-
171-
@unittest.skip("Broke with quick fix")
172-
@override_switch("new_auth", active=True)
173-
def test_post_with_share_demographic_scopes_new_auth_switch(self):
174-
# Test with new_auth switch.
175-
self.testing_post_with_share_demographic_scopes()
176-
177-
@unittest.skip("Broke with quick fix")
178165
@override_switch("require-scopes", active=True)
179-
def testing_post_with_share_demographic_scopes(self):
166+
def test_post_with_share_demographic_scopes(self):
180167
"""
181168
Test authorization related to different, beneficiary "share_demographic_scopes",
182169
application.require_demographic_scopes, and requested scopes values.

0 commit comments

Comments
 (0)