Skip to content

Commit 7cdeac2

Browse files
add OpensearchIO tests for username and/or password being set
1 parent 6f58d6d commit 7cdeac2

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,34 @@ def test_upload_returns_early_when_ti_is_none(self, tmp_path):
831831
log_file.write_text('{"message": "test"}\n')
832832
self.opensearch_io.upload(log_file, ti=None)
833833

834+
@pytest.mark.parametrize(
835+
("username", "password"),
836+
[
837+
("admin", "secret"),
838+
("admin", ""),
839+
("", "secret"),
840+
],
841+
)
842+
def test_client_with_auth(self, username, password):
843+
"""If either username or password are provided, the IO should pass http_auth to the client."""
844+
opensearch_io = OpensearchRemoteLogIO(
845+
write_to_opensearch=True,
846+
write_stdout=True,
847+
delete_local_copy=True,
848+
host="localhost",
849+
port=9200,
850+
username=username,
851+
password=password,
852+
base_log_folder=self.opensearch_io.base_log_folder,
853+
log_id_template="{dag_id}-{task_id}-{run_id}-{map_index}-{try_number}",
854+
)
855+
856+
transport_args = opensearch_io.client.transport.kwargs
857+
assert "http_auth" in transport_args
858+
assert transport_args["http_auth"] == (username, password)
859+
834860
def test_client_no_auth(self):
861+
"""If both username and password are empty, the IO should _not_ pass http_auth to the client."""
835862
opensearch_io = OpensearchRemoteLogIO(
836863
write_to_opensearch=True,
837864
write_stdout=True,
@@ -843,6 +870,7 @@ def test_client_no_auth(self):
843870
base_log_folder=self.opensearch_io.base_log_folder,
844871
log_id_template="{dag_id}-{task_id}-{run_id}-{map_index}-{try_number}",
845872
)
873+
846874
assert "http_auth" not in opensearch_io.client.transport.kwargs
847875

848876

0 commit comments

Comments
 (0)