Skip to content

Commit 9e0f8ab

Browse files
Escape paths in the volume lifecycle test
Signed-off-by: Aakash Saravanan <aakash.saravanan@databricks.com>
1 parent 9b37b13 commit 9e0f8ab

1 file changed

Lines changed: 19 additions & 11 deletions

File tree

‎tests/e2e/test_kernel_backend.py‎

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -780,8 +780,8 @@ def test_scientific_notation_decimal_parameter_binds(conn):
780780
def test_volume_file_lifecycle(kernel_conn_params, tmp_path, catalog, async_op):
781781
allowed = tmp_path / "allowed"
782782
allowed.mkdir()
783-
source = allowed / "input.bin"
784-
destination = allowed / "output.bin"
783+
source = allowed / "input's.bin"
784+
destination = allowed / "output's.bin"
785785
payload = bytes(range(256)) * 4096
786786
source.write_bytes(payload)
787787
denied = tmp_path / "denied.bin"
@@ -790,6 +790,10 @@ def test_volume_file_lifecycle(kernel_conn_params, tmp_path, catalog, async_op):
790790
namespace = f"volume_{uuid4().hex}"
791791
qualified = f"`{catalog.replace('`', '``')}`.`{namespace}`"
792792
remote = f"/Volumes/{catalog}/{namespace}/files/input.bin"
793+
794+
def literal(path):
795+
return "'" + str(path).replace("\\", "\\\\").replace("'", "\\'") + "'"
796+
793797
with sql.connect(
794798
**kernel_conn_params, staging_allowed_local_path=str(allowed)
795799
) as connection:
@@ -802,7 +806,7 @@ def test_volume_file_lifecycle(kernel_conn_params, tmp_path, catalog, async_op):
802806
with no_paths.cursor() as denied_cursor:
803807
with pytest.raises(ProgrammingError):
804808
denied_cursor.execute(
805-
f"PUT '{source}' INTO '{remote}' OVERWRITE"
809+
f"PUT {literal(source)} INTO {literal(remote)} OVERWRITE"
806810
)
807811

808812
def execute(query):
@@ -814,23 +818,27 @@ def execute(query):
814818
return cur.fetchall()
815819

816820
assert (
817-
execute(f"-- upload\nPUT '{source}' INTO '{remote}' OVERWRITE")
821+
execute(
822+
f"-- upload\nPUT {literal(source)} INTO {literal(remote)} OVERWRITE"
823+
)
818824
== []
819825
)
820826
with pytest.raises(NotSupportedError, match="Streaming PUT"):
821-
execute(f"PUT r'__input_stream__' INTO '{remote}' OVERWRITE")
822-
assert execute(f"GET '{remote}' TO '{destination}'") == []
827+
execute(f"PUT r'__input_stream__' INTO {literal(remote)} OVERWRITE")
828+
assert execute(f"GET {literal(remote)} TO {literal(destination)}") == []
823829
assert destination.read_bytes() == payload
824830
with pytest.raises(ProgrammingError):
825-
execute(f"PUT '{denied}' INTO '{remote}' OVERWRITE")
831+
execute(f"PUT {literal(denied)} INTO {literal(remote)} OVERWRITE")
826832
with pytest.raises(FileNotFoundError):
827833
execute(
828-
f"PUT '{allowed / 'missing.bin'}' INTO '{remote}' OVERWRITE"
834+
f"PUT {literal(allowed / 'missing.bin')} INTO {literal(remote)} OVERWRITE"
829835
)
830-
assert execute(f"REMOVE '{remote}'") == []
831-
assert execute(f"REMOVE '{remote}'") == []
836+
assert execute(f"REMOVE {literal(remote)}") == []
837+
assert execute(f"REMOVE {literal(remote)}") == []
832838
with pytest.raises(OperationalError, match="404"):
833-
execute(f"GET '{remote}' TO '{allowed / 'deleted.bin'}'")
839+
execute(
840+
f"GET {literal(remote)} TO {literal(allowed / 'deleted.bin')}"
841+
)
834842
assert execute("SELECT 1")[0][0] == 1
835843
finally:
836844
cur.execute(f"DROP SCHEMA {qualified} CASCADE")

0 commit comments

Comments
 (0)