Skip to content

Commit ff505d7

Browse files
committed
Suppress InsecureRequestWarning when using --insecure
The user already knows this is insecure, there's no point in bringing it up again and again. See also: https://github.com/kennethreitz/requests/issues/2214 Change-Id: I7991b2e568407269f84138bc03711147ed080c9c
1 parent f9d0657 commit ff505d7

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

swiftclient/shell.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1524,6 +1524,11 @@ def main(arguments=None):
15241524

15251525
with OutputManager() as output:
15261526
parser.usage = globals()['st_%s_help' % args[0]]
1527+
if options['insecure']:
1528+
import requests
1529+
from requests.packages.urllib3.exceptions import \
1530+
InsecureRequestWarning
1531+
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
15271532
try:
15281533
globals()['st_%s' % args[0]](parser, argv[1:], output)
15291534
except ClientException as err:

tests/unit/test_shell.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import unittest
2424
import textwrap
2525

26-
26+
from requests.packages.urllib3.exceptions import InsecureRequestWarning
2727
import six
2828

2929
import swiftclient
@@ -1899,15 +1899,23 @@ def _test_options_passed_to_keystone(self, cmd, opts, os_opts,
18991899
auth_token=token)
19001900

19011901
with mock.patch('swiftclient.client._import_keystone_client',
1902-
_make_fake_import_keystone_client(fake_ks)):
1903-
with mock.patch('swiftclient.client.http_connection', fake_conn):
1904-
with mock.patch.dict(os.environ, env, clear=True):
1905-
try:
1906-
swiftclient.shell.main(args)
1907-
except SystemExit as e:
1908-
self.fail('Unexpected SystemExit: %s' % e)
1909-
except SwiftError as err:
1910-
self.fail('Unexpected SwiftError: %s' % err)
1902+
_make_fake_import_keystone_client(fake_ks)), \
1903+
mock.patch('swiftclient.client.http_connection', fake_conn), \
1904+
mock.patch.dict(os.environ, env, clear=True), \
1905+
mock.patch('requests.packages.urllib3.disable_warnings') as \
1906+
mock_disable_warnings:
1907+
try:
1908+
swiftclient.shell.main(args)
1909+
except SystemExit as e:
1910+
self.fail('Unexpected SystemExit: %s' % e)
1911+
except SwiftError as err:
1912+
self.fail('Unexpected SwiftError: %s' % err)
1913+
1914+
if 'insecure' in flags:
1915+
self.assertEqual([mock.call(InsecureRequestWarning)],
1916+
mock_disable_warnings.mock_calls)
1917+
else:
1918+
self.assertEqual([], mock_disable_warnings.mock_calls)
19111919

19121920
if no_auth:
19131921
# check that keystone client was not used and terminate tests

0 commit comments

Comments
 (0)