Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 9 additions & 14 deletions apps/capabilities/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,15 @@ def has_permission(self, request, view):
slug__in=token_scopes
).values_list('protected_resources', flat=True).all())

# this is a shorterm fix to reject all tokens that do not have either
# patient/coverage.read or patient/ExplanationOfBenefit.read
if ("patient/Coverage.read" in token_scopes) or ("patient/ExplanationOfBenefit.read" in token_scopes):
for scope in scopes:
for method, path in json.loads(scope):
if method != request.method:
continue
if path == request.path:
return True
if re.fullmatch(path, request.path) is not None:
return True
return False
else:
return False
for scope in scopes:
for method, path in json.loads(scope):
if method != request.method:
continue
if path == request.path:
return True
if re.fullmatch(path, request.path) is not None:
return True
return False
else:
# BB2-237: Replaces ASSERT with exception. We should never reach here.
mesg = ("TokenHasScope requires the `oauth2_provider.rest_framework.OAuth2Authentication`"
Expand Down
2 changes: 0 additions & 2 deletions apps/capabilities/tests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import json
import unittest

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

@unittest.skip("Broke with quick fix")
def test_request_is_protected(self):
request = SimpleRequest("scope")
request.method = "GET"
Expand Down
2 changes: 1 addition & 1 deletion apps/dot_ext/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ def clean(self):
scope = ""

# Remove demographic information scopes, if beneficiary is not sharing
if cleaned_data.get("share_demographic_scopes") == "False":
if cleaned_data.get("share_demographic_scopes") != "True":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch. This is way more explicit.

cleaned_data["scope"] = " ".join(
[
s
Expand Down
6 changes: 3 additions & 3 deletions apps/dot_ext/tests/demographic_scopes_test_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@
"request_scopes": APPLICATION_SCOPES_FULL,
# Result:
"result_has_error": False,
"result_token_scopes_granted": APPLICATION_SCOPES_FULL,
"result_token_scopes_granted": APPLICATION_SCOPES_NON_DEMOGRAPHIC,
"result_access_token_count": 1,
"result_refresh_token_count": 1,
"result_archived_token_count": 0,
Expand Down Expand Up @@ -221,7 +221,7 @@
"request_scopes": APPLICATION_SCOPES_FULL,
# Result:
"result_has_error": False,
"result_token_scopes_granted": APPLICATION_SCOPES_FULL,
"result_token_scopes_granted": APPLICATION_SCOPES_NON_DEMOGRAPHIC,
"result_access_token_count": 3,
"result_refresh_token_count": 3,
"result_archived_token_count": 1,
Expand Down Expand Up @@ -314,7 +314,7 @@
"request_scopes": SCOPES_JUST_PATIENT_AND_A,
# Result:
"result_has_error": False,
"result_token_scopes_granted": SCOPES_JUST_PATIENT_AND_A,
"result_token_scopes_granted": SCOPES_JUST_A,
"result_access_token_count": 3,
"result_refresh_token_count": 3,
"result_archived_token_count": 8,
Expand Down
15 changes: 1 addition & 14 deletions apps/dot_ext/tests/test_views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import json
import base64
import unittest
from datetime import date, timedelta

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

@unittest.skip("Broke with quick fix")
def test_post_with_share_demographic_scopes(self):
# Test with-out new_auth switch
self.testing_post_with_share_demographic_scopes()

@unittest.skip("Broke with quick fix")
@override_switch("new_auth", active=True)
def test_post_with_share_demographic_scopes_new_auth_switch(self):
# Test with new_auth switch.
self.testing_post_with_share_demographic_scopes()

@unittest.skip("Broke with quick fix")
@override_switch("require-scopes", active=True)
def testing_post_with_share_demographic_scopes(self):
def test_post_with_share_demographic_scopes(self):
"""
Test authorization related to different, beneficiary "share_demographic_scopes",
application.require_demographic_scopes, and requested scopes values.
Expand Down
Loading