|
9 | 9 | from pygitguardian import GGClient |
10 | 10 | from pygitguardian.models import APITokensResponse, Detail, TokenScope |
11 | 11 |
|
12 | | -from ggshield.core.client import check_client_api_key, create_client_from_config |
| 12 | +from ggshield.core.client import ( |
| 13 | + check_client_api_key, |
| 14 | + create_client_from_config, |
| 15 | + create_session, |
| 16 | +) |
13 | 17 | from ggshield.core.config import Config |
14 | 18 | from ggshield.core.errors import ( |
15 | 19 | APIKeyCheckError, |
@@ -239,3 +243,56 @@ def test_retrieve_client_unknown_custom_dashboard_url(isolated_fs: FakeFilesyste |
239 | 243 | config = Config() |
240 | 244 | config.cmdline_instance_name = "https://example.com" |
241 | 245 | create_client_from_config(config) |
| 246 | + |
| 247 | + |
| 248 | +def test_create_session_mounts_http_adapter(): |
| 249 | + """ |
| 250 | + GIVEN create_session is called |
| 251 | + WHEN the session is created |
| 252 | + THEN HTTPAdapter is mounted for both http:// and https:// |
| 253 | + """ |
| 254 | + session = create_session() |
| 255 | + |
| 256 | + # Verify adapters are mounted |
| 257 | + assert "http://" in session.adapters |
| 258 | + assert "https://" in session.adapters |
| 259 | + |
| 260 | + from requests.adapters import HTTPAdapter |
| 261 | + |
| 262 | + assert isinstance(session.get_adapter("http://example.com"), HTTPAdapter) |
| 263 | + assert isinstance(session.get_adapter("https://example.com"), HTTPAdapter) |
| 264 | + |
| 265 | + |
| 266 | +def test_create_session_pool_configuration(): |
| 267 | + """ |
| 268 | + GIVEN create_session is called |
| 269 | + WHEN the session is created |
| 270 | + THEN the HTTPAdapter has the correct pool configuration |
| 271 | + """ |
| 272 | + session = create_session() |
| 273 | + |
| 274 | + adapter = session.get_adapter("https://example.com") |
| 275 | + |
| 276 | + # Verify pool configuration by checking the init parameters |
| 277 | + assert getattr(adapter, "_pool_connections", None) == 20 |
| 278 | + assert getattr(adapter, "_pool_maxsize", None) == 100 |
| 279 | + |
| 280 | + |
| 281 | +@pytest.mark.parametrize("allow_self_signed", [True, False]) |
| 282 | +def test_create_session_with_self_signed_option(allow_self_signed: bool): |
| 283 | + """ |
| 284 | + GIVEN create_session is called with allow_self_signed parameter |
| 285 | + WHEN the session is created |
| 286 | + THEN HTTPAdapter is mounted regardless of allow_self_signed value |
| 287 | + AND verify is set correctly |
| 288 | + """ |
| 289 | + session = create_session(allow_self_signed=allow_self_signed) |
| 290 | + |
| 291 | + # Verify adapters are mounted |
| 292 | + assert "https://" in session.adapters |
| 293 | + |
| 294 | + # Verify SSL verification setting |
| 295 | + if allow_self_signed: |
| 296 | + assert session.verify is False |
| 297 | + else: |
| 298 | + assert session.verify is True |
0 commit comments