Skip to content

Commit f3e59a2

Browse files
committed
rollback on some fixes that aren't needed or worth it
1 parent 1668846 commit f3e59a2

5 files changed

Lines changed: 8 additions & 219 deletions

File tree

src/pysafeguard/errors.py

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,6 @@
1818
from requests import Response
1919

2020

21-
# D-013: cap how much of a response body we splice into an exception's human-facing
22-
# message. The full body remains available to callers via :attr:`SafeguardError.response_body`
23-
# for diagnostic use; this limit only bounds what lands in ``str(exc)`` (the form that
24-
# typically reaches logs, crash reporters, and SIEMs). Truncation — not field-level
25-
# redaction — is the chosen mitigation: it never wrongly masks legitimate Safeguard
26-
# payload fields like ``PasswordRulesPolicyId``, ``ApiKeyName``, or
27-
# ``RequirePasswordChange``.
28-
_MAX_BODY_IN_MESSAGE = 200
29-
30-
31-
def _truncate_for_message(body: str | None, limit: int = _MAX_BODY_IN_MESSAGE) -> str:
32-
"""Bound a response body for inclusion in a human-readable exception message.
33-
34-
Returns ``body`` unchanged if it is already at or under ``limit`` characters,
35-
otherwise returns the first ``limit`` characters followed by a
36-
``... (truncated, N total chars)`` marker so the reader knows it was elided.
37-
"""
38-
if body is None:
39-
return ""
40-
if len(body) <= limit:
41-
return body
42-
return f"{body[:limit]}... (truncated, {len(body)} total chars)"
43-
4421

4522
class SafeguardError(Exception):
4623
"""Base exception for all PySafeguard errors.
@@ -105,9 +82,9 @@ class ApiError(SafeguardError):
10582
@classmethod
10683
def from_response(cls, resp: Response) -> ApiError:
10784
"""Create an ApiError from a sync ``requests.Response``."""
108-
body = resp.text
109-
message = f"{resp.status_code} {resp.reason}: {resp.request.method} {resp.url}\n{_truncate_for_message(body)}"
85+
message = f"{resp.status_code} {resp.reason}: {resp.request.method} {resp.url}\n{resp.text}"
11086
status_code = resp.status_code
87+
body = resp.text
11188

11289
subclass = _STATUS_MAP.get(status_code, cls)
11390
return subclass(message, status_code=status_code, response_body=body)
@@ -120,7 +97,7 @@ def from_async_response(cls, resp: ClientResponse, body: str) -> ApiError:
12097
:param body: The response body text (must be read by the caller
12198
with ``await resp.text()`` before calling this method).
12299
"""
123-
message = f"{resp.status} {resp.reason}: {resp.method} {resp.url}\n{_truncate_for_message(body)}"
100+
message = f"{resp.status} {resp.reason}: {resp.method} {resp.url}\n{body}"
124101
status_code = resp.status
125102

126103
subclass = _STATUS_MAP.get(status_code, cls)

src/pysafeguard/pkce.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
from requests import Response, Session
2020

21-
from .errors import SafeguardError, _truncate_for_message
21+
from .errors import SafeguardError
2222

2323
DEFAULT_TIMEOUT = 300
2424

@@ -93,7 +93,7 @@ def get_pkce_token(
9393
claims_resp = _rsts_request(session, pkce_base_url + _STEP_GENERATE_CLAIMS, form_data)
9494
if claims_resp.status_code != 200:
9595
raise SafeguardError(
96-
f"Failed to generate claims: {_truncate_for_message(claims_resp.text)}",
96+
f"Failed to generate claims: {claims_resp.text}",
9797
status_code=claims_resp.status_code,
9898
response_body=claims_resp.text,
9999
)
@@ -164,7 +164,7 @@ def _rsts_request(session: Session, url: str, form_data: dict[str, str]) -> Resp
164164
if not (200 <= status < 300):
165165
error_message = resp.text.strip() if resp.text.strip() else str(status)
166166
raise SafeguardError(
167-
f"rSTS authentication error: {_truncate_for_message(error_message)}",
167+
f"rSTS authentication error: {error_message}",
168168
status_code=status,
169169
response_body=resp.text,
170170
)
@@ -375,7 +375,7 @@ def _post_authorization_code(session: Session, appliance: str, code: str, code_v
375375

376376
if not resp.ok:
377377
raise SafeguardError(
378-
f"Failed to exchange authorization code: {resp.status_code} {_truncate_for_message(resp.text)}",
378+
f"Failed to exchange authorization code: {resp.status_code} {resp.text}",
379379
status_code=resp.status_code,
380380
response_body=resp.text,
381381
)
@@ -400,7 +400,7 @@ def _post_login_response(session: Session, appliance: str, rsts_token: str, api_
400400

401401
if not resp.ok:
402402
raise SafeguardError(
403-
f"Failed to exchange RSTS token: {resp.status_code} {_truncate_for_message(resp.text)}",
403+
f"Failed to exchange RSTS token: {resp.status_code} {resp.text}",
404404
status_code=resp.status_code,
405405
response_body=resp.text,
406406
)

tests/test_credential_redaction_audit.py

Lines changed: 0 additions & 122 deletions
This file was deleted.

tests/test_dependency_versions.py

Lines changed: 0 additions & 30 deletions
This file was deleted.

tests/test_samples_documentation.py

Lines changed: 0 additions & 36 deletions
This file was deleted.

0 commit comments

Comments
 (0)