From 8f41a390bf9a54db6f85032bc56b453307b95451 Mon Sep 17 00:00:00 2001 From: FC Stegerman Date: Sun, 8 Jan 2023 06:26:27 +0100 Subject: [PATCH] fix clone_from_unsafe_protocol tests --- test/test_repo.py | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/test/test_repo.py b/test/test_repo.py index 0985b6352..d5474353f 100644 --- a/test/test_repo.py +++ b/test/test_repo.py @@ -386,7 +386,7 @@ def test_clone_from_safe_options(self, rw_repo): Repo.clone_from(rw_repo.common_dir, destination, multi_options=[option]) assert destination.exists() - def test_clone_from_unsafe_procol(self): + def test_clone_from_unsafe_protocol(self): with tempfile.TemporaryDirectory() as tdir: tmp_dir = pathlib.Path(tdir) tmp_file = tmp_dir / "pwn" @@ -396,24 +396,49 @@ def test_clone_from_unsafe_procol(self): ] for url in urls: with self.assertRaises(UnsafeProtocolError): - Repo.clone_from(url, tmp_dir) + Repo.clone_from(url, tmp_dir / "repo") assert not tmp_file.exists() - def test_clone_from_unsafe_procol_allowed(self): + def test_clone_from_unsafe_protocol_allowed(self): with tempfile.TemporaryDirectory() as tdir: tmp_dir = pathlib.Path(tdir) tmp_file = tmp_dir / "pwn" urls = [ - "ext::sh -c touch% /tmp/pwn", + f"ext::sh -c touch% {tmp_file}", "fd::/foo", ] for url in urls: # The URL will be allowed into the command, but the command will # fail since we don't have that protocol enabled in the Git config file. with self.assertRaises(GitCommandError): - Repo.clone_from(url, tmp_dir, allow_unsafe_protocols=True) + Repo.clone_from(url, tmp_dir / "repo", allow_unsafe_protocols=True) assert not tmp_file.exists() + def test_clone_from_unsafe_protocol_allowed_and_enabled(self): + with tempfile.TemporaryDirectory() as tdir: + tmp_dir = pathlib.Path(tdir) + tmp_file = tmp_dir / "pwn" + urls = [ + f"ext::sh -c touch% {tmp_file}", + ] + allow_ext = [ + "--config=protocol.ext.allow=always", + ] + for url in urls: + # The URL will be allowed into the command, and the protocol is enabled, + # but the command will fail since it can't read from the remote repo. + assert not tmp_file.exists() + with self.assertRaises(GitCommandError): + Repo.clone_from( + url, + tmp_dir / "repo", + multi_options=allow_ext, + allow_unsafe_protocols=True, + allow_unsafe_options=True, + ) + assert tmp_file.exists() + tmp_file.unlink() + @with_rw_repo("HEAD") def test_max_chunk_size(self, repo): class TestOutputStream(TestBase):