ibm-cloud-sdk-core 3.20.1__tar.gz → 3.20.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {ibm-cloud-sdk-core-3.20.1/ibm_cloud_sdk_core.egg-info → ibm-cloud-sdk-core-3.20.2}/PKG-INFO +2 -2
- {ibm-cloud-sdk-core-3.20.1 → ibm-cloud-sdk-core-3.20.2}/README.md +1 -1
- {ibm-cloud-sdk-core-3.20.1 → ibm-cloud-sdk-core-3.20.2}/ibm_cloud_sdk_core/base_service.py +1 -1
- ibm-cloud-sdk-core-3.20.2/ibm_cloud_sdk_core/http_adapter.py +27 -0
- {ibm-cloud-sdk-core-3.20.1 → ibm-cloud-sdk-core-3.20.2}/ibm_cloud_sdk_core/utils.py +0 -27
- ibm-cloud-sdk-core-3.20.2/ibm_cloud_sdk_core/version.py +1 -0
- {ibm-cloud-sdk-core-3.20.1 → ibm-cloud-sdk-core-3.20.2/ibm_cloud_sdk_core.egg-info}/PKG-INFO +2 -2
- {ibm-cloud-sdk-core-3.20.1 → ibm-cloud-sdk-core-3.20.2}/ibm_cloud_sdk_core.egg-info/SOURCES.txt +3 -2
- {ibm-cloud-sdk-core-3.20.1 → ibm-cloud-sdk-core-3.20.2}/ibm_cloud_sdk_core.egg-info/requires.txt +1 -1
- {ibm-cloud-sdk-core-3.20.1 → ibm-cloud-sdk-core-3.20.2}/requirements.txt +1 -1
- {ibm-cloud-sdk-core-3.20.1 → ibm-cloud-sdk-core-3.20.2}/setup.py +1 -1
- {ibm-cloud-sdk-core-3.20.1 → ibm-cloud-sdk-core-3.20.2}/test/test_api_exception.py +5 -0
- ibm-cloud-sdk-core-3.20.2/test/test_http_adapter.py +123 -0
- {ibm-cloud-sdk-core-3.20.1 → ibm-cloud-sdk-core-3.20.2}/test/test_jwt_token_manager.py +1 -2
- {ibm-cloud-sdk-core-3.20.1 → ibm-cloud-sdk-core-3.20.2}/test/test_token_manager.py +1 -7
- ibm-cloud-sdk-core-3.20.1/ibm_cloud_sdk_core/version.py +0 -1
- ibm-cloud-sdk-core-3.20.1/test_integration/test_ssl_verification.py +0 -62
- {ibm-cloud-sdk-core-3.20.1 → ibm-cloud-sdk-core-3.20.2}/LICENSE +0 -0
- {ibm-cloud-sdk-core-3.20.1 → ibm-cloud-sdk-core-3.20.2}/MANIFEST.in +0 -0
- {ibm-cloud-sdk-core-3.20.1 → ibm-cloud-sdk-core-3.20.2}/ibm_cloud_sdk_core/__init__.py +0 -0
- {ibm-cloud-sdk-core-3.20.1 → ibm-cloud-sdk-core-3.20.2}/ibm_cloud_sdk_core/api_exception.py +0 -0
- {ibm-cloud-sdk-core-3.20.1 → ibm-cloud-sdk-core-3.20.2}/ibm_cloud_sdk_core/authenticators/__init__.py +0 -0
- {ibm-cloud-sdk-core-3.20.1 → ibm-cloud-sdk-core-3.20.2}/ibm_cloud_sdk_core/authenticators/authenticator.py +0 -0
- {ibm-cloud-sdk-core-3.20.1 → ibm-cloud-sdk-core-3.20.2}/ibm_cloud_sdk_core/authenticators/basic_authenticator.py +0 -0
- {ibm-cloud-sdk-core-3.20.1 → ibm-cloud-sdk-core-3.20.2}/ibm_cloud_sdk_core/authenticators/bearer_token_authenticator.py +0 -0
- {ibm-cloud-sdk-core-3.20.1 → ibm-cloud-sdk-core-3.20.2}/ibm_cloud_sdk_core/authenticators/container_authenticator.py +0 -0
- {ibm-cloud-sdk-core-3.20.1 → ibm-cloud-sdk-core-3.20.2}/ibm_cloud_sdk_core/authenticators/cp4d_authenticator.py +0 -0
- {ibm-cloud-sdk-core-3.20.1 → ibm-cloud-sdk-core-3.20.2}/ibm_cloud_sdk_core/authenticators/iam_authenticator.py +0 -0
- {ibm-cloud-sdk-core-3.20.1 → ibm-cloud-sdk-core-3.20.2}/ibm_cloud_sdk_core/authenticators/iam_request_based_authenticator.py +0 -0
- {ibm-cloud-sdk-core-3.20.1 → ibm-cloud-sdk-core-3.20.2}/ibm_cloud_sdk_core/authenticators/mcsp_authenticator.py +0 -0
- {ibm-cloud-sdk-core-3.20.1 → ibm-cloud-sdk-core-3.20.2}/ibm_cloud_sdk_core/authenticators/no_auth_authenticator.py +0 -0
- {ibm-cloud-sdk-core-3.20.1 → ibm-cloud-sdk-core-3.20.2}/ibm_cloud_sdk_core/authenticators/vpc_instance_authenticator.py +0 -0
- {ibm-cloud-sdk-core-3.20.1 → ibm-cloud-sdk-core-3.20.2}/ibm_cloud_sdk_core/detailed_response.py +0 -0
- {ibm-cloud-sdk-core-3.20.1 → ibm-cloud-sdk-core-3.20.2}/ibm_cloud_sdk_core/get_authenticator.py +0 -0
- {ibm-cloud-sdk-core-3.20.1 → ibm-cloud-sdk-core-3.20.2}/ibm_cloud_sdk_core/private_helpers.py +0 -0
- {ibm-cloud-sdk-core-3.20.1 → ibm-cloud-sdk-core-3.20.2}/ibm_cloud_sdk_core/token_managers/__init__.py +0 -0
- {ibm-cloud-sdk-core-3.20.1 → ibm-cloud-sdk-core-3.20.2}/ibm_cloud_sdk_core/token_managers/container_token_manager.py +0 -0
- {ibm-cloud-sdk-core-3.20.1 → ibm-cloud-sdk-core-3.20.2}/ibm_cloud_sdk_core/token_managers/cp4d_token_manager.py +0 -0
- {ibm-cloud-sdk-core-3.20.1 → ibm-cloud-sdk-core-3.20.2}/ibm_cloud_sdk_core/token_managers/iam_request_based_token_manager.py +0 -0
- {ibm-cloud-sdk-core-3.20.1 → ibm-cloud-sdk-core-3.20.2}/ibm_cloud_sdk_core/token_managers/iam_token_manager.py +0 -0
- {ibm-cloud-sdk-core-3.20.1 → ibm-cloud-sdk-core-3.20.2}/ibm_cloud_sdk_core/token_managers/jwt_token_manager.py +0 -0
- {ibm-cloud-sdk-core-3.20.1 → ibm-cloud-sdk-core-3.20.2}/ibm_cloud_sdk_core/token_managers/mcsp_token_manager.py +0 -0
- {ibm-cloud-sdk-core-3.20.1 → ibm-cloud-sdk-core-3.20.2}/ibm_cloud_sdk_core/token_managers/token_manager.py +0 -0
- {ibm-cloud-sdk-core-3.20.1 → ibm-cloud-sdk-core-3.20.2}/ibm_cloud_sdk_core/token_managers/vpc_instance_token_manager.py +0 -0
- {ibm-cloud-sdk-core-3.20.1 → ibm-cloud-sdk-core-3.20.2}/ibm_cloud_sdk_core.egg-info/dependency_links.txt +0 -0
- {ibm-cloud-sdk-core-3.20.1 → ibm-cloud-sdk-core-3.20.2}/ibm_cloud_sdk_core.egg-info/top_level.txt +0 -0
- {ibm-cloud-sdk-core-3.20.1 → ibm-cloud-sdk-core-3.20.2}/ibm_cloud_sdk_core.egg-info/zip-safe +0 -0
- {ibm-cloud-sdk-core-3.20.1 → ibm-cloud-sdk-core-3.20.2}/pyproject.toml +0 -0
- {ibm-cloud-sdk-core-3.20.1 → ibm-cloud-sdk-core-3.20.2}/requirements-dev.txt +0 -0
- {ibm-cloud-sdk-core-3.20.1 → ibm-cloud-sdk-core-3.20.2}/setup.cfg +0 -0
- {ibm-cloud-sdk-core-3.20.1 → ibm-cloud-sdk-core-3.20.2}/test/__init__.py +0 -0
- {ibm-cloud-sdk-core-3.20.1 → ibm-cloud-sdk-core-3.20.2}/test/test_authenticator.py +0 -0
- {ibm-cloud-sdk-core-3.20.1 → ibm-cloud-sdk-core-3.20.2}/test/test_base_service.py +0 -0
- {ibm-cloud-sdk-core-3.20.1 → ibm-cloud-sdk-core-3.20.2}/test/test_basic_authenticator.py +0 -0
- {ibm-cloud-sdk-core-3.20.1 → ibm-cloud-sdk-core-3.20.2}/test/test_bearer_authenticator.py +0 -0
- {ibm-cloud-sdk-core-3.20.1 → ibm-cloud-sdk-core-3.20.2}/test/test_container_authenticator.py +0 -0
- {ibm-cloud-sdk-core-3.20.1 → ibm-cloud-sdk-core-3.20.2}/test/test_container_token_manager.py +0 -0
- {ibm-cloud-sdk-core-3.20.1 → ibm-cloud-sdk-core-3.20.2}/test/test_cp4d_authenticator.py +0 -0
- {ibm-cloud-sdk-core-3.20.1 → ibm-cloud-sdk-core-3.20.2}/test/test_cp4d_token_manager.py +0 -0
- {ibm-cloud-sdk-core-3.20.1 → ibm-cloud-sdk-core-3.20.2}/test/test_detailed_response.py +0 -0
- {ibm-cloud-sdk-core-3.20.1 → ibm-cloud-sdk-core-3.20.2}/test/test_iam_authenticator.py +0 -0
- {ibm-cloud-sdk-core-3.20.1 → ibm-cloud-sdk-core-3.20.2}/test/test_iam_token_manager.py +0 -0
- {ibm-cloud-sdk-core-3.20.1 → ibm-cloud-sdk-core-3.20.2}/test/test_mcsp_authenticator.py +0 -0
- {ibm-cloud-sdk-core-3.20.1 → ibm-cloud-sdk-core-3.20.2}/test/test_mcsp_token_manager.py +0 -0
- {ibm-cloud-sdk-core-3.20.1 → ibm-cloud-sdk-core-3.20.2}/test/test_no_auth_authenticator.py +0 -0
- {ibm-cloud-sdk-core-3.20.1 → ibm-cloud-sdk-core-3.20.2}/test/test_utils.py +0 -0
- {ibm-cloud-sdk-core-3.20.1 → ibm-cloud-sdk-core-3.20.2}/test/test_vpc_instance_authenticator.py +0 -0
- {ibm-cloud-sdk-core-3.20.1 → ibm-cloud-sdk-core-3.20.2}/test/test_vpc_instance_token_manager.py +0 -0
- {ibm-cloud-sdk-core-3.20.1 → ibm-cloud-sdk-core-3.20.2}/test_integration/__init__.py +0 -0
- {ibm-cloud-sdk-core-3.20.1 → ibm-cloud-sdk-core-3.20.2}/test_integration/test_cp4d_authenticator_integration.py +0 -0
- {ibm-cloud-sdk-core-3.20.1 → ibm-cloud-sdk-core-3.20.2}/test_integration/test_iam_authenticator_integration.py +0 -0
- {ibm-cloud-sdk-core-3.20.1 → ibm-cloud-sdk-core-3.20.2}/test_integration/test_mcsp_authenticator_integration.py +0 -0
{ibm-cloud-sdk-core-3.20.1/ibm_cloud_sdk_core.egg-info → ibm-cloud-sdk-core-3.20.2}/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: ibm-cloud-sdk-core
|
|
3
|
-
Version: 3.20.
|
|
3
|
+
Version: 3.20.2
|
|
4
4
|
Summary: Core library used by SDKs for IBM Cloud Services
|
|
5
5
|
Home-page: https://github.com/IBM/python-sdk-core
|
|
6
6
|
Author: IBM
|
|
@@ -29,7 +29,7 @@ License-File: LICENSE
|
|
|
29
29
|
[](https://cla-assistant.io/ibm/python-sdk-core)
|
|
30
30
|
[](https://github.com/semantic-release/semantic-release)
|
|
31
31
|
|
|
32
|
-
# IBM Python SDK Core Version 3.20.
|
|
32
|
+
# IBM Python SDK Core Version 3.20.2
|
|
33
33
|
This project contains core functionality required by Python code generated by the IBM Cloud OpenAPI SDK Generator
|
|
34
34
|
(openapi-sdkgen).
|
|
35
35
|
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
[](https://cla-assistant.io/ibm/python-sdk-core)
|
|
5
5
|
[](https://github.com/semantic-release/semantic-release)
|
|
6
6
|
|
|
7
|
-
# IBM Python SDK Core Version 3.20.
|
|
7
|
+
# IBM Python SDK Core Version 3.20.2
|
|
8
8
|
This project contains core functionality required by Python code generated by the IBM Cloud OpenAPI SDK Generator
|
|
9
9
|
(openapi-sdkgen).
|
|
10
10
|
|
|
@@ -30,6 +30,7 @@ from requests.exceptions import JSONDecodeError
|
|
|
30
30
|
from ibm_cloud_sdk_core.authenticators import Authenticator
|
|
31
31
|
from .api_exception import ApiException
|
|
32
32
|
from .detailed_response import DetailedResponse
|
|
33
|
+
from .http_adapter import SSLHTTPAdapter
|
|
33
34
|
from .token_managers.token_manager import TokenManager
|
|
34
35
|
from .utils import (
|
|
35
36
|
has_bad_first_or_last_char,
|
|
@@ -38,7 +39,6 @@ from .utils import (
|
|
|
38
39
|
cleanup_values,
|
|
39
40
|
read_external_sources,
|
|
40
41
|
strip_extra_slashes,
|
|
41
|
-
SSLHTTPAdapter,
|
|
42
42
|
GzipStream,
|
|
43
43
|
)
|
|
44
44
|
from .private_helpers import _build_user_agent
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import ssl
|
|
2
|
+
|
|
3
|
+
from requests.adapters import HTTPAdapter, DEFAULT_POOLBLOCK
|
|
4
|
+
from urllib3.util.ssl_ import create_urllib3_context
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
# pylint: disable=fixme
|
|
8
|
+
class SSLHTTPAdapter(HTTPAdapter):
|
|
9
|
+
"""Wraps the original HTTP adapter and adds additional SSL context."""
|
|
10
|
+
|
|
11
|
+
def __init__(self, *args, **kwargs):
|
|
12
|
+
self._disable_ssl_verification = kwargs.pop('_disable_ssl_verification', None)
|
|
13
|
+
|
|
14
|
+
super().__init__(*args, **kwargs)
|
|
15
|
+
|
|
16
|
+
def init_poolmanager(self, connections, maxsize, block=DEFAULT_POOLBLOCK, **pool_kwargs):
|
|
17
|
+
"""Create and use custom SSL configuration."""
|
|
18
|
+
|
|
19
|
+
ssl_context = create_urllib3_context()
|
|
20
|
+
ssl_context.load_default_certs()
|
|
21
|
+
ssl_context.minimum_version = ssl.TLSVersion.TLSv1_2
|
|
22
|
+
|
|
23
|
+
if self._disable_ssl_verification:
|
|
24
|
+
ssl_context.check_hostname = False
|
|
25
|
+
ssl_context.verify_mode = ssl.CERT_NONE
|
|
26
|
+
|
|
27
|
+
super().init_poolmanager(connections, maxsize, block, ssl_context=ssl_context, **pool_kwargs)
|
|
@@ -19,41 +19,14 @@ import gzip
|
|
|
19
19
|
import io
|
|
20
20
|
import json as json_import
|
|
21
21
|
import re
|
|
22
|
-
import ssl
|
|
23
22
|
from os import getenv, environ, getcwd
|
|
24
23
|
from os.path import isfile, join, expanduser
|
|
25
24
|
from typing import List, Union
|
|
26
25
|
from urllib.parse import urlparse, parse_qs
|
|
27
26
|
|
|
28
|
-
from requests.adapters import HTTPAdapter, DEFAULT_POOLBLOCK
|
|
29
|
-
from urllib3.util.ssl_ import create_urllib3_context
|
|
30
|
-
|
|
31
27
|
import dateutil.parser as date_parser
|
|
32
28
|
|
|
33
29
|
|
|
34
|
-
# pylint: disable=fixme
|
|
35
|
-
# TODO: revert the change in the `requirement.txt` once this class become deprecated!
|
|
36
|
-
class SSLHTTPAdapter(HTTPAdapter):
|
|
37
|
-
"""Wraps the original HTTP adapter and adds additional SSL context."""
|
|
38
|
-
|
|
39
|
-
def __init__(self, *args, **kwargs):
|
|
40
|
-
self._disable_ssl_verification = kwargs.pop('_disable_ssl_verification', None)
|
|
41
|
-
|
|
42
|
-
super().__init__(*args, **kwargs)
|
|
43
|
-
|
|
44
|
-
def init_poolmanager(self, connections, maxsize, block=DEFAULT_POOLBLOCK, **pool_kwargs):
|
|
45
|
-
"""Create and use custom SSL configuration."""
|
|
46
|
-
|
|
47
|
-
ssl_context = create_urllib3_context()
|
|
48
|
-
ssl_context.minimum_version = ssl.TLSVersion.TLSv1_2
|
|
49
|
-
|
|
50
|
-
if self._disable_ssl_verification:
|
|
51
|
-
ssl_context.check_hostname = False
|
|
52
|
-
ssl_context.verify_mode = ssl.CERT_NONE
|
|
53
|
-
|
|
54
|
-
super().init_poolmanager(connections, maxsize, block, ssl_context=ssl_context, **pool_kwargs)
|
|
55
|
-
|
|
56
|
-
|
|
57
30
|
class GzipStream(io.RawIOBase):
|
|
58
31
|
"""Compress files on the fly.
|
|
59
32
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = '3.20.2'
|
{ibm-cloud-sdk-core-3.20.1 → ibm-cloud-sdk-core-3.20.2/ibm_cloud_sdk_core.egg-info}/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: ibm-cloud-sdk-core
|
|
3
|
-
Version: 3.20.
|
|
3
|
+
Version: 3.20.2
|
|
4
4
|
Summary: Core library used by SDKs for IBM Cloud Services
|
|
5
5
|
Home-page: https://github.com/IBM/python-sdk-core
|
|
6
6
|
Author: IBM
|
|
@@ -29,7 +29,7 @@ License-File: LICENSE
|
|
|
29
29
|
[](https://cla-assistant.io/ibm/python-sdk-core)
|
|
30
30
|
[](https://github.com/semantic-release/semantic-release)
|
|
31
31
|
|
|
32
|
-
# IBM Python SDK Core Version 3.20.
|
|
32
|
+
# IBM Python SDK Core Version 3.20.2
|
|
33
33
|
This project contains core functionality required by Python code generated by the IBM Cloud OpenAPI SDK Generator
|
|
34
34
|
(openapi-sdkgen).
|
|
35
35
|
|
{ibm-cloud-sdk-core-3.20.1 → ibm-cloud-sdk-core-3.20.2}/ibm_cloud_sdk_core.egg-info/SOURCES.txt
RENAMED
|
@@ -10,6 +10,7 @@ ibm_cloud_sdk_core/api_exception.py
|
|
|
10
10
|
ibm_cloud_sdk_core/base_service.py
|
|
11
11
|
ibm_cloud_sdk_core/detailed_response.py
|
|
12
12
|
ibm_cloud_sdk_core/get_authenticator.py
|
|
13
|
+
ibm_cloud_sdk_core/http_adapter.py
|
|
13
14
|
ibm_cloud_sdk_core/private_helpers.py
|
|
14
15
|
ibm_cloud_sdk_core/utils.py
|
|
15
16
|
ibm_cloud_sdk_core/version.py
|
|
@@ -50,6 +51,7 @@ test/test_container_token_manager.py
|
|
|
50
51
|
test/test_cp4d_authenticator.py
|
|
51
52
|
test/test_cp4d_token_manager.py
|
|
52
53
|
test/test_detailed_response.py
|
|
54
|
+
test/test_http_adapter.py
|
|
53
55
|
test/test_iam_authenticator.py
|
|
54
56
|
test/test_iam_token_manager.py
|
|
55
57
|
test/test_jwt_token_manager.py
|
|
@@ -63,5 +65,4 @@ test/test_vpc_instance_token_manager.py
|
|
|
63
65
|
test_integration/__init__.py
|
|
64
66
|
test_integration/test_cp4d_authenticator_integration.py
|
|
65
67
|
test_integration/test_iam_authenticator_integration.py
|
|
66
|
-
test_integration/test_mcsp_authenticator_integration.py
|
|
67
|
-
test_integration/test_ssl_verification.py
|
|
68
|
+
test_integration/test_mcsp_authenticator_integration.py
|
|
@@ -74,6 +74,9 @@ def test_api_exception():
|
|
|
74
74
|
mock_response = requests.get('https://test-errormessage.com', timeout=None)
|
|
75
75
|
exception = ApiException(500, http_response=mock_response)
|
|
76
76
|
assert exception.message == 'IAM error message'
|
|
77
|
+
assert exception.http_response.text == '{"errorMessage": "IAM error message"}'
|
|
78
|
+
assert exception.http_response.content == b'{"errorMessage": "IAM error message"}'
|
|
79
|
+
assert exception.http_response.json() == {'errorMessage': 'IAM error message'}
|
|
77
80
|
|
|
78
81
|
responses.add(
|
|
79
82
|
responses.GET,
|
|
@@ -86,3 +89,5 @@ def test_api_exception():
|
|
|
86
89
|
exception = ApiException(500, http_response=mock_response)
|
|
87
90
|
assert exception.message == 'plain text error'
|
|
88
91
|
assert str(exception) == 'Error: plain text error, Status code: 500 , X-global-transaction-id: xx'
|
|
92
|
+
assert exception.http_response.text == 'plain text error'
|
|
93
|
+
assert exception.http_response.content == b'plain text error'
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
# pylint: disable=missing-docstring
|
|
2
|
+
import os
|
|
3
|
+
import threading
|
|
4
|
+
import warnings
|
|
5
|
+
from http.server import HTTPServer, SimpleHTTPRequestHandler
|
|
6
|
+
from ssl import get_default_verify_paths, SSLContext, PROTOCOL_TLSv1_1, PROTOCOL_TLSv1_2
|
|
7
|
+
from typing import Callable
|
|
8
|
+
|
|
9
|
+
import pytest
|
|
10
|
+
import urllib3
|
|
11
|
+
from requests.exceptions import SSLError
|
|
12
|
+
|
|
13
|
+
from ibm_cloud_sdk_core.base_service import BaseService
|
|
14
|
+
from ibm_cloud_sdk_core.authenticators import NoAuthAuthenticator
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# The certificate files that are used in this tests are generated by this command:
|
|
18
|
+
# pylint: disable=line-too-long,pointless-string-statement
|
|
19
|
+
"""
|
|
20
|
+
openssl req -x509 -out test_ssl.crt -keyout test_ssl.key \
|
|
21
|
+
-newkey rsa:2048 -nodes -sha256 -days 36500 \
|
|
22
|
+
-subj '/CN=localhost' -extensions EXT -config <( \
|
|
23
|
+
printf "[dn]\nCN=localhost\n[req]\ndistinguished_name = dn\n[EXT]\nsubjectAltName=DNS:localhost\nkeyUsage=digitalSignature\nextendedKeyUsage=serverAuth")
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
# Load the certificate and the key files.
|
|
28
|
+
cert = os.path.join(os.path.dirname(__file__), '../resources/test_ssl.crt')
|
|
29
|
+
key = os.path.join(os.path.dirname(__file__), '../resources/test_ssl.key')
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def _local_server(tls_version: int, port: int) -> Callable:
|
|
33
|
+
def decorator(test_function: Callable) -> Callable:
|
|
34
|
+
def inner():
|
|
35
|
+
# Disable warnings caused by the self-signed certificate.
|
|
36
|
+
urllib3.disable_warnings()
|
|
37
|
+
|
|
38
|
+
# Build the SSL context for the server.
|
|
39
|
+
ssl_context = SSLContext(tls_version)
|
|
40
|
+
ssl_context.load_cert_chain(certfile=cert, keyfile=key)
|
|
41
|
+
|
|
42
|
+
# Create and start the server on a separate thread.
|
|
43
|
+
server = HTTPServer(('localhost', port), SimpleHTTPRequestHandler)
|
|
44
|
+
server.socket = ssl_context.wrap_socket(server.socket, server_side=True)
|
|
45
|
+
t = threading.Thread(target=server.serve_forever)
|
|
46
|
+
t.start()
|
|
47
|
+
|
|
48
|
+
# We run everything in a big try-except-finally block to make sure we always
|
|
49
|
+
# shutdown the HTTP server gracefully.
|
|
50
|
+
try:
|
|
51
|
+
test_function()
|
|
52
|
+
except Exception: # pylint: disable=try-except-raise
|
|
53
|
+
raise
|
|
54
|
+
finally:
|
|
55
|
+
server.shutdown()
|
|
56
|
+
t.join()
|
|
57
|
+
# Re-enable warnings.
|
|
58
|
+
warnings.resetwarnings()
|
|
59
|
+
|
|
60
|
+
return inner
|
|
61
|
+
|
|
62
|
+
return decorator
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
@_local_server(PROTOCOL_TLSv1_1, 3333)
|
|
66
|
+
def test_tls_v1_1():
|
|
67
|
+
service = BaseService(service_url='https://localhost:3333', authenticator=NoAuthAuthenticator())
|
|
68
|
+
prepped = service.prepare_request('GET', url='/')
|
|
69
|
+
# The following request should fail, because the server will try
|
|
70
|
+
# to use TLS v1.1 but that's not allowed in our client.
|
|
71
|
+
with pytest.raises(Exception) as exception:
|
|
72
|
+
service.send(prepped, verify=cert)
|
|
73
|
+
# Errors can be differ based on the Python version.
|
|
74
|
+
assert exception.type is SSLError or exception.type is ConnectionError
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
@_local_server(PROTOCOL_TLSv1_2, 3334)
|
|
78
|
+
def test_tls_v1_2():
|
|
79
|
+
service = BaseService(service_url='https://localhost:3334', authenticator=NoAuthAuthenticator())
|
|
80
|
+
|
|
81
|
+
# First call the server with the default configuration.
|
|
82
|
+
# It should fail due to the self-signed SSL cert.
|
|
83
|
+
assert service.disable_ssl_verification is False
|
|
84
|
+
prepped = service.prepare_request('GET', url='/')
|
|
85
|
+
with pytest.raises(SSLError, match='certificate verify failed: self-signed certificate'):
|
|
86
|
+
res = service.send(prepped)
|
|
87
|
+
|
|
88
|
+
# Next configure it to validate by using our local certificate. Should raise no exception.
|
|
89
|
+
res = service.send(prepped, verify=cert)
|
|
90
|
+
assert res is not None
|
|
91
|
+
|
|
92
|
+
# Now disable the SSL verification. The request shouldn't raise any issue.
|
|
93
|
+
service.set_disable_ssl_verification(True)
|
|
94
|
+
assert service.disable_ssl_verification is True
|
|
95
|
+
prepped = service.prepare_request('GET', url='/')
|
|
96
|
+
res = service.send(prepped)
|
|
97
|
+
assert res is not None
|
|
98
|
+
|
|
99
|
+
# Lastly, try with an external URL.
|
|
100
|
+
# This test case is mainly here to reproduce the regression
|
|
101
|
+
# in the `requests` package that was introduced in `2.32.3`.
|
|
102
|
+
# More details on the issue can be found here: https://github.com/psf/requests/issues/6730
|
|
103
|
+
service = BaseService(service_url='https://cloud.ibm.com', authenticator=NoAuthAuthenticator())
|
|
104
|
+
assert service.disable_ssl_verification is False
|
|
105
|
+
|
|
106
|
+
ssl_context = service.http_adapter.poolmanager.connection_pool_kw.get("ssl_context")
|
|
107
|
+
assert ssl_context is not None
|
|
108
|
+
# In some cases (especially in Ubuntu containers that we use for testing on Travis)
|
|
109
|
+
# the default CA certificates are stored in a different place, so let's try to
|
|
110
|
+
# load those before making the final decision for this test case.
|
|
111
|
+
if len(ssl_context.get_ca_certs()) == 0:
|
|
112
|
+
try:
|
|
113
|
+
default_ca_path = get_default_verify_paths().capath
|
|
114
|
+
ssl_context.load_verify_locations(os.path.join(default_ca_path, 'ca-certificates.crt'))
|
|
115
|
+
except:
|
|
116
|
+
# Errors are ignored, let's jump straight to the assertion.
|
|
117
|
+
pass
|
|
118
|
+
|
|
119
|
+
assert len(ssl_context.get_ca_certs()) > 0
|
|
120
|
+
|
|
121
|
+
prepped = service.prepare_request('GET', url='/status')
|
|
122
|
+
res = service.send(prepped)
|
|
123
|
+
assert res is not None
|
|
@@ -97,9 +97,8 @@ def test_is_token_expired():
|
|
|
97
97
|
|
|
98
98
|
|
|
99
99
|
def test_abstract_class_instantiation():
|
|
100
|
-
with pytest.raises(TypeError
|
|
100
|
+
with pytest.raises(TypeError, match=r"^Can't instantiate abstract class JWTTokenManager.*$"):
|
|
101
101
|
JWTTokenManager(None)
|
|
102
|
-
assert str(err.value).startswith("Can't instantiate abstract class JWTTokenManager with abstract")
|
|
103
102
|
|
|
104
103
|
|
|
105
104
|
def test_disable_ssl_verification():
|
|
@@ -34,14 +34,8 @@ class MockTokenManager(TokenManager):
|
|
|
34
34
|
|
|
35
35
|
|
|
36
36
|
def test_abstract_class_instantiation():
|
|
37
|
-
with pytest.raises(TypeError
|
|
37
|
+
with pytest.raises(TypeError, match=r"^Can't instantiate abstract class TokenManager.*$"):
|
|
38
38
|
TokenManager(None)
|
|
39
|
-
assert (
|
|
40
|
-
str(err.value) == "Can't instantiate abstract class "
|
|
41
|
-
"TokenManager with abstract methods "
|
|
42
|
-
"_save_token_info, "
|
|
43
|
-
"request_token"
|
|
44
|
-
)
|
|
45
39
|
|
|
46
40
|
|
|
47
41
|
def requests_request_spy(*args, **kwargs):
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = '3.20.1'
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
# pylint: disable=missing-docstring
|
|
2
|
-
import os
|
|
3
|
-
import threading
|
|
4
|
-
from http.server import HTTPServer, SimpleHTTPRequestHandler
|
|
5
|
-
from ssl import PROTOCOL_TLS_SERVER, SSLContext
|
|
6
|
-
|
|
7
|
-
import pytest
|
|
8
|
-
from requests.exceptions import SSLError
|
|
9
|
-
|
|
10
|
-
from ibm_cloud_sdk_core.base_service import BaseService
|
|
11
|
-
from ibm_cloud_sdk_core.authenticators import NoAuthAuthenticator
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
# The certificate files that are used in this tests are generated by this command:
|
|
15
|
-
# openssl req \
|
|
16
|
-
# -new \
|
|
17
|
-
# -newkey rsa:4096 \
|
|
18
|
-
# -days 36500 \
|
|
19
|
-
# -nodes \
|
|
20
|
-
# -x509 \
|
|
21
|
-
# -subj "/C=US/CN=localhost" \
|
|
22
|
-
# -keyout test_ssl.key \
|
|
23
|
-
# -out test_ssl.cert
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
def test_ssl_verification():
|
|
27
|
-
# Load the certificate and the key files.
|
|
28
|
-
cert = os.path.join(os.path.dirname(__file__), '../resources/test_ssl.cert')
|
|
29
|
-
key = os.path.join(os.path.dirname(__file__), '../resources/test_ssl.key')
|
|
30
|
-
|
|
31
|
-
# Build the SSL context for the server.
|
|
32
|
-
ssl_context = SSLContext(PROTOCOL_TLS_SERVER)
|
|
33
|
-
ssl_context.load_cert_chain(certfile=cert, keyfile=key)
|
|
34
|
-
|
|
35
|
-
# Create and start the server on a separate thread.
|
|
36
|
-
server = HTTPServer(('127.0.0.1', 3333), SimpleHTTPRequestHandler)
|
|
37
|
-
server.socket = ssl_context.wrap_socket(server.socket, server_side=True)
|
|
38
|
-
t = threading.Thread(target=server.serve_forever)
|
|
39
|
-
t.start()
|
|
40
|
-
|
|
41
|
-
# We run everything in a big try-except-finally block to make sure we always
|
|
42
|
-
# shutdown the HTTP server gracefully.
|
|
43
|
-
try:
|
|
44
|
-
service = BaseService(service_url='https://127.0.0.1:3333', authenticator=NoAuthAuthenticator())
|
|
45
|
-
#
|
|
46
|
-
# First call the server with the default configuration.
|
|
47
|
-
# It should fail due to the invalid SSL cert.
|
|
48
|
-
assert service.disable_ssl_verification is False
|
|
49
|
-
prepped = service.prepare_request('GET', url='/')
|
|
50
|
-
with pytest.raises(SSLError):
|
|
51
|
-
res = service.send(prepped)
|
|
52
|
-
|
|
53
|
-
# Now disable the SSL verification. The request shouldn't raise any issue.
|
|
54
|
-
service.set_disable_ssl_verification(True)
|
|
55
|
-
assert service.disable_ssl_verification is True
|
|
56
|
-
prepped = service.prepare_request('GET', url='/')
|
|
57
|
-
res = service.send(prepped)
|
|
58
|
-
assert res is not None
|
|
59
|
-
except Exception: # pylint: disable=try-except-raise
|
|
60
|
-
raise
|
|
61
|
-
finally:
|
|
62
|
-
server.shutdown()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{ibm-cloud-sdk-core-3.20.1 → ibm-cloud-sdk-core-3.20.2}/ibm_cloud_sdk_core/detailed_response.py
RENAMED
|
File without changes
|
{ibm-cloud-sdk-core-3.20.1 → ibm-cloud-sdk-core-3.20.2}/ibm_cloud_sdk_core/get_authenticator.py
RENAMED
|
File without changes
|
{ibm-cloud-sdk-core-3.20.1 → ibm-cloud-sdk-core-3.20.2}/ibm_cloud_sdk_core/private_helpers.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{ibm-cloud-sdk-core-3.20.1 → ibm-cloud-sdk-core-3.20.2}/ibm_cloud_sdk_core.egg-info/top_level.txt
RENAMED
|
File without changes
|
{ibm-cloud-sdk-core-3.20.1 → ibm-cloud-sdk-core-3.20.2}/ibm_cloud_sdk_core.egg-info/zip-safe
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{ibm-cloud-sdk-core-3.20.1 → ibm-cloud-sdk-core-3.20.2}/test/test_container_authenticator.py
RENAMED
|
File without changes
|
{ibm-cloud-sdk-core-3.20.1 → ibm-cloud-sdk-core-3.20.2}/test/test_container_token_manager.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{ibm-cloud-sdk-core-3.20.1 → ibm-cloud-sdk-core-3.20.2}/test/test_vpc_instance_authenticator.py
RENAMED
|
File without changes
|
{ibm-cloud-sdk-core-3.20.1 → ibm-cloud-sdk-core-3.20.2}/test/test_vpc_instance_token_manager.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|