Skip to content

use tempfile.TemporaryDirectory & fix clone_from_unsafe_protocol tests #1531

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 8, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix clone_from_unsafe_protocol tests
  • Loading branch information
obfusk committed Jan 8, 2023
commit 8f41a390bf9a54db6f85032bc56b453307b95451
35 changes: 30 additions & 5 deletions test/test_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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):
Expand Down