From f5c373f2a41ada6110fef9ac701701f541364e0a Mon Sep 17 00:00:00 2001 From: Jacob Lowe <40873986+jalowe13@users.noreply.github.com> Date: Fri, 6 Dec 2024 09:56:05 -0600 Subject: [PATCH] Bug/WP-418: site search error when user does not have community file listing access. (#1005) * file fix starting point * ssh_op_err1 exception addition and test * comment fix * linting --- .../PublicData/PublicData.module.css | 1 + server/portal/apps/site_search/api/views.py | 12 ++++++-- .../apps/site_search/views_unit_test.py | 30 +++++++++++++++---- 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/client/src/components/PublicData/PublicData.module.css b/client/src/components/PublicData/PublicData.module.css index 1ee1414a5..f9572db12 100644 --- a/client/src/components/PublicData/PublicData.module.css +++ b/client/src/components/PublicData/PublicData.module.css @@ -7,3 +7,4 @@ /* FAQ: Public pages, like `PublicData` and `SiteSearch`, have no sidebar */ /* padding-left: 1.5em; /* ~24px (20px * design * 1.2 design-to-app ratio) */ } + diff --git a/server/portal/apps/site_search/api/views.py b/server/portal/apps/site_search/api/views.py index 5eff6f31a..fa7fab86c 100644 --- a/server/portal/apps/site_search/api/views.py +++ b/server/portal/apps/site_search/api/views.py @@ -102,10 +102,18 @@ def get(self, request, *args, **kwargs): return JsonResponse(response) def _handle_tapis_ssh_exception(self, e): - if 'SSH_POOL_MISSING_CREDENTIALS' in str(e) or 'SSH_FX_PERMISSION_DENIED' in str(e): + if ( + "SSH_POOL_MISSING_CREDENTIALS" in str(e) + or "SSH_FX_PERMISSION_DENIED" in str(e) + or "FILES_CLIENT_SSH_OP_ERR1" in str(e) + ): # in case of these error types, user is not authenticated # or does not have access do not fail the entire search # request, log the issue. - logger.exception("Error retrieving search results due to TAPIS SSH related error: {}".format(str(e))) + logger.exception( + "Error retrieving search results due to TAPIS SSH related error: {}".format( + str(e) + ) + ) else: raise diff --git a/server/portal/apps/site_search/views_unit_test.py b/server/portal/apps/site_search/views_unit_test.py index aa775a49f..71834fbac 100644 --- a/server/portal/apps/site_search/views_unit_test.py +++ b/server/portal/apps/site_search/views_unit_test.py @@ -1,18 +1,36 @@ +from unittest.mock import patch + +from tapipy.errors import BaseTapyException + +from portal.apps.site_search.api.views import SiteSearchApiView + + def test_search_unauthenticated(client, regular_user): - response = client.get('/search/') + response = client.get("/search/") assert response.status_code == 200 - assert response.context['setup_complete'] is False + assert response.context["setup_complete"] is False def test_search_authenticated_without_setup_complete(client, authenticated_user): - response = client.get('/search/') + response = client.get("/search/") assert response.status_code == 200 - assert response.context['setup_complete'] is False + assert response.context["setup_complete"] is False def test_search_authenticated_with_setup_complete(client, authenticated_user): authenticated_user.profile.setup_complete = True authenticated_user.profile.save() - response = client.get('/search/') + response = client.get("/search/") assert response.status_code == 200 - assert response.context['setup_complete'] + assert response.context["setup_complete"] + + +@patch("portal.apps.site_search.api.views.logger") +def test_handle_tapis_ssh_exception_files_client_ssh_op_err1(mock_logger): + view = SiteSearchApiView() + message = "FILES_CLIENT_SSH_OP_ERR1" + exception = BaseTapyException(message) + view._handle_tapis_ssh_exception(exception) + mock_logger.exception.assert_called_once_with( + f"Error retrieving search results due to TAPIS SSH related error: message: {message}" + )