|
7 | 7 | import tempfile |
8 | 8 | import time |
9 | 9 | from string import Template |
10 | | -from typing import ClassVar |
| 10 | +from typing import ( |
| 11 | + ClassVar, |
| 12 | + Union, |
| 13 | +) |
11 | 14 | from unittest.mock import ( |
12 | 15 | _patch, |
13 | 16 | patch, |
@@ -124,7 +127,7 @@ class BaseKeycloakIntegrationTestCase(integration_util.IntegrationTestCase): |
124 | 127 | container_name: ClassVar[str] |
125 | 128 | backend_config_file: ClassVar[str] |
126 | 129 | provider_name: ClassVar[str] |
127 | | - saved_oauthlib_insecure_transport: ClassVar[bool] |
| 130 | + saved_env_vars: ClassVar[dict[str, Union[str, None]]] |
128 | 131 | config_patcher: ClassVar[_patch] |
129 | 132 |
|
130 | 133 | @classmethod |
@@ -174,18 +177,21 @@ def tearDownClass(cls): |
174 | 177 |
|
175 | 178 | @classmethod |
176 | 179 | def disableOauthlibHttps(cls): |
177 | | - if "OAUTHLIB_INSECURE_TRANSPORT" in os.environ: |
178 | | - cls.saved_oauthlib_insecure_transport = bool(os.environ["OAUTHLIB_INSECURE_TRANSPORT"]) |
179 | | - os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "true" |
180 | | - os.environ["REQUESTS_CA_BUNDLE"] = os.path.dirname(__file__) + "/keycloak-server.crt.pem" |
181 | | - os.environ["SSL_CERT_FILE"] = os.path.dirname(__file__) + "/keycloak-server.crt.pem" |
| 180 | + env_vars = { |
| 181 | + "OAUTHLIB_INSECURE_TRANSPORT": "true", |
| 182 | + "REQUESTS_CA_BUNDLE": os.path.dirname(__file__) + "/keycloak-server.crt.pem", |
| 183 | + "SSL_CERT_FILE": os.path.dirname(__file__) + "/keycloak-server.crt.pem", |
| 184 | + } |
| 185 | + cls.saved_env_vars = {key: os.environ.get(key) for key in env_vars} |
| 186 | + os.environ.update(env_vars) |
182 | 187 |
|
183 | 188 | @classmethod |
184 | 189 | def restoreOauthlibHttps(cls): |
185 | | - if getattr(cls, "saved_oauthlib_insecure_transport", None): |
186 | | - os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = str(cls.saved_oauthlib_insecure_transport) |
187 | | - else: |
188 | | - del os.environ["OAUTHLIB_INSECURE_TRANSPORT"] |
| 190 | + for key, value in cls.saved_env_vars.items(): |
| 191 | + if value is not None: |
| 192 | + os.environ[key] = value |
| 193 | + else: |
| 194 | + del os.environ[key] |
189 | 195 |
|
190 | 196 | @classmethod |
191 | 197 | def handle_galaxy_oidc_config_kwds(cls, config): |
|
0 commit comments