Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -11644,7 +11644,10 @@ def _build_deploymentstatus_url(cmd, resource_group_name, webapp_name, slot, dep

def _get_ondeploy_headers(params):
if params.src_path:
content_type = 'application/octet-stream'
if (params.artifact_type or '').strip().lower() == 'zip':
content_type = 'application/zip'
else:
content_type = 'application/octet-stream'
elif params.src_url:
content_type = 'application/json'
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1459,6 +1459,50 @@ def _make_params(self):
params.slot = None
return params

@mock.patch('azure.cli.command_modules.appservice.custom._populate_cached_scm_headers')
@mock.patch('azure.cli.command_modules.appservice.custom.get_scm_site_headers', return_value={})
def test_get_ondeploy_headers_uses_zip_content_type_for_zip_artifact(
self, get_scm_site_headers_mock, _populate_cached_headers_mock):
from azure.cli.command_modules.appservice.custom import _get_ondeploy_headers
params = self._make_params()
params.src_path = '/tmp/package.zip'
params.artifact_type = 'zip'
Comment on lines +1462 to +1469

_get_ondeploy_headers(params)

sent_additional_headers = get_scm_site_headers_mock.call_args.kwargs['additional_headers']
self.assertEqual(sent_additional_headers['Content-Type'], 'application/zip')
self.assertEqual(sent_additional_headers['Cache-Control'], 'no-cache')

@mock.patch('azure.cli.command_modules.appservice.custom._populate_cached_scm_headers')
@mock.patch('azure.cli.command_modules.appservice.custom.get_scm_site_headers', return_value={})
def test_get_ondeploy_headers_zip_content_type_is_case_insensitive(
self, get_scm_site_headers_mock, _populate_cached_headers_mock):
from azure.cli.command_modules.appservice.custom import _get_ondeploy_headers
params = self._make_params()
params.src_path = '/tmp/package.zip'
params.artifact_type = 'ZIP'

_get_ondeploy_headers(params)

sent_additional_headers = get_scm_site_headers_mock.call_args.kwargs['additional_headers']
self.assertEqual(sent_additional_headers['Content-Type'], 'application/zip')

@mock.patch('azure.cli.command_modules.appservice.custom._populate_cached_scm_headers')
@mock.patch('azure.cli.command_modules.appservice.custom.get_scm_site_headers', return_value={})
def test_get_ondeploy_headers_keeps_octet_stream_for_non_zip_artifact(
self, get_scm_site_headers_mock, _populate_cached_headers_mock):
from azure.cli.command_modules.appservice.custom import _get_ondeploy_headers
params = self._make_params()
params.src_path = '/tmp/package.war'
params.artifact_type = 'war'

_get_ondeploy_headers(params)

sent_additional_headers = get_scm_site_headers_mock.call_args.kwargs['additional_headers']
self.assertEqual(sent_additional_headers['Content-Type'], 'application/octet-stream')
self.assertEqual(sent_additional_headers['Cache-Control'], 'no-cache')

def test_get_or_fetch_scm_url_derives_from_cached_site(self):
from azure.cli.command_modules.appservice.custom import _get_or_fetch_scm_url
from azure.mgmt.web.models import HostType
Expand Down
Loading