Skip to content

Commit

Permalink
fix(providers/mongo): prevent applying lower method on boolean field (a…
Browse files Browse the repository at this point in the history
  • Loading branch information
josix authored and harjeevanmaan committed Oct 23, 2024
1 parent 6cd0aa3 commit 59aefc6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
6 changes: 3 additions & 3 deletions providers/src/airflow/providers/mongo/hooks/mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@ def __init__(self, mongo_conn_id: str = default_conn_name, *args, **kwargs) -> N
self.client: MongoClient | None = None
self.uri = self._create_uri()

self.allow_insecure = self.extras.pop("allow_insecure", "false").lower() == "true"
self.allow_insecure = str(self.extras.pop("allow_insecure", "false")).lower() == "true"
self.ssl_enabled = (
self.extras.get("ssl", "false").lower() == "true"
or self.extras.get("tls", "false").lower() == "true"
str(self.extras.get("ssl", "false")).lower() == "true"
or str(self.extras.get("tls", "false")).lower() == "true"
)

if self.ssl_enabled and not self.allow_insecure:
Expand Down
12 changes: 12 additions & 0 deletions providers/tests/mongo/hooks/test_mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ def mongo_connections():
port=27017,
extra='{"srv": true}',
),
Connection(
conn_id="mongo_default_with_allow_insecure_ssl_fields",
conn_type="mongo",
host="mongo",
extra='{"allow_insecure": false, "ssl": true}',
),
# Mongo establishes connection during initialization, so we need to have this connection
Connection(conn_id="fake_connection", conn_type="mongo", host="mongo", port=27017),
]
Expand Down Expand Up @@ -400,3 +406,9 @@ def test_context_manager():
assert ctx_hook.client is not None

assert ctx_hook.client is None


def test_allow_insecure_and_ssl_enabled():
hook = MongoHook(mongo_conn_id="mongo_default_with_allow_insecure_ssl_fields")
assert hook.allow_insecure is False
assert hook.ssl_enabled is True

0 comments on commit 59aefc6

Please sign in to comment.