Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix verify_in_ssl log statement which no longer has access to SSL params #202

Merged
merged 1 commit into from
Sep 22, 2023
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
8 changes: 1 addition & 7 deletions app/src/adapters/db/clients/postgres_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,6 @@ def generate_iam_auth_token(aws_region: str, host: str, port: int, user: str) ->
def verify_ssl(connection_info: Any) -> None:
"""Verify that the database connection is encrypted and log a warning if not."""
if connection_info.pgconn.ssl_in_use:
logger.info(
"database connection is using SSL: %s",
", ".join(
name + " " + connection_info.ssl_attribute(name)
for name in connection_info.ssl_attribute_names
),
)
logger.info("database connection is using SSL")
else:
logger.warning("database connection is not using SSL")
15 changes: 4 additions & 11 deletions app/tests/src/adapters/db/clients/test_postgres_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,24 @@ class DummyPgConn:


class DummyConnectionInfo:
def __init__(self, ssl_in_use, attributes):
self.attributes = attributes
self.ssl_attribute_names = tuple(attributes.keys())
def __init__(self, ssl_in_use):
self.pgconn = DummyPgConn(ssl_in_use)

def ssl_attribute(self, name):
return self.attributes[name]


def test_verify_ssl(caplog):
caplog.set_level(logging.INFO) # noqa: B1

conn_info = DummyConnectionInfo(True, {"protocol": "ABCv3", "key_bits": "64", "cipher": "XYZ"})
conn_info = DummyConnectionInfo(True)
verify_ssl(conn_info)

assert caplog.messages == [
"database connection is using SSL: protocol ABCv3, key_bits 64, cipher XYZ"
]
assert caplog.messages == ["database connection is using SSL"]
assert caplog.records[0].levelname == "INFO"


def test_verify_ssl_not_in_use(caplog):
caplog.set_level(logging.INFO) # noqa: B1

conn_info = DummyConnectionInfo(False, {})
conn_info = DummyConnectionInfo(False)
verify_ssl(conn_info)

assert caplog.messages == ["database connection is not using SSL"]
Expand Down