Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions scripts/redis_acl_safety.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@
from __future__ import annotations

import secrets
from collections.abc import Sequence
from dataclasses import dataclass
from typing import Sequence
from urllib.parse import urlsplit
from typing import Self

import redis

Expand Down Expand Up @@ -238,7 +238,7 @@ def classify_environment(
if probe is not None:
try:
probe.close()
except Exception: # noqa: BLE001 -- best-effort cleanup only
except Exception: # noqa: S110, BLE001 -- best-effort cleanup only, deliberately silent
pass
if got != attestation.nonce_value:
raise EnvironmentClassificationError(
Expand Down Expand Up @@ -460,7 +460,7 @@ class AuthenticatedSession:
for exactly what is and is not enforced.
"""

def __init__(self, *, environment: RedisEnvironment, gate: CommandGate, client: "redis.Redis"):
def __init__(self, *, environment: RedisEnvironment, gate: CommandGate, client: redis.Redis):
self.environment = environment
self._gate = gate
self._client = client
Expand All @@ -478,10 +478,10 @@ def close(self) -> None:
self._closed = True
try:
self._client.close()
except Exception: # noqa: BLE001 -- best-effort cleanup only
except Exception: # noqa: S110, BLE001 -- best-effort cleanup only, deliberately silent
pass

def __enter__(self) -> "AuthenticatedSession":
def __enter__(self) -> Self:
return self

def __exit__(self, exc_type, exc, tb) -> None:
Expand Down Expand Up @@ -558,7 +558,7 @@ def authenticate(
if client is not None:
client.close()
raise
except Exception as exc: # noqa: BLE001 -- convert anything unexpected to a safety error, never leak it raw
except Exception as exc: # convert anything unexpected to a safety error, never leak it raw
if client is not None:
client.close()
raise AuthenticationFailedError(
Expand Down
3 changes: 1 addition & 2 deletions tests/test_redis_acl_safety.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import redis

from scripts.redis_acl_safety import (
DANGEROUS_COMMANDS,
PRODUCTION_ALLOWED_COMMANDS,
PRODUCTION_PORT,
AuthenticatedSession,
Expand Down Expand Up @@ -231,7 +230,7 @@ def test_authenticate_production_rejects_non_production_port(self):


def _run(cmd, **kw):
return subprocess.run(cmd, capture_output=True, text=True, timeout=30, **kw)
return subprocess.run(cmd, capture_output=True, text=True, timeout=30, check=False, **kw)


@pytest.fixture(scope="session")
Expand Down
Loading