Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[raz] Raise 503 exception for no SAS token and cleaner tests #2470

Merged
merged 1 commit into from
Aug 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 9 additions & 0 deletions desktop/core/src/desktop/lib/rest/raz_http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,17 @@
# limitations under the License.

import logging
import sys

from desktop import conf
from desktop.lib.raz.clients import AdlsRazClient
from desktop.lib.rest.http_client import HttpClient
from desktop.lib.exceptions_renderable import PopupException

if sys.version_info[0] > 2:
from django.utils.translation import gettext as _
else:
from django.utils.translation import ugettext as _


LOG = logging.getLogger(__name__)
Expand Down Expand Up @@ -48,6 +55,8 @@ def execute(self, http_method, path, params=None, data=None, headers=None, allow
signed_url = url
if response.get('token'):
signed_url += ('?' if '?' not in url else '&') + response.get('token')
else:
raise PopupException(_('No SAS token in response'), error_code=503)

# Required because `self._make_url` is called in base class execute method also
signed_path = path + signed_url.partition(path)[2]
Expand Down
25 changes: 8 additions & 17 deletions desktop/core/src/desktop/lib/rest/raz_http_client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@

import sys

from nose.tools import assert_equal, assert_false, assert_true
from nose.tools import assert_equal, assert_false, assert_true, assert_raises

from desktop.lib.rest.raz_http_client import RazHttpClient
from desktop.lib.exceptions_renderable import PopupException


if sys.version_info[0] > 2:
Expand Down Expand Up @@ -56,20 +57,10 @@ def test_get_file(self):
timeout=120
)

# When there is no SAS token in response
raz_get_url.return_value = {}
client = RazHttpClient(username='test', base_url='https://gethue.blob.core.windows.net')
f = client.execute(http_method='GET', path='/gethue/data/customer.csv', params={'action': 'getStatus'})

raz_http_execute.assert_called_with(
http_method='GET',
path='/gethue/data/customer.csv?action=getStatus',
data=None,
headers=None,
allow_redirects=False,
urlencode=False,
files=None,
stream=False,
clear_cookies=False,
timeout=120
)
def test_no_sas_token_in_response(self):
with patch('desktop.lib.rest.raz_http_client.AdlsRazClient.get_url') as raz_get_url:
raz_get_url.return_value = {}
client = RazHttpClient(username='test', base_url='https://gethue.blob.core.windows.net')

assert_raises(PopupException, client.execute, http_method='GET', path='/gethue/data/customer.csv', params={'action': 'getStatus'})