diff --git a/test/notebook_test_runner/test_notebooks_in_dss_docker_image.py b/test/notebook_test_runner/test_notebooks_in_dss_docker_image.py index fb9f3e99..8d16fb74 100644 --- a/test/notebook_test_runner/test_notebooks_in_dss_docker_image.py +++ b/test/notebook_test_runner/test_notebooks_in_dss_docker_image.py @@ -64,7 +64,7 @@ def notebook_test_container_with_log(notebook_test_container): print(socket.stat()) print() logs = notebook_test_container.logs().decode("utf-8").strip() - print("Container Logs: {logs or '(empty)'}", flush=True) + print(f"Container Logs: {logs or '(empty)'}", flush=True) yield notebook_test_container diff --git a/test/unit/entrypoint/test_file_permissions.py b/test/unit/entrypoint/test_file_permissions.py new file mode 100644 index 00000000..0b7b812c --- /dev/null +++ b/test/unit/entrypoint/test_file_permissions.py @@ -0,0 +1,58 @@ +import pytest +import os +import re +import stat + +from exasol.ds.sandbox.runtime.ansible.roles.entrypoint.files import entrypoint + +# def stat_result( +# st_mode=0, +# st_ino=0, +# st_dev=0, +# st_nlink=0, +# st_uid=0, +# st_gid=0, +# st_size=0, +# st_atime=0, +# st_mtime=0, +# st_ctime=0, +# ): +# return os.stat_result(( +# st_mode, st_ino, st_dev, st_nlink, st_uid, st_gid, st_size, +# st_atime, st_mtime, st_ctime, +# )) + + +def test_file_inspector_non_existing_file(mocker): + mocker.patch("os.stat") + # need to mock os.path.exists as os.path.exists seems to call os.stat :) + mocker.patch("os.path.exists", return_value=False) + testee = entrypoint.FileInspector("/non/existing/file") + actual = testee.is_group_accessible() + assert actual == False + assert not os.stat.called + + +@pytest.fixture +def accessible_file(tmp_path): + mode = os.stat(tmp_path).st_mode | stat.S_IRGRP | stat.S_IWGRP + os.chmod(tmp_path, mode) + return tmp_path + + +@pytest.fixture +def non_accessible_file(tmp_path): + mode = stat.S_IRUSR | stat.S_IWUSR + os.chmod(tmp_path, mode) + return tmp_path + + +def test_file_inspector_group_accessible(accessible_file): + testee = entrypoint.FileInspector(accessible_file) + assert testee.is_group_accessible() + + +def test_file_inspector_not_group_accessible(non_accessible_file, caplog): + testee = entrypoint.FileInspector(non_accessible_file) + assert not testee.is_group_accessible() + assert re.match(r"ERROR .* No rw permissions for group", caplog.text)