Skip to content

Commit

Permalink
Warn users of sslCommonName deprecation. (#2704)
Browse files Browse the repository at this point in the history
  • Loading branch information
dlm6693 authored Jun 28, 2022
1 parent 6b4bbfa commit 184f7c8
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
19 changes: 17 additions & 2 deletions botocore/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
import logging
import os
import warnings

from botocore import waiter, xform_name
from botocore.args import ClientArgsCreator
Expand Down Expand Up @@ -606,8 +608,21 @@ def _create_endpoint(
resolved, region_name, endpoint_url
)
if endpoint_url is None:
# Use the sslCommonName over the hostname for Python 2.6 compat.
hostname = resolved.get('sslCommonName', resolved.get('hostname'))
sslCommonName = resolved.get('sslCommonName')
hostname = resolved.get('hostname')
is_disabled = ensure_boolean(
os.environ.get('BOTO_DISABLE_COMMONNAME', False)
)
if not is_disabled and sslCommonName is not None:
warnings.warn(
f'The {service_name} client is currently using a '
f'deprecated endpoint: {sslCommonName}. In the next '
f'minor version this will be moved to {hostname}. '
'See https://github.com/boto/botocore/issues/2705 '
'for more details.',
category=FutureWarning,
)
hostname = sslCommonName
endpoint_url = self._make_url(
hostname, is_secure, resolved.get('protocols', [])
)
Expand Down
24 changes: 24 additions & 0 deletions tests/unit/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
import os
from contextlib import closing

import pytest

import botocore
import botocore.config
from botocore import client, exceptions, hooks
Expand Down Expand Up @@ -1607,6 +1610,27 @@ def test_client_close_context_manager(self):

self.endpoint.close.assert_called_once_with()

def test_sslCommonName_warning(self):
creator = self.create_client_creator()
self.endpoint_data['sslCommonName'] = 'bar'

with self.assertWarns(FutureWarning) as warning:
creator.create_client(
'myservice', 'us-west-2', credentials=self.credentials
)
self.assertEqual(len(warning.warnings), 1)

@mock.patch.dict(os.environ, {'BOTO_DISABLE_COMMONNAME': 'true'})
def test_BOTO_DISABLE_COMMONNAME(self):
creator = self.create_client_creator()
self.endpoint_data['sslCommonName'] = 'bar'

with pytest.warns(None) as warning:
creator.create_client(
'myservice', 'us-west-2', credentials=self.credentials
)
self.assertEqual(len(warning), 0)


class TestClientErrors(TestAutoGeneratedClient):
def add_error_response(self, error_response):
Expand Down

0 comments on commit 184f7c8

Please sign in to comment.