Skip to content

Commit 8bf84fe

Browse files
chore: upgrade urllib to latest (#240)
* fix: update `urllib3` and `click` dependencies * remove click changes, this will be added in different pr * changelogs * changelogs * mock sso ring test * patch httpretty fake socket shutdown for urllib3 2.0+ compatibility * Update cloudsmith_cli/core/tests/test_rest.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent a8e8570 commit 8bf84fe

File tree

6 files changed

+41
-7
lines changed

6 files changed

+41
-7
lines changed

CHANGELOG.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,18 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77

88
## [Unreleased]
99

10+
### Fixed
11+
12+
- Upgraded `urllib3` from `v1.26.20` to `v2.5.0`.
13+
- Added `mock_keyring` fixture to prevent SSO token refresh attempts during individual `test_rest.py` test which runs in pipelines (full suite passes). Caused by [HTTPretty issue 484](https://github.com/gabrielfalcao/HTTPretty/issues/484).
14+
- Entitlement token list command now fixed
15+
1016
### Added
1117

1218
- Set `--show-all` to alias `--page-all`
1319
- Add the ability to use a shortcut within `--page-size` to use pass `-1` or `*` to retrieve all pages i.e. `--page-size -1` or `--page-size *` (note the wildcard may require escaping in some shell environments)
1420
- Added support for deny policy management commands (list, create, get, update, delete)
1521

16-
### Fixed
17-
18-
- Entitlement token list command now fixed
19-
2022
## [1.9.4] - 2025-11-07
2123

2224
> No code changes in this release. Version bump performed for release process consistency and to address packaging/metadata updates.

cloudsmith_cli/cli/commands/metrics/entitlements.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ def usage(ctx, opts, owner_repo, tokens, start, finish):
123123
owner = owner_repo[0]
124124
repo = None
125125

126+
data = None
126127
context_msg = "Failed to get list of metrics!"
127128
data = {}
128129
with handle_api_exceptions(ctx, opts=opts, context_msg=context_msg):

cloudsmith_cli/core/rest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def create_requests_session(
106106
retry = RetryWithCallback(
107107
backoff_factor=backoff_factor,
108108
connect=retries,
109-
method_whitelist=False,
109+
allowed_methods=False,
110110
read=retries,
111111
status_forcelist=tuple(status_forcelist),
112112
status=retries,

cloudsmith_cli/core/tests/test_rest.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import httpretty
2+
import pytest
23

34
from ..api.init import initialise_api
45
from ..rest import RestClient
56

67

78
class TestRestClient:
89
@httpretty.activate(allow_net_connect=False, verbose=True)
10+
@pytest.mark.usefixtures("mock_keyring")
911
def test_implicit_retry_for_status_codes(self):
1012
"""Assert that the rest client retries certain status codes automatically."""
1113
# initialise_api() needs to be called before RestClient can be instantiated,
@@ -37,3 +39,32 @@ def test_implicit_retry_for_status_codes(self):
3739

3840
assert len(httpretty.latest_requests()) == 6
3941
assert r.status == 200
42+
43+
44+
@pytest.fixture
45+
def mock_keyring(monkeypatch):
46+
"""Mock keyring functions to prevent reading real SSO tokens from the system keyring.
47+
48+
This is necessary because initialise_api() checks the keyring for SSO tokens,
49+
and if found, it attempts to refresh them via a network request. When running
50+
this test in isolation with httpretty mocking enabled, that network request
51+
will fail because it's not mocked.
52+
"""
53+
# Import here to avoid circular imports
54+
import httpretty.core
55+
56+
from .. import keyring
57+
58+
# Mock all keyring getter functions to return None/False
59+
monkeypatch.setattr(keyring, "get_access_token", lambda api_host: None)
60+
monkeypatch.setattr(keyring, "get_refresh_token", lambda api_host: None)
61+
monkeypatch.setattr(keyring, "should_refresh_access_token", lambda api_host: False)
62+
63+
# Patch httpretty's fake socket to handle shutdown() which urllib3 2.0+ calls
64+
# This fixes: "Failed to socket.shutdown because a real socket does not exist"
65+
monkeypatch.setattr(
66+
httpretty.core.fakesock.socket,
67+
"shutdown",
68+
lambda self, how: None,
69+
raising=False,
70+
)

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ typing-extensions==4.13.2
135135
# via
136136
# astroid
137137
# pylint
138-
urllib3==1.26.20
138+
urllib3==2.5.0
139139
# via
140140
# cloudsmith-api
141141
# cloudsmith-cli (setup.py)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def get_long_description():
5858
"requests>=2.18.4",
5959
"requests_toolbelt>=0.8.0",
6060
"semver>=2.7.9",
61-
"urllib3<2.0",
61+
"urllib3>=2.5",
6262
],
6363
entry_points={
6464
"console_scripts": ["cloudsmith=cloudsmith_cli.cli.commands.main:main"]

0 commit comments

Comments
 (0)