Skip to content

Commit

Permalink
Putting dataset test results behind security flag
Browse files Browse the repository at this point in the history
  • Loading branch information
galvana committed Dec 6, 2024
1 parent 3f0c296 commit b6d43fe
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/fides/api/api/v1/endpoints/privacy_request_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -2662,10 +2662,14 @@ def get_test_privacy_request_results(
# Escape datetime and ObjectId values
raw_data = privacy_request.get_raw_access_results()
escaped_json = json.dumps(raw_data, indent=2, default=storage_json_encoder)
escaped_data = json.loads(escaped_json)
results = json.loads(escaped_json)

return {
"privacy_request_id": privacy_request.id,
"status": privacy_request.status,
"results": escaped_data,
"results": (
results
if CONFIG.security.subject_request_download_ui_enabled
else "Access results download is disabled."
),
}
2 changes: 1 addition & 1 deletion src/fides/api/schemas/privacy_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,4 +401,4 @@ class FilteredPrivacyRequestResults(FidesSchema):

privacy_request_id: str
status: PrivacyRequestStatus
results: Dict[str, Any]
results: Union[Dict[str, Any], str]
8 changes: 8 additions & 0 deletions tests/fixtures/application_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -3453,6 +3453,14 @@ def subject_request_download_ui_enabled():
CONFIG.security.subject_request_download_ui_enabled = original_value


@pytest.fixture(scope="function")
def subject_request_download_ui_disabled():
original_value = CONFIG.security.subject_request_download_ui_enabled
CONFIG.security.subject_request_download_ui_enabled = False
yield
CONFIG.security.subject_request_download_ui_enabled = original_value


@pytest.fixture(scope="function")
def system_with_no_uses(db: Session) -> Generator[System, None, None]:
system = System.create(
Expand Down
41 changes: 41 additions & 0 deletions tests/ops/api/v1/endpoints/test_privacy_request_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -8462,6 +8462,47 @@ def test_filtered_results_postgres(
"results",
}

@pytest.mark.integration_postgres
@pytest.mark.usefixtures(
"default_access_policy",
"postgres_integration_db",
"subject_request_download_ui_disabled",
)
def test_filtered_results_postgres_access_results_disabled(
self,
connection_config,
postgres_example_test_dataset_config,
api_client: TestClient,
generate_auth_header,
) -> None:
dataset_url = get_connection_dataset_url(
connection_config, postgres_example_test_dataset_config
)
auth_header = generate_auth_header(scopes=[DATASET_TEST])
response = api_client.post(
dataset_url + "/test",
headers=auth_header,
json={"email": "[email protected]"},
)
assert response.status_code == HTTP_200_OK

privacy_request_id = response.json()["privacy_request_id"]
url = V1_URL_PREFIX + PRIVACY_REQUEST_FILTERED_RESULTS.format(
privacy_request_id=privacy_request_id
)
auth_header = generate_auth_header(scopes=[PRIVACY_REQUEST_READ_ACCESS_RESULTS])
response = api_client.get(
url,
headers=auth_header,
)
assert response.status_code == HTTP_200_OK
assert set(response.json().keys()) == {
"privacy_request_id",
"status",
"results",
}
assert response.json()["results"] == "Access results download is disabled."

@pytest.mark.integration_mongo
@pytest.mark.usefixtures("default_access_policy")
def test_filtered_results_mongo(
Expand Down

0 comments on commit b6d43fe

Please sign in to comment.