Skip to content

Commit 0887e75

Browse files
add tests for username and/or password being set
1 parent daddaa3 commit 0887e75

1 file changed

Lines changed: 30 additions & 1 deletion

File tree

providers/opensearch/tests/unit/opensearch/log/test_os_task_handler.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
)
4747
from airflow.utils.log.file_task_handler import FileTaskHandler
4848
from airflow.utils.state import DagRunState, TaskInstanceState
49-
5049
from tests_common.test_utils.config import conf_vars
5150
from tests_common.test_utils.db import clear_db_dags, clear_db_runs
5251
from tests_common.test_utils.version_compat import AIRFLOW_V_3_0_PLUS
@@ -288,7 +287,36 @@ def test_client_with_patterns(self):
288287
)
289288
assert handler.index_patterns == patterns
290289

290+
@pytest.mark.parametrize(
291+
("username", "password"),
292+
[
293+
("admin", "secret"),
294+
("admin", ""),
295+
("", "secret"),
296+
],
297+
)
298+
def test_client_with_auth(self, username, password):
299+
"""If either username or password are provided, the handler should pass http_auth to the client."""
300+
handler = OpensearchTaskHandler(
301+
base_log_folder=self.local_log_location,
302+
end_of_log_mark=self.end_of_log_mark,
303+
write_stdout=self.write_stdout,
304+
host="localhost",
305+
port=9200,
306+
username=username,
307+
password=password,
308+
json_format=self.json_format,
309+
json_fields=self.json_fields,
310+
host_field=self.host_field,
311+
offset_field=self.offset_field,
312+
)
313+
314+
transport_args = handler.client.transport.kwargs
315+
assert "http_auth" in transport_args
316+
assert transport_args["http_auth"] == (username, password)
317+
291318
def test_client_no_auth(self):
319+
"""If both username and password are empty, the handler should _not_ pass http_auth to the client."""
292320
handler = OpensearchTaskHandler(
293321
base_log_folder=self.local_log_location,
294322
end_of_log_mark=self.end_of_log_mark,
@@ -302,6 +330,7 @@ def test_client_no_auth(self):
302330
host_field=self.host_field,
303331
offset_field=self.offset_field,
304332
)
333+
305334
assert "http_auth" not in handler.client.transport.kwargs
306335

307336
@pytest.mark.db_test

0 commit comments

Comments
 (0)