-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add feature flag for checking allowed data fields
Adds setting for allowed data field check named as: ENABLE_ALLOWED_DATA_FIELDS_RESTRICTION The setting defaults False. When False, app logs a warning message when there is a query trying to access a field which is not in service's allowed_data_fields Refs HP-2319
- Loading branch information
Showing
4 changed files
with
84 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
profiles/tests/test_allowed_data_field_restriction_flag.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
from unittest import mock | ||
|
||
from profiles.tests.factories import ProfileFactory, SensitiveDataFactory | ||
from services.tests.factories import AllowedDataFieldFactory, ServiceConnectionFactory | ||
|
||
|
||
def test_enable_allowed_data_fields_restriction_flag_false_shows_data( | ||
user_gql_client, service, settings | ||
): | ||
settings.ENABLE_ALLOWED_DATA_FIELDS_RESTRICTION = False | ||
profile = ProfileFactory(user=user_gql_client.user) | ||
ServiceConnectionFactory(profile=profile, service=service) | ||
service.allowed_data_fields.add(AllowedDataFieldFactory(field_name="name")) | ||
SensitiveDataFactory(profile=profile) | ||
|
||
query = """ | ||
{ | ||
myProfile { | ||
firstName | ||
sensitivedata { | ||
ssn | ||
} | ||
} | ||
} | ||
""" | ||
|
||
executed = user_gql_client.execute(query, service=service) | ||
|
||
assert executed["data"]["myProfile"]["firstName"] == profile.first_name | ||
assert ( | ||
executed["data"]["myProfile"]["sensitivedata"]["ssn"] | ||
== profile.sensitivedata.ssn | ||
) | ||
|
||
|
||
@mock.patch("logging.warning") | ||
def test_enable_allowed_data_fields_restriction_flag_logs_warning_if_access_to_restricted_field( | ||
mock_log, user_gql_client, service, settings | ||
): | ||
settings.ENABLE_ALLOWED_DATA_FIELDS_RESTRICTION = False | ||
profile = ProfileFactory(user=user_gql_client.user) | ||
ServiceConnectionFactory(profile=profile, service=service) | ||
service.allowed_data_fields.add(AllowedDataFieldFactory(field_name="name")) | ||
SensitiveDataFactory(profile=profile) | ||
|
||
query = """ | ||
{ | ||
myProfile { | ||
firstName | ||
sensitivedata { | ||
ssn | ||
} | ||
} | ||
} | ||
""" | ||
|
||
user_gql_client.execute(query, service=service) | ||
|
||
assert mock_log.call_count == 1 |